我试图在我的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)
my dataframe如下所示:
dtypes and data head
错误消息
我尝试了你的代码,阅读这里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))