python - Difference between .score() and .predict in the sklearn library? -


I have used a SVC object in Scalean Library with the following code:

clf = Svm.SVC (kernel = 'linear', c = 1, cache_sage = 1000, max_iiter = -1, verbose = tru)

Then I fit it using data:

model = clf.fit (X_train, y_train)

Where X_train is one (30160) and y_train is (301,) ndarray (yttrain The label "1", "2" and "3" consisting of the class)

Now, before I stumbled into the .core () method, I was using the following to determine the accuracy of my model on the training model:

< Code> forecast = np.divide ((y_train == model.predict (X_train)). Sum (), y_train.size, dtype = float)

which gives results of approximately 62% is.

However, when using the model.score (X_train, y_train) method, I get about 83% result.

So, I was thinking that someone could tell me why this should be done, because as far as I understand, only the results should be returned?

ADDENDUM:

The first 10 values ​​of y_true are:

  • 2, 3, 1, 3, 2, 3, 2, 2, 3 , 1, ...

While for y_pred (while using model.predict (X_train), they are:

  • 2, 3 , 3, 2, 2, 3, 2, 3, 3, 3, ...

Because your y_train is (301, 1) and no (301,) transmits numpy, so

< Pre> (y_train == model.predict (X_train)) size == (301, 301)

that is not your intention will be the correct version of your code

  np.mean (y_train.ravel () == model.predict (X_train))  

which will give

  model score (X_train, y_train)  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -