【问题标题】:Getting error None of the type in columns in pandas, python获取错误在熊猫,python中的列中没有类型
【发布时间】:2020-07-19 14:56:48
【问题描述】:

我正在尝试使用 KFold 在数据集上训练机器学习模型。我不断收到这个关键错误,不知道如何解决。 我已经尝试过中提到的方法 How To Solve KeyError: u"None of [Index([..], dtype='object')] are in the [columns]" 这是我的代码

diffFile = pd.read_csv('Difference.csv', delimiter=',', delim_whitespace= 0)
X = diffFile.iloc[:,[0,1,2]]
y = diffFile.iloc[:,3]
adb = AdaBoostClassifier()
scores = []
kf = KFold(n_splits=30)
for train_index,test_index in kf.split(X):
    X_train,X_test=X[train_index],X[test_index]
    y_train,y_test=y[train_index],y[test_index]
    adb.fit(X_train,y_train)
    scores.append(adb.score(X_test,y_test))

这是我的文件 https://drive.google.com/file/d/1_VwBNSADq6l893VFiULVPzrBYiB-fqyo/view?usp=sharing

我正在使用带有 Python 3.7 的 Jupyter Notebook 任何帮助将非常感激。 谢谢你

【问题讨论】:

  • 你的问题是什么?

标签: python pandas


【解决方案1】:

应该是:

X_train,X_test=X.iloc[train_index],X.iloc[test_index]
y_train,y_test=y.iloc[train_index],y.iloc[test_index]

您正在尝试使用 X[train_index] 为 X 建立索引,但这里有 pandas 数据框。

【讨论】:

  • 非常感谢,我是数据科学的初学者,您可以为我推荐任何课程吗?
  • 付费:应用课程,免费:有一些 youtube 频道,如 krish naik 的频道
猜你喜欢
  • 2018-05-07
  • 2020-09-23
  • 1970-01-01
  • 2020-09-25
  • 2023-01-04
  • 2013-03-31
相关资源
最近更新 更多