I want to have root mean squared of gradient boosting algorithm but when I want to print it, I receive an attribute error
my_best_model.np.sqrt(metrics.mean_squared_error(X_test_new, y_test_new))
output:
AttributeError Traceback (most recent call last)
<ipython-input-80-9c2e86b2ddf9> in <module>
----> 1 my_best_model.np.sqrt(metrics.mean_squared_error(X_test_new, y_test_new))
AttributeError: 'GradientBoostingRegressor' object has no attribute 'np'
This is not the correct usage; assuming that my_best_model is a fitted GradientBoostingRegressor, you should use:
from sklearn.metrics import mean_squared_error
mse = mean_squared_error(y_test_new, my_best_model.predict(X_test_new))
rmse = np.sqrt(mse)
Related
I just simply typed the code given in tf.Tensor Tensorflow 2.2.0, and here is my code: please i want solution for thi Error !!
print(tf.__version__)
a=2
b=3
c=tf.add(a,b,name='add')
print(c)
sess = tf.Session()
print(sess.run(c))
sess.close()
output
2.2.0
tf.Tensor(5, shape=(), dtype=int32)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-34-0f2b1dd0c6d9> in <module>()
4 c=tf.add(a,b,name='add')
5 print(c)
----> 6 sess = tf.Session()
7 print(sess.run(c))
8 sess.close()
AttributeError: module 'tensorflow' has no attribute 'Session'
while trying to predict the model i am getting this numpy.ndarray error .it might be the returning statement of the prepare function. what can be possibly done to get rid of this error .
import cv2
import tensorflow as tf
CATEGORIES = ["Dog", "Cat"]
def prepare(filepath):
IMG_SIZE = 50 # 50 in txt-based
img_array = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1)
model = tf.keras.models.load_model("64x3-CNN.model")
prediction = model.predict([prepare('dog.jpg')])
print(prediction) # will be a list in a list.
tried to give the full path still the same error persist.
TypeError Traceback (most recent call last)
<ipython-input-45-f9de27e9ff1e> in <module>
15
16 prediction = model.predict([prepare('dog.jpg')])
---> 17 print(prediction) # will be a list in a list.
18 print(CATEGORIES[int(prediction[0][0])])
TypeError: 'numpy.ndarray' object is not callable
Not sure what the rest of your code looks like. But if you use 'print' as a variable in Python 3 you can get this error:
import numpy as np
x = np.zeros((2,2))
print = np.ones((2,2))
print(x)
Output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'numpy.ndarray' object is not callable
This type of errors mostly occurs when trying to print an array instead of simple strings or single variable numbers, so I would recommend you to change:
17 print(prediction) # will be a list in a list.
18 print(CATEGORIES[int(prediction[0][0])])
Then you would get:
17 print(str(prediction)) # will be a list in a list.
18 print(str(CATEGORIES[int(prediction[0][0])]))
I am trying to use xgboost on a dataset. I have seen the same syntax in various blogs but I am getting an error while calling clf.evals_result()
here is my code
from xgboost import XGBRegressor as xgb
from sklearn.metrics import mean_absolute_error as mae
evals_result ={}
eval_s = [(x, y),(xval,yval)]
clf = xgb(n_estimators=100,learning_rate=0.03,tree_method='gpu_hist',lamda=0.1,eval_metric='mae',eval_set=eval_s,early_stopping_rounds=0,evals_result=evals_result)
clf.fit(x,y)
r = clf.evals_result()
here is error I am receiving
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-138-2d6867968043> in <module>
1
----> 2 r = clf.evals_result()
3
4 p = clf.predict(xval)
/opt/conda/lib/python3.6/site-packages/xgboost/sklearn.py in evals_result(self)
399 'validation_1': {'logloss': ['0.41965', '0.17686']}}
400 """
--> 401 if self.evals_result_:
402 evals_result = self.evals_result_
403 else:
AttributeError: 'XGBRegressor' object has no attribute 'evals_result_'
I got exactly the same error, the solution it's to pass the eval_set to the fit function and not in the creation of the classifier
clf.fit(x,y,eval_set=eval_s)
Then you can run clf.evals_result()
I want to save and load the count vectorizer vocabulary.This is my code
from sklearn.feature_extraction.text import CountVectorizer
cv = CountVectorizer(max_features = 1500)
Cv_vec = cv.fit(X['review'])
X_cv=Cv_vec.transform(X['review']).toarray()
dictionary_filepath='CV_dict'
pickle.dump(Cv_vec.vocabulary_, open(dictionary_filepath, 'w'))
It shows me
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-407-3a9b06f969a9> in <module>()
1 dictionary_filepath='CV_dict'
----> 2 pickle.dump(Cv_vec.vocabulary_, open(dictionary_filepath, 'w'))
TypeError: write() argument must be str, not bytes
I want to save the vocabulary of the count vectorizer and load it.Can anyone help me with it please?.
Open the file in binary mode when pickling out an object. And try to use a context manager, i.e.
from sklearn.feature_extraction.text import CountVectorizer
cv = CountVectorizer(max_features = 1500)
Cv_vec = cv.fit(X['review'])
X_cv=Cv_vec.transform(X['review']).toarray()
dictionary_filepath='CV_dict'
with open('CV_dict.pkl', 'wb') as fout:
pickle.dump(Cv_vec.vocabulary_, fout)
I am getting an error for the following code.
Can someone please tell me where I am going wrong?
p.s. I have given the path correctly for.mrcfile
import numpy
import Mrc
a = Mrc.bindFile('somefile.mrc')
# a is a NumPy array with the image data memory mapped from
# somefile.mrc. You can use it directly with any function
# that will take a NumPy array.
hist = numpy.histogram(a, bins=200)
# a.Mrc is an instances of the Mrc class. One thing
# you can do with that class is print out key information from the header.
a.Mrc.info()
# Use a.Mrc.hdr to access the MRC header fields.
wavelength0_nm = a.Mrc.hdr.wave[0]
AttributeError Traceback (most recent call last)
in ()
3 a = Mrc.bindFile('/home/smitha/deep-image-prior/data/Falcon_2015_05_14-20_42_18.mrc')
4 hist = numpy.histogram(a, bins=200)
----> 5 a.Mrc.info()
6 wavelength0_nm = a.Mrc.hdr.wave[0]
7
AttributeError: 'NoneType' object has no attribute 'Mrc'