i am trying to find a predicted Y value (output is numerical) with x inputs using strings (eg. Business type, Department and Region). After using this :
print(model.predict([['Finance and Control'], ['EMEA'], ['Professional Services']]))
it returned this error : AttributeError: 'numpy.ndarray' object has no attribute 'predict'
import pickle
model = pickle.load(open('model3.pkl','rb'))
print(model.predict([['Finance and Control'], ['EMEA'], ['Professional Services']]))
Sample array after OHE
I ran into a similar issue as this, though without additional context, I'm not sure our errors derive from the same problem. However, the resolution I arrived at may help someone in the future as they go down the SO rabbit hole.
Using sklearn-0.20,
import joblib
model = joblib.load('model.pkl')
model.predict(previously_loaded_data)
Resulted in
AttributeError: 'numpy.ndarray' object has no attribute 'predict'
However, the following allowed me to load the actual model and use its predict method:
from sklearn.externals import joblib
model = joblib.load('model.pkl')
model.predict(previously_loaded_data)
sklearn.externals.joblib is deprecated since sklearn-0.23+, but my use case required sklearn-0.20.
Related
I have trained a classifier model and its working nicely in terms of giving prediction(boolian) in my local machine.
% movie data
% [Rating, Production_Budget_million]
movie_data=[1,20]
likelihood_pos=multivariate_normal_pos.pdf(movie_data)
likelihood_neg=multivariate_normal_neg.pdf(movie_data)
post_pos=likelihood_pos*prior_pos/(likelihood_pos*prior_pos+likelihood_neg*prior_neg)
post_neg=likelihood_neg*prior_neg/(likelihood_neg*prior_neg+likelihood_pos*prior_pos)
pred= post_pos>post_neg
pred
The problem I am facing ,after dumping the model as pickle when I am trying to calling the model and test with user data its giving an error"AttributeError: 'numpy.bool_' object has no attribute 'predict'"
I know the result will be boolian as"TRUE/FALSE".
#dumping/saving the model
import pickle
pickle.dump(pred, open('pred.pkl','wb'))
#calling the model
predx = pickle.load(open('pred.pkl','rb'))
#testing with user data
print(predx.predict([[1,20]]))
How can I solve the issue and fined the boolian output?
I used PyCaret 3.0-rc. I developed model and saved them. after almost 3 weeks, now I loaded model. But when I want to use them :
train_predictions = predict_model(model, data=train)
I got the following error:
AttributeError: 'TransformerWrapper' object has no attribute '_memory_transform'
Can any one help me solve it?
I am having problems using sklearn's SequentialFeatureSelector for feature selection prior to clustering.
Please see my code:
Shooting_ST_array = np.array(Shooting_ST)
kmeans1 = KMeans(n_clusters=4)
kmeans1 = kmeans1.fit(Shooting_ST_array)
sfs = SequentialFeatureSelector(estimator=kmeans1, n_features_to_select=5, direction='backward')
sfs.fit(Shooting_ST_array, y=None)
sfs.get_feature_names_out(Shooting_ST.columns)
Depending on whether I used forward or backward selection, the algorithm returns the first 5 or last 5 columns.
I am also getting the following attribute error:
AttributeError: 'NoneType' object has no attribute 'split'
Does anyone have an idea what I am doing wrong? I have unfortunately not found any example implementations of the method for unlabelled data.
I want to train a model with a custom loss function, in order to do that, I need to convert the tensor to numpy array inside the method below:
def median_loss_estimation(y_true, y_predicted):
a = y_predicted.numpy()
but I have this error:
AttributeError: 'Tensor' object has no attribute 'numpy'
Why?
How can I convert the tensor to a numpy array?
The answer is: put run_eagerly=True in model.compile!
You're doing the right thing, only Tensorflow 2.1 is currently broken in that aspect. This would normally happen if you run the code without eager mode enabled. However, Tensorflow 2 by default runs in eager mode... or at least it should. The issue is tracked here.
There are at least two solutions to this:
Install the latest nightly build.
Set model.run_eagerly = True.
Ok I have this code
import anchor
bm = anchor.BayesianModalities()
modalities = bm.fit_transform(data)
but shows me this error
AttributeError: 'BayesianModalities' object has no attribute 'fit_transform'
What Can be it?
This looks like an issue with the README, the method is actually fit_predict rather than fit_transform. Give the below a try.
import anchor
bm = anchor.BayesianModalities()
modalities = bm.fit_predict(data)