fit() 缺少 1 个必需的位置参数:'self'
fit() missing 1 required positional argument: 'self'
我尝试将 SVC
放入 skikit-learn
,但结果是 TypeError: fit() missing 1 required positional argument: 'self' in the line SVC.fit(X=Xtrain, y=ytrain)
from sklearn.svm import SVC
import seaborn as sns; sns.set()
from sklearn.datasets.samples_generator import make_circles
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score
X, y = make_circles(100, factor=.2, noise=.2)
Xtrain, Xtest, ytrain, ytest = train_test_split(X,y,random_state=42)
svc = SVC(kernel = "poly")
SVC.fit(X=Xtrain, y=ytrain)
predictions = SVC.predict(ytest)
问题是您在此处创建模型 svc = SVC(kernel = "poly")
,但您使用 non-instantiable 模型调用拟合。
您必须将对象更改为:
svc_model = SVC(kernel = "poly")
svc_model.fit(X=Xtrain, y=ytrain)
predictions = svc_model.predict(Xtest)
我建议你 Indique 测试大小,通常最好的做法是 30% 用于测试,70% 用于训练。所以你可以指出。
Xtrain, Xtest, ytrain, ytest = train_test_split(X,y,test_size=0.30, random_state=42)
我尝试将 SVC
放入 skikit-learn
,但结果是 TypeError: fit() missing 1 required positional argument: 'self' in the line SVC.fit(X=Xtrain, y=ytrain)
from sklearn.svm import SVC
import seaborn as sns; sns.set()
from sklearn.datasets.samples_generator import make_circles
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score
X, y = make_circles(100, factor=.2, noise=.2)
Xtrain, Xtest, ytrain, ytest = train_test_split(X,y,random_state=42)
svc = SVC(kernel = "poly")
SVC.fit(X=Xtrain, y=ytrain)
predictions = SVC.predict(ytest)
问题是您在此处创建模型 svc = SVC(kernel = "poly")
,但您使用 non-instantiable 模型调用拟合。
您必须将对象更改为:
svc_model = SVC(kernel = "poly")
svc_model.fit(X=Xtrain, y=ytrain)
predictions = svc_model.predict(Xtest)
我建议你 Indique 测试大小,通常最好的做法是 30% 用于测试,70% 用于训练。所以你可以指出。
Xtrain, Xtest, ytrain, ytest = train_test_split(X,y,test_size=0.30, random_state=42)