3

I have a problem with this code:

    from sklearn import svm
    model_SVC = SVC()
    model_SVC.fit(X_scaled_df_train, y_train)
    svm_prediction = model_SVC.predict(X_scaled_df_test)

The error message is

NameError
Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_14392/1339209891.py in ----> 1 svm_prediction = model_SVC.predict(X_scaled_df_test)

NameError: name 'model_SVC' is not defined

Any ideas?

Alexander L. Hayes
  • 3,892
  • 4
  • 13
  • 34
Bookish Mass
  • 61
  • 1
  • 5
  • 1
    Try `from sklearn.svm import SVC` to import SVC. Or change the next line to `model_SVC = svm.SVC()`. See if that works – Redox Aug 22 '22 at 11:10

2 Answers2

2

use:

from sklearn.svm import SVC
s510
  • 2,271
  • 11
  • 18
1

The line from sklearn import svm was incorrect. The correct way is

from sklearn.svm import SVC

The documentation is sklearn.svm.SVC. And when I choose this model, I'm mindful of the dataset size. Extracted:

The fit time scales at least quadratically with the number of samples and may be impractical beyond tens of thousands of samples. For large datasets consider using LinearSVC instead.

from sklearn.svm import LinearSVC

For more info you could read When should one use LinearSVC or SVC?

blackraven
  • 5,284
  • 7
  • 19
  • 45