【发布时间】:2017-03-22 10:44:58
【问题描述】:
我不明白什么时候必须使用 scikit learn 的 fit 方法。
在此网页中:http://machinelearningmastery.com/automate-machine-learning-workflows-pipelines-python-scikit-learn/ 有一个管道 + StandardScaler 的例子。不使用fit方法。
但在另一个:http://scikit-learn.org/stable/auto_examples/svm/plot_rbf_parameters.html 还有一个StandardScaler,还有一个fit方法。
这是我的代码:Pipeline+Robustscaler:
result_list = []
for name in ["AWA","Rem","S1","S2","SWS","SX", "ALL"]:
x=sio.loadmat('/home/{}_E.mat'.format(name))['x']
s_y=sio.loadmat('/home/{}_E.mat'.format(name))['y']
y=np.ravel(s_y)
print(name, x.shape, y.shape)
print("")
#Create a pipeline
clf = make_pipeline(preprocessing.RobustScaler(), SVC(cache_size=1000, kernel='rbf'))
###################10x20 SSS##################################
print("10x20")
xSSSmean20 = []
for i in range(10):
sss= StratifiedShuffleSplit(y, 20, test_size=0.1, random_state=i)
scoresSSS=cross_validation.cross_val_score(clf, x, y, cv=sss)
xSSSmean20.append(scoresSSS.mean())
result_list.append(xSSSmean20)
print("")
【问题讨论】:
-
为什么这是一个不好的问题?
-
因为
The fit method is not used.是错误的说法。用于cross_val_score -
好的。谢谢你。我不知道。
标签: python-3.x scikit-learn svm