I am currently learning how to preprocess handwritten characters.There was an error that I couldn't understand, so I would like to ask you a question with the help of professionals.
I was able to articulate, grayscale, shrink, invert, and then convert the image object into a feature vector, but I can't do the subsequent "Hand over the feature vector to the predict() method."
The error "This LogisticRegression instance is not fitted yet" appears.
The code is as follows:
pip install pillow
import matplotlib.pyplot asplt
from PIL import Image
im=Image.open('mydigit.jpg')
config,ax=plt.subplots()
ax.imshow(im)
from PIL import ImageEnhance
im_enhanced=ImageEnhance.Brightness(im).enhance(2.0)
config,ax=plt.subplots()
ax.imshow(im_enhanced)
im_gray=im_enhanced.convert(mode='L')
config,ax=plt.subplots()
ax.imshow(im_gray,cmap='gray')
im_8x8 = im_gray.resize ((8,8))
config,ax=plt.subplots()
ax.imshow(im_8x8,cmap='gray')
from PIL import ImageOps
im_inverted=ImageOps.invert(im_8x8)
config,ax=plt.subplots()
ax.imshow(im_inverted,cmap='gray')
import numpy
X_im2d = numpy.asarray(im_inverted)
X_im2d
X_im1d = X_im2d.reshape(-1)
X_im1d
X_multiplied=X_im1d* (16/255)
X_multiplied
from sklearn.linear_model importLogisticRegression
clf=LogisticRegression(random_state=0, solver='libliner', multi_class='auto')
clf.predict(X_multiplied)[0]
The following error statement
NotFittedError Traceback (most recent call last)
<ipython-input-97-0e0508a3ae41>in<module>
---->1clf.predict(X_multiplied)[0]
~\Test\lib\site-packages\sklearn\linear_model\base.py in predict(self,X)
287 Predicted class label per sample.
288 """
-->289scores=self.decision_function(X)
290 iflen(scores.shape) == 1:
291indices=(scores>0).astype(np.int)
~\Test\lib\site-packages\sklearn\linear_model\base.py in decision_function(self,X)
261 if not hasattr(self, 'coef_') or self.coef_is None:
262 raise NotFittedError("This%(name)s instance is not fitted"
-->263 "yet"%{'name':type(self).__name_})
264
265 X = check_array(X, accept_sparse='csr')
NotFittedError: This LogisticRegression instance is not fitted yet
I'm not learning, but I can't predict it.
With scikit-learn, whatever algorithm you use, you basically learn with fit()
and predict with predict()
.Of course, if you've already learned a model, you can load it.
In the first place, the prediction is not "handwritten character preprocessing."
© 2024 OneMinuteCode. All rights reserved.