我正在尝试适合我使用管道组合的模型:
from sklearn import cross_validation
from sklearn.linear_model import LogisticRegression
from sklearn.grid_search import GridSearchCV
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import MinMaxScaler
cross_validation_object = cross_validation.StratifiedKFold(Y, n_folds = 10)
scaler = MinMaxScaler(feature_range = [0,1])
logistic_fit = LogisticRegression()
pipeline_object = Pipeline([('scaler', scaler),('model', logistic_fit)])
tuned_parameters = [{'model__C': [0.01,0.1,1,10],
'model__penalty': ['l1','l2']}]
grid_search_object = GridSearchCV(pipeline_object, tuned_parameters, cv = cross_validation_object, scoring = 'accuracy')
grid_search_object.fit(X_train,Y_train)
我的问题是:best_estimator是否会根据训练数据中的值来缩放测试数据?例如,如果我调用:
grid_search_object.best_estimator_.predict(X_test)
它不会尝试在X_test数据上拟合标量,对吧?它会用原始参数对它进行变换。
谢谢!
predict
方法不适合任何数据。在这种情况下,正如你所描述的,best_estimator_
管道将根据它在训练集中学习到的缩放来缩放。