text_plain_output_1.png
from sklearn.metrics import accuracy_score

import numpy as np

import pandas as pd

mnist_train = pd.read_csv('../input/mnist-in-csv/mnist_train.csv')
mnist_test = pd.read_csv('../input/mnist-in-csv/mnist_test.csv')

X_train = mnist_train.iloc[:, 1:785]
y_train = mnist_train.iloc[:, 0]
lda = LDA(n_components=9)
X_train_r2 = lda.fit(X_train, y_train)

X_test = mnist_test.iloc[:, 1:785]
y_test = mnist_test.iloc[:, 0]

y_pred = lda.predict(X_test)

w = lda.coef_
w.shape

w0 = lda.intercept_
np.transpose(w0).shape

y_test_final = mnist_test.loc[mnist_test['label'].isin([3, 8])]
y_test_final = y_test_final.iloc[:, 0]
X_test_final = mnist_test.loc[mnist_test['label'].isin([3, 8])]
X_test_final = X_test_final.iloc[:, 1:785]

y_train_final = mnist_train.loc[mnist_train['label'].isin([3, 8])]
y_train_final = y_train_final.iloc[:, 0]
X_train_final = mnist_train.loc[mnist_train['label'].isin([3, 8])]
X_train_final = X_train_final.iloc[:, 1:785]

lda1 = LDA(n_components=1)
X_train_r21 = lda1.fit(X_train_final, y_train_final)

y_pred1 = lda1.predict(X_test_final)

w = lda1.coef_
w.shape