简体   繁体   English

MLKNN - __int__() 采用 1 个位置参数,但 2 个是使用 fit 方法给出的

[英]MLKNN - __int__() takes 1 positional argument but 2 were given with fit method

I have two pandas dataframes.我有两个 pandas 数据帧。 one df(or X) with word2vec embeddings, with shape (50000,200).一个带有 word2vec 嵌入的 df(或 X),形状为 (50000,200)。 and another dataframe (or sparse matrix) with 0s and 1s filled.和另一个填充了 0 和 1 的 dataframe(或稀疏矩阵)。 this df is the output of sklearn.preprocessing.MultiLabelBinarizer , so filled with only 1s and 0s in every column and shape of this df is (50000, 102).这个 df 是 sklearn.preprocessing.MultiLabelBinarizer 的output ,所以在每一列中只填充了 1 和 0,这个 df 的形状是 (50000, 102)。

I have tried fitting a skmultilearn.adapt.mlknn on this data, as shown below:我尝试在这些数据上拟合skmultilearn.adapt.mlknn ,如下所示:

from skmultilearn.adapt import MLkNN
classifier = MLkNN(k=3)
# train
classifier.fit(X=x_train_w2v.to_numpy(), y=y_train.to_numpy())

the error I get is:我得到的错误是:

TypeError Traceback (most recent call last)
<ipython-input-36-5ae90a2db4ec> in <module>
5 # # train
6
----> 7 clf_mlknn.fit(X=x_train_w2v.to_numpy(),y=y_train.to_numpy())
8 # predict
9 # predict_mlknn_wv = classifier_new.predict(x_test_mlknn)


~\Anaconda3\lib\site-packages\skmultilearn\adapt\mlknn.py in fit(self, X, y)
216 self._prior_prob_true, self._prior_prob_false = self._compute_prior(self._label_cache)
217 # Computing the posterior probabilities
--> 218 self._cond_prob_true, self._cond_prob_false = self._compute_cond(X, self._label_cache)
219 return self
220


~\Anaconda3\lib\site-packages\skmultilearn\adapt\mlknn.py in _compute_cond(self, X, y)
163 """
164
--> 165 self.knn_ = NearestNeighbors(self.k).fit(X)
166 c = sparse.lil_matrix((self._num_labels, self.k + 1), dtype='i8')
167 cn = sparse.lil_matrix((self._num_labels, self.k + 1), dtype='i8')


TypeError: __init__() takes 1 positional argument but 2 were given

from the source code, i could see that NearestNeighbors was being fit only with X, which can also be seen in above error in the line that starts with --> 165 .从源代码中,我可以看到NearestNeighbors只适用于 X,这也可以在以上错误中以--> 165开头的行中看到。 I presume that is what generating the error.我认为这是产生错误的原因。

How do I fix this error and fit MLkNN properly?如何修复此错误并正确安装 MLkNN?

The error is related to a deprecation warning that was already indicated by scikit-learn for NearestNeighbors:该错误与 scikit-learn 已针对 NearestNeighbors 指示的弃用警告有关:

FutureWarning: Pass n_neighbors=3 as keyword args. FutureWarning:将 n_neighbors=3 作为关键字参数传递。 From version 1.0 (renaming of 0.25) passing these as positional arguments will result in an error "will result in an error", FutureWarning)从版本 1.0(重命名为 0.25)开始,将这些作为位置 arguments 传递将导致错误“将导致错误”,FutureWarning)

This issue has been adapted here and it will be included in next releases:此问题已在此处进行了调整,并将包含在下一个版本中:

https://github.com/scikit-multilearn/scikit-multilearn/issues/230 https://github.com/scikit-multilearn/scikit-multilearn/issues/230

In the meantime it is possible to use the solution of @Naveen-Reddy-Marthala MLKNN - __int__() takes 1 positional argument but 2 were given with fit method :同时,可以使用@Naveen-Reddy-Marthala MLKNN 的解决方案 - __int__() 采用 1 个位置参数,但 2 个是通过 fit 方法给出的

!pip uninstall scikit-learn -y
!pip install scikit-learn==0.24.1

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

相关问题 类型错误:fit() 需要 1 个位置参数,但给出了 3 个 - TypeError: fit() takes 1 positional argument but 3 were given Google storage.Client 抛出 .__int__ 错误:接受 2 个位置参数,但给出了 3 个 - Google storage.Client throwing .__int__ error: takes 2 positional arguments but 3 were given 类方法采用1个位置参数,但给出了2个 - Class method takes 1 positional argument but 2 were given method() 接受 1 个位置参数,但给出了 4 个? - method() takes 1 positional argument, but 4 were given? 方法采用 1 个位置参数,但给出了 2 个 - Method takes 1 positional argument but 2 were given TypeError:method() 接受 1 个位置参数,但给出了 2 个 - TypeError: method() takes 1 positional argument but 2 were given sklearn 管道错误 - fit() 采用 1 个位置参数,但给出了 3 个 - sklearn pipeline error - fit() takes 1 positional argument but 3 were given 需要1个位置参数,但给出2个 - takes 1 positional argument but 2 were given 类方法上的 Python 错误:“采用 1 个位置参数,但给出了 2 个” - Python error on class method: 'takes 1 positional argument but 2 were given' 在self.Bind上,wxPython方法“需要1个位置参数但是2个被赋予” - wxPython method “takes 1 positional argument but 2 were given” on self.Bind
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM