LDA预测手写数字集
import sklearn.datasets as sk from sklearn.discriminant_analysis import LinearDiscriminantAnalysis from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score digitals = sk.load_digits() print(type(digitals.target)) print('手写数据集中有以下类型数据:') print(digitals.keys()) print('\n\ndata为其各像素块数据:') print(digitals.data) print('\n\ntarget为其各图片的标签(实际数字):') print(digitals.target) print('\n\nfeature_names为其各各像素块的名称(列名):') print(digitals.feature_names) print('\n\ntarget_names全部标签都是什么:') print(digitals.target_names) print(digitals.data) exit(0) x_train, x_test, y_train, y_test = train_test_split(digitals.data, digitals.target,test_size=0.2) model = LinearDiscriminantAnalysis(n_components = 2) model.fit(x_train, y_train) print("\n\nX_test为:") print(model.predict(x_test)) print("\n\nY_test值为:") print(y_test) print("\n\n准确度为:") print(accuracy_score(model.predict(x_test),y_test))