我正在使用Python 3.6.1 | Anaconda 4.4.0
我是ML的新手,在学习的同时练习。我选择了一个kagle数据集来练习LDA以减少维数。出现了两个混乱:
代码:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
datasets = pd.read_csv('mushrooms.csv')
X_df = datasets.iloc[:, 1:] # Independent variables
y_df = datasets.iloc[:, 0] # Dependent variables
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
X_df = X_df.apply(LabelEncoder().fit_transform)
x = OneHotEncoder(sparse=False).fit_transform(X_df.values)
y = LabelEncoder().fit_transform(y_df.values)
# Splitting dataset in to training set and test set.
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test =
train_test_split(x,y,test_size=0.2,random_state=0)
# Feature scaling
from sklearn.preprocessing import StandardScaler
sc_x = StandardScaler()
x_train = sc_x.fit_transform(x_train)
x_test = sc_x.transform(x_test)
#---------------------------------------------
# Applying LDA (Linear Discriminant Analysis)
#---------------------------------------------
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
lda = LDA(n_components = 2)
x_train = lda.fit_transform(x_train, y_train)
x_test = lda.transform(x_test)
答案 0 :(得分:3)
这表明错误消息的内容是:您的一些变量是共线的。换句话说,一个向量的元素是另一个向量的元素的线性函数,例如
0, 1, 2, 3
3, 5, 7, 9
在这种情况下,LDA无法区分他们对世界其他地区的影响。
我无法诊断任何特定的内容,因为您未能提供建议的MCVE。