我什么时候必须使用 scikit learn 的 fit 方法?
When do i have to use the fit method of scikit learn?
我不明白什么时候必须使用scikit learn的fit方法。
在此网页中:http://machinelearningmastery.com/automate-machine-learning-workflows-pipelines-python-scikit-learn/
有一个管道 + StandardScaler 的例子。未使用拟合方法。
但在另一个中: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("")
我不明白什么时候必须使用scikit learn的fit方法。
在此网页中:http://machinelearningmastery.com/automate-machine-learning-workflows-pipelines-python-scikit-learn/ 有一个管道 + StandardScaler 的例子。未使用拟合方法。
但在另一个中: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("")