'This SVC instance is not fitted yet. Call 'fit' with appropriate arguments before using this method
I have used SVC of sklearn to fit the training set, and tried to predict the y_pred by classifier.predict(X_test), but it returned NotFittedError: This SVC instance is not fitted yet. Call 'fit' with appropriate arguments before using this method.
I tried restarting the python, it didn't work. I also tried LogisticRegression from sklearn.linear_model and it worked just fine.
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
dataset = pd.read_csv('Social_Network_Ads.csv')
X = dataset.iloc[:, [2, 3]].values
y = dataset.iloc[:, 4].values
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
from sklearn.svm import SVC
classifier = SVC(kernel = 'linear', random_state = 0)
classifier.fit = (X_train, y_train)
y_pred = classifier.predict(X_test)
I expect the y_pred to contain the predicted values of X_test.
Instead, I got the below error message, NotFittedError: This SVC instance is not fitted yet. Call 'fit' with appropriate arguments before using this method.
Solution 1:[1]
In the 2nd last line it is :
classifier.fit(X_train, y_train)
and not
classifier.fit = (X_train, y_train)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | StupidWolf |
