我已使用sklearn的SVC来拟合训练集,并尝试通过classifier.predict(X_test)预测y_pred,但是它返回NotFittedError:此SVC实例尚未安装。使用此方法之前,请使用适当的参数调用“适合”。
我尝试重新启动python,但没有成功。我还尝试了sklearn.linear_model的LogisticRegression,但效果很好。
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)
我希望y_pred包含X_test的预测值。
相反,我收到以下错误消息, NotFittedError:此SVC实例尚未安装。使用此方法之前,请使用适当的参数调用“适合”。