简体   繁体   English

'系列' object 没有属性 'getformat'

[英]'Series' object has no attribute 'getformat'

I'm trying to run MLKnn classifier over my pandas dataframe and when I try to fit the classifier I get this error message:我正在尝试在我的 pandas dataframe 上运行 MLKnn 分类器,当我尝试安装分类器时,我收到以下错误消息:

Series object has no attribute 'getformat'

Here's the code:这是代码:

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 is as shown below:我的 dataframe 如下图所示:

dtypes and data head dtypes 和数据头

error message错误信息

I tried with your code, and reading here https://github.com/scikit-learn/scikit-learn/blob/95119c13a/sklearn/model_selection/_search.py#L723 , it says that your parameters shuold be array like.我尝试使用您的代码,并在此处阅读https://github.com/scikit-learn/scikit-learn/blob/95119c13a/sklearn/model_selection/_search.py#L723 ,它说您的参数应该是数组。 So I converted it using numpy and the error went away.所以我使用 numpy 对其进行了转换,错误就消失了。

Here just a snippet with the conversion I did.这里只是我所做的转换的一个片段。

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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM