我有一个带有解释性变量的pd.DataFrame :x和另一个带有目标变量y的数据。
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.有人知道我做错了什么吗?
发布于 2017-04-03 16:41:19
线性判别分析是一种分类技术。根据您的错误,Y值涉及某种类型的浮点值数组:
array([ 0.001, 0.003 ...sklearn不知道如何将其解释为类别标签。你确定你应该使用的是LDA而不是某种回归吗?
https://stackoverflow.com/questions/43189690
复制相似问题