【问题标题】:I can't use RandomForest inside a loop?我不能在循环中使用 RandomForest?
【发布时间】:2020-11-14 10:42:45
【问题描述】:

我正在尝试获取 RandomForest 参数的最佳值,这就是我使用此循环的原因:

''' from sklearn.ensemble 导入随机森林分类器

train_f1 = []
test_f1 = []

for i in range(10,100,10):
    
    clf=RandomForestCLassifier(min_samples_split=i)
    clf.fit(x_train2, y_train2)
  
    temp = clf.predict(x_train2)
    temp = f1_score(tmp,y_train2)
    train_f1.append(temp)

    tmp = clf.predict(x_valid)
    tmp = f1_score(tmp,y_valid)
    test_f1.append(tmp)

但是,我收到此错误:“名称 'RandomForestCLassifier' 未定义”。我不知道这个错误在说什么。有人可以帮我解决这个问题吗?

【问题讨论】:

  • 检查您的大小写。
  • RandomForestClassifier(3个大写字母,你的有4个)
  • @dm2 谢谢大声笑。我需要多加注意
  • 每个人都会遇到,只需要了解要查找的内容。我相信你下次遇到类似错误时会检查这个:D

标签: pandas dataframe random-forest


【解决方案1】:

您需要先从 scikit-learn 导入 RandomForestCLassifier

from sklearn.ensemble import RandomForestClassifier

(编辑)你拼错了RandomForestClassifierL 应该小写。

【讨论】:

    猜你喜欢
    • 2021-07-25
    • 2018-05-06
    • 1970-01-01
    • 1970-01-01
    • 2020-08-02
    • 1970-01-01
    • 1970-01-01
    • 2019-08-13
    • 1970-01-01
    相关资源
    最近更新 更多