【scikit-learn】GridSearchCV 在wind

2018-02-18  本文已影响0人  脑荼地

先说下环境:Win10+spyder+py3.6

贴下成功运行的代码:

from sklearn.datasets import load_wine
from sklearn.model_selection import GridSearchCV
from sklearn import svm
from sklearn.ensemble import BaggingClassifier

def Test(): 
    data = load_wine()
    Feat = data.data
    Label = data.target
    bag_clf = BaggingClassifier( base_estimator=svm.SVC(kernel='rbf'), bootstrap=True,n_jobs=-1)
    bag_clf.fit(Feat,Label) 
    Params = [{"base_estimator__C":[1,2,3],
               "base_estimator__gamma":[1.2,0.9],
               "max_features":[0.3,0.4,0.5],
               "max_samples":[0.9,0.8,0.7],
               "n_estimators":[60,80,100],
               "random_state":[120,100]}]
    grid_search = GridSearchCV(bag_clf, Params, cv=5,verbose=1.1,n_jobs=-1)
    grid_search.fit(Feat,Label)
    print('bestparam=',grid_search.best_params_ ,'score=',grid_search.best_score_)
        
if __name__ == '__main__':
    __spec__ = None
    Test() 
运行结果如下: 运行结果
上一篇下一篇

猜你喜欢

热点阅读