Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scikit learn sklearn中的网格搜索交叉验证_Scikit Learn - Fatal编程技术网

Scikit learn sklearn中的网格搜索交叉验证

Scikit learn sklearn中的网格搜索交叉验证,scikit-learn,Scikit Learn,网格搜索交叉验证能否用于使用决策树分类器提取最佳参数? 为什么不呢 我邀请您检查的文件 例子 并提取最佳参数: tree.best_params_ Out[1]: {'max_depth': 5} 下面是决策树网格搜索的代码 from sklearn.tree import DecisionTreeClassifier from sklearn.model_selection import GridSearchCV def dtree_grid_search(X,y,nfolds):

网格搜索交叉验证能否用于使用决策树分类器提取最佳参数? 为什么不呢

我邀请您检查的文件

例子 并提取最佳参数:

tree.best_params_
Out[1]: {'max_depth': 5}

下面是决策树网格搜索的代码

from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import GridSearchCV

def dtree_grid_search(X,y,nfolds):
    #create a dictionary of all values we want to test
    param_grid = { 'criterion':['gini','entropy'],'max_depth': np.arange(3, 15)}
    # decision tree model
    dtree_model=DecisionTreeClassifier()
    #use gridsearch to test all values
    dtree_gscv = GridSearchCV(dtree_model, param_grid, cv=nfolds)
    #fit model to data
    dtree_gscv.fit(X, y)
    return dtree_gscv.best_params_

谢谢那么,tree.best_params是最佳功能的名称吗?如果我的功能名称是['a'、'b'、'c'、'd'、'e'],我如何知道最佳功能名称?
树。最佳参数
返回类似于
{'params1':最佳参数}
的词汇。在这种情况下,如果您使用的是
GridSearchCV
,那么您是否希望使用完整的数据集来适应,而不仅仅是训练子集?由于
GridSearchCV
正在执行k-fold CV的某些变体,因此仅使用训练数据似乎是浪费数据。千万不要使用测试集来查找超参数,因为在训练阶段引入不应该有的信息,最终会导致拟合过度。当您没有验证样本时,CV主要用于模拟测试集。@gowithefloww Agree!使用测试集进行超参数调优将是在箭头周围绘制目标的完美示例。
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import GridSearchCV

def dtree_grid_search(X,y,nfolds):
    #create a dictionary of all values we want to test
    param_grid = { 'criterion':['gini','entropy'],'max_depth': np.arange(3, 15)}
    # decision tree model
    dtree_model=DecisionTreeClassifier()
    #use gridsearch to test all values
    dtree_gscv = GridSearchCV(dtree_model, param_grid, cv=nfolds)
    #fit model to data
    dtree_gscv.fit(X, y)
    return dtree_gscv.best_params_