I am dealing with error
"AttributeError: 'numpy.ndarray' object has no attribute 'nipy_spectral'"
while running silhouette analysis.
The original code was taken from here. I have added the line that shows the error:
color = cm.nipy_spectral(float(i) / n_clusters)
The problem was that you were assigning cm to some other array. Correct way is not to assign cm to any other array or change the code to
matplotlib.cm.nipy_spectral(float(i) / n_clusters)
Change it at all the places where cm is used.
Here is the snippet of the input data and the result of running print(type(cm)).
Screenshot
Related
deviations = returns - returns.mean() squared_deviations =
deviations**2 variance = squared_deviations.mean()
import numpy as np
volatility = np.sqrt(variance) volatility
When I run this code I get this error
'function' object has no attribute 'mean'
I am confused as I have written this text before and it seems to have worked fine. I even do simple stuff like returns.std() and I get the same response.
'function' object has no attribute even after importing pandas
I have already imported NumPy and pandas
Find below the code I used to create the residuals_plot from yellowbrick package.
I ran the xgbregressor model, predicted the results and tried to create the residuals plot.
The plot came out properly, but followed with the below error. I didn't use the line_color
attribute at all anywhere in the code.
AttributeError: 'XGBRegressor' object has no attribute 'line_color' .
I would really appreciate if someone could help me with this.
from yellowbrick.regressor import residuals_plot
print("\n Residuals Plot")
residuals_plot(XGBR, MBxtrain, MBytrain, MBxtest, MBytest)
residuals_plot_from_yellowbrick_package
I am implementing unscented kalman filter and getting this error "numpy.ndarray object is not callable" for the non-linear function 'g' in the prediction step.
enter image description here
I have also attached my code where I got this error. Any assistance would be highly appreciated. Thanks!
Just like the error message says, gx is a numpy array:
gx = np.array([g_E, g_R])
But you are trying to call it as if it were a function:
self.sigmas_x[:,i] = gx(self.sigmas[:,i],dt, u)
Hence the error.
This error occurs in my code: AttributeError: 'str' object has no attribute 'mean_validation_score'. What can I do to resolve it?
GridMean = [result.mean_validation_score for result in
gridA.cv_results_]
print(GridMean)
plt.plot(k_values, GridMean)
plt.xlabel('Value of "K" for KNN')
plt.ylabel('CrossValidated Accuracy')
"mean_validation_score" is depricated now it's "mean_test_score". Use "mean_test_score".
For your confirmation you can check-it-out
gridA.cv_results_.keys()
After running the above comment you can see there is no "mean_validation_score".
I presume you are working with sklearn.model_selection.GridSearchCV, with gridA being an instance of GridSearchCV.
I am not sure when the method mean_validation_score was deprecated for GridSearchCV objects, but for sklearn 0.22 you can get the scores calling them with the key 'mean_test_score' being gridA.cv_results a dictionary. Like this:
GridMean = gridA.cv_results_['mean_test_score']
So I have been writing a code to standardize the elements of a matrix and the function I used is as follows:
def preprocess(Data):
if stdn ==True:
st=np.empty((Data.shape[0],Data.shape[1]))
for i in xrange(0,Data.shape[0]):
st[i,0]=Data[i,0]
for i in xrange(1,Data.shape[1]):
st[:,i]=((Data[:,i]-np.min(Data[:,i]))/(np.ptp(Data[:,i])))
np.random.shuffle(st)
return st
else:
return Data
It works very well outside the class but when used inside of it it gives me this error:
AttributeError: 'tuple' object has no attribute 'shape'
Any idea on how I can fix it??
P.S. This is a KNN classification code
According to the error you posted, Data is of type tuple and there is no attribute shape defined for data. You could try casting Data when you call your preprocess function, e.g.:
preprocess(numpy.array(Data))