Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python scikit学习中的多标签编码_Python_Scikit Learn - Fatal编程技术网

Python scikit学习中的多标签编码

Python scikit学习中的多标签编码,python,scikit-learn,Python,Scikit Learn,我正在尝试对数据帧的目标列进行编码。此列包含的变量类型为object 我有一个包含所有代码的DataFrame,icd10。使用这些,我试图对我的infoDFDataFrame的标签进行二值化 我的代码如下所示: from sklearn import preprocessing lb = preprocessing.LabelBinarizer() #fit all the possible label codes lb.fit(icd10['ICD10']) temp = lb.trans

我正在尝试对数据帧的目标列进行编码。此列包含的变量类型为object

我有一个包含所有代码的
DataFrame
icd10
。使用这些,我试图对我的
infoDF
DataFrame
的标签进行二值化

我的代码如下所示:

from sklearn import preprocessing

lb = preprocessing.LabelBinarizer()
#fit all the possible label codes
lb.fit(icd10['ICD10'])
temp = lb.transform(infoDF['Target'])
for i,x in enumerate(lb.classes_):
    infoDF[x] = temp[ : , i]
当我运行它时,我得到以下回溯:

  File "<ipython-input-42-2b1db450b16e>", line 3, in <module>
    lb.fit(icd10['ICD10'])

  File "C:\Users\as\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\preprocessing\label.py", line 413, in fit
    self.classes_ = unique_labels(y)

  File "C:\Users\as\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\utils\multiclass.py", line 96, in unique_labels
    raise ValueError("Unknown label type: %s" % repr(ys))

ValueError: Unknown label type: (0              1
1              2
2              3
3              4
4              5
5              6
6              7
7              8
8              9
9             10
10            11
11            12
12            13
13            14
14            15
15            16
16            17
17            18
18            19
19            20
20            21
21            22
22           A00
23          A000
24          A001
25          A009
26       A00–A09
27           A01
28          A010
29          A011

19433       Z960
19434       Z961
19435       Z962
19436       Z963
19437       Z964
19438       Z965
19439       Z966
19440       Z967
19441       Z968
19442       Z969
19443        Z97
19444       Z970
19445       Z971
19446       Z972
19447       Z973
19448       Z974
19449       Z975
19450       Z978
19451        Z98
19452       Z980
19453       Z981
19454       Z982
19455       Z988
19456        Z99
19457       Z990
19458       Z991
19459       Z992
19460       Z993
19461       Z998
19462       Z999
Name: ICD10, Length: 19463, dtype: object,)
文件“”,第3行,在
lb.fit(icd10['icd10'])
文件“C:\Users\as\AppData\Local\Continuum\anaconda3\lib\site packages\sklearn\preprocessing\label.py”,第413行
self.classes=唯一标签(y)
文件“C:\Users\as\AppData\Local\Continuum\anaconda3\lib\site packages\sklearn\utils\multiclass.py”,第96行,使用唯一的\u标签
提升值错误(“未知标签类型:%s”%repr(ys))
ValueError:未知的标签类型:(0 1)
1              2
2              3
3              4
4              5
5              6
6              7
7              8
8              9
9             10
10            11
11            12
12            13
13            14
14            15
15            16
16            17
17            18
18            19
19            20
20            21
21            22
22 A00
23 A000
24 A001
25 A009
26 A00–A09
27 A01
28 A010
29 A011
19433 Z960
19434 Z961
19435 Z962
19436 Z963
19437 Z964
19438 Z965
19439 Z966
19440Z967
19441Z968
19442 Z969
19443 Z97
19444 Z970
19445 Z971
19446 Z972
19447 Z973
19448 Z974
19449 Z975
19450Z978
19451 Z98
19452 Z980
19453 Z981
19454 Z982
19455 Z988
19456 Z99
19457 Z990
19458 Z991
19459 Z992
19460 Z993
19461 Z998
19462 Z999
名称:ICD10,长度:19463,数据类型:object,)

我不确定我做错了什么。

虽然我们没有您的数据集的确切格式,但似乎是初始整数导致了问题

sklearn的LabelBinarizer调用,根据文档,它不允许“字符串和整数标签的混合”

尝试删除前21行,查看错误是否仍然存在

import pandas as pd
from sklearn import preprocessing

lb = preprocessing.LabelBinarizer()

icd11 = pd.DataFrame({'ICD11': [0, '6C51', '6C50.Z']})

# crashes
lb.fit(icd11['ICD11'])

# does not crash
lb.fit(icd11['ICD11'][1:])