本文整理汇总了Python中sklearn.model_selection.GridSearchCV.best_estimator_方法的典型用法代码示例。如果您正苦于以下问题:Python GridSearchCV.best_estimator_方法的具体用法?Python GridSearchCV.best_estimator_怎么用?Python GridSearchCV.best_estimator_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.model_selection.GridSearchCV
的用法示例。
在下文中一共展示了GridSearchCV.best_estimator_方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cross_validation_nb
# 需要导入模块: from sklearn.model_selection import GridSearchCV [as 别名]
# 或者: from sklearn.model_selection.GridSearchCV import best_estimator_ [as 别名]
def cross_validation_nb(train_set,train_target):
# GaussianNB
gnb_clf = clf_set[3]
gnb_score = max(cross_val_score(gnb_clf, train_set, train_target, cv = nfolds))
# MultinomialNB
alpha = [0.001, 0.01, 0.1, 0.3, 0.6, 1]
param_grid = {'alpha':alpha}
mnb_clf = clf_set[4]
grid_search = GridSearchCV(mnb_clf, param_grid, cv=nfolds)
grid_search.fit(train_set, train_target)
mnb_score = grid_search.best_score_
if gnb_score > mnb_score:
best_clf = GaussianNB()
else:
best_clf = grid_search.best_estimator_()
return best_clf