第69集 python机器学习:网格搜索预处理及其模型选择( 六 )

#不需要预处理) , 则可以将该步骤设置为None 。

from sklearn.ensemble import RandomForestClassifier

cancer = load_breast_cancer()

param_grid = [{'classifier': [SVC()
'preprocessing': [StandardScaler() None

'classifier__gamma': [0.0010.010.1110100

'classifier__C': [0.0010.010.1110100

{'classifier': [RandomForestClassifier(n_estimators=100)
'preprocessing':  [None

'classifier__max_features': [1 2 3

#将网格搜索实例化并运行

x_train x_test y_train y_test = train_test_split(cancer.data cancer.target random_state=0)

grid = GridSearchCV(pipe param_grid cv=5)

推荐阅读