2

我正在尝试在我的 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 和数据头

错误信息

4

1 回答 1

1

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

这里只是我所做的转换的一个片段。

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))
于 2021-03-03T10:29:59.737 回答