【问题标题】:'Series' object has no attribute 'getformat'“系列”对象没有属性“getformat”
【发布时间】:2021-03-02 21:28:15
【问题描述】:

我正在尝试在我的 pandas 数据帧上运行 MLKnn 分类器,当我尝试拟合分类器时,我收到以下错误消息:

Series object has no attribute 'getformat'

代码如下:

from skmultilearn.adapt import MLkNN
from sklearn.model_selection import GridSearchCV

parameters = {'k': range(1,3), 's': [0.5, 0.7, 1.0]}
score = 'f1_macro'

X = dados.drop(['defects'], axis=1)

y = dados['defects']
X_train, X_test, y_train, y_test = train_test_split(X, y,random_state=1)

classifier = GridSearchCV(MLkNN(), parameters,scoring=score)
classifier.fit(X_train, y_train)

我的数据框如下图:

dtypes and data head

error message

【问题讨论】:

  • 请添加错误输出以获取更多详细信息,例如错误发生在哪一行,您有回溯 sn -p 吗?
  • 我用错误信息更新了原帖
  • 看来基本上你是在传递 2 pd 系列给你拆分。但是文档说 --> scikit-learn.org/stable/modules/generated/…
  • 我的 DF 是通过传递我的文件路径的 pd.read_csv 生成的,我使用了与 KNeighborsClassifier 相同的 train_test_split 技术,它工作得很好,你对我应该如何进行有什么建议吗? (抱歉有任何拼写错误,英语不是我的主要语言。)

标签: python scikit-learn knn scikit-multilearn


【解决方案1】:

我尝试使用您的代码,并在此处阅读https://github.com/scikit-learn/scikit-learn/blob/95119c13a/sklearn/model_selection/_search.py#L723,它说您的参数应该是数组。所以我使用 numpy 对其进行了转换,错误消失了。

这里只是一个我所做的转换的 sn-p。

from skmultilearn.adapt import MLkNN
from sklearn.model_selection import GridSearchCV, train_test_split
import numpy as np

parameters = {'k': range(1,3), 's': [0.5, 0.7, 1.0]}
score = 'f1_macro'

X = dados.drop(['defects'], axis=1)
y = dados['defects']

X_train, X_test, y_train, y_test = train_test_split(X, y,random_state=1)
classifier = GridSearchCV(MLkNN(), parameters,scoring=score)
classifier.fit(np.array(X_train), np.array(y_train))

【讨论】:

  • 我试过你的解决方法,错误信息如下图/usr/local/lib/python3.7/dist-packages/scipy/sparse/lil.py in _get_row_ranges(self, rows, col_slice) 296 new.rows, new.data, 297 rows, --> 298 j_start, j_stop, j_stride, nj) 299 300 return new _csparsetools.pyx in scipy.sparse._csparsetools.lil_get_row_ranges() ValueError: row index 147 out of bounds
  • 你检查Xy的形状了吗? X 的形状必须是 (n_samples, n_features),y 必须是 (n_samples, n_output) 或 (n_samples,)
  • X 的形状为 (373,21),y 的形状为 (373,)
猜你喜欢
  • 2019-06-30
  • 2020-11-11
  • 2019-04-22
  • 2019-07-26
  • 2020-04-04
  • 2019-09-16
  • 2017-12-12
  • 2018-05-25
  • 2019-07-07
相关资源
最近更新 更多