1
我有一个pd.DataFrame与解释变量:X和另一个与目标变量y的数据框。python LDA scikit学习抛出ValueError
type(X)
Out[1]: pandas.core.frame.DataFrame
X_num.shape
Out[2]: (1213, 3298)
和
type(y)
Out[3]: pandas.core.frame.DataFrame
y.shape
Out[4]: (1213, 8)
,我想只用一个Y列计算LDA:
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
lda = LDA(n_components=2)
for col in y:
X_t = lda.fit(X.copy(), y[col].copy())
y的列名
y[col].name
Out[5]: u'myvarname'
,但我总是得到错误
ValueError: Unknown label type: (array([ 0.001, 0.003 ...
我也试过
X_t = lda.fit(X.copy(), y[col].values.copy())
,并得到了同样的错误。
根据帮助适合需要为Y
Y : array-like of response, shape = [n_samples, n_targets]
Target vectors, where n_samples in the number of samples
and n_targets is the number of response variables.
任何人的想法我做错了什么?
很好,转换为字符串做到了。 y值是类别,但保存为浮点数,因此分类是正确的工具。 – horseshoe