2
下面的代碼給出錯誤信息:應用sklearn功能大熊貓數據幀給ValueError異常(「未知標籤類型:%R」%Y)
>>> import pandas as pd
>>> from sklearn import preprocessing, svm
>>> df = pd.DataFrame({"a": [0,1,2], "b":[0,1,2], "c": [0,1,2]})
>>> clf = svm.SVC()
>>> df = df.apply(lambda x: preprocessing.scale(x))
>>> clf.fit(df[["a", "b"]], df["c"])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Alexander\Anaconda\lib\site-packages\sklearn\svm\base.py", lin
151, in fit
y = self._validate_targets(y)
File "C:\Users\Alexander\Anaconda\lib\site-packages\sklearn\svm\base.py", lin
515, in _validate_targets
check_classification_targets(y)
File "C:\Users\Alexander\Anaconda\lib\site-packages\sklearn\utils\multiclass.
y", line 173, in check_classification_targets
raise ValueError("Unknown label type: %r" % y)
ValueError: Unknown label type: 0 -1.224745
1 0.000000
2 1.224745
Name: c, dtype: float64
大熊貓數據幀的D型細胞不是一個對象,所以應用sklearn svm函數應該沒問題,但由於某種原因它不能識別分類標籤。什麼導致這個問題?
嘗試'DF [ 「A」, 「B」]] values'和'DF [ 「C」] values' SKLearn通常預計的陣列,不是數據框。 –
同樣的問題,錯誤信息是: – Alex
raise ValueError(「Unknown label type:%r」%y) ValueError:Unknown label type:array([ - 1.22474487,0.,1.22474487]) – Alex