代码之家  ›  专栏  ›  技术社区  ›  stone rock

使用gridsearchcv时出现类型错误?

  •  -1
  • stone rock  · 技术社区  · 6 年前

    我在试着调音 n_estimators 属于 RandomForestClassifier 使用 GridSearchCV . 但我收到输入错误-> TypeError: get_params() missing 1 required positional argument: 'self'

    代码:

    from sklearn.grid_search import GridSearchCV
    from sklearn.ensemble import RandomForestClassifier
    
    n_trees = list(range(10,110,10))
    print(n_trees)
    
    [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
    
    param_grid = dict(n_estimators=n_trees)
    print(param_grid)
    
    {'n_estimators': [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]}
    
    grid = GridSearchCV(RandomForestClassifier, param_grid, cv=5, scoring='roc_auc')
    
    
    grid.fit(X,y)   <--- Getting error at this cell
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   ababuji    6 年前

    在线中 grid = GridSearchCV(RandomForestClassifier, param_grid, cv=5, scoring='roc_auc') ,而不是你写的,试着 grid = GridSearchCV(RandomForestClassifier(), param_grid, cv=5, scoring='roc_auc')

    我不能肯定…因为你没有给我 X y ,或者我可以在我的笔记本电脑中复制它,让你知道它是否有效!

    如果有用就告诉我!