sklearn中gridsearchcv 与pipeline结合使用

X = train[column]
y=(train["class"]-1).astype(int)
tfid = TfidfVectorizer(use_idf = 1,
                       smooth_idf = 1,
                       sublinear_tf = 1,
                       max_df = 0.9,
                       min_df = 3,
                       ngram_range = (1,3))
X_feature = tfid.fit_transform(X)

esta = svm.LinearSVC()
pip = Pipeline([('tfid',tfid),('esta',esta)])
param = dict(tfid__max_features=[100000,200000,300000])
grid = GridSearchCV(pip,param_grid = param,scoring='f1_weighted')
grid.fit(X,y)
print('best params:'% grid.best_params_)

print("Best score: %0.3f" % grid.best_score_)

 

你可能感兴趣的:(机器学习)