【问题标题】:sklearn: Found input variables with inconsistent numbers of samples while using RandomForestClassifiersklearn:在使用 RandomForestClassifier 时发现样本数量不一致的输入变量
【发布时间】:2022-01-10 04:52:22
【问题描述】:

我正在使用 RandomForestClassifier 和某个数据集解决分类问题,当我尝试运行我的程序时,出现一条错误消息,显示:“发现样本数量不一致的输入变量:[242, 61]”。我应该怎么办? 代码是:-

from sklearn.ensemble import RandomForestClassifier
np.random.seed(42)
X=heart_disease.drop('target',axis=1)
y=heart_disease['target']
X_train,y_train,X_test,y_test=train_test_split(X,y,test_size=0.2)
clf=RandomForestClassifier()
clf.fit(X_train, y_train)
clf.score(X_test,y_test)

【问题讨论】:

    标签: python scikit-learn classification


    【解决方案1】:

    那是因为train_test_split的返回不正确试试这个:

    X_train, X_test, y_train, y_test=train_test_split(X,y,test_size=0.2)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-23
      • 1970-01-01
      • 2021-02-02
      • 2021-06-20
      • 2018-06-25
      • 2021-05-06
      • 2020-11-19
      • 2019-12-11
      相关资源
      最近更新 更多