Skip to content

Commit d204c13

Browse files
authored
Add files via upload
1 parent 20ee540 commit d204c13

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Demo_LDA.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import numpy as np
2+
from sklearn import datasets
3+
# chaneg this to switch algorithm & types of validation (jho, jkfold, jloo)
4+
from ML.lda import jloo
5+
import matplotlib.pyplot as plt
6+
import seaborn as sns
7+
8+
9+
iris = datasets.load_iris()
10+
feat = iris.data
11+
label = iris.target
12+
13+
# parameters
14+
opts = {}
15+
# machine learning
16+
mdl = jloo(feat, label, opts)
17+
18+
# overall accuracy
19+
accuracy = mdl['acc']
20+
21+
# confusion matrix
22+
confmat = mdl['con']
23+
print(confmat)
24+
25+
# precision & recall
26+
result = mdl['r']
27+
print(result)
28+
29+
# plot confusion matrix
30+
uni = np.unique(label)
31+
# Normalise
32+
con = confmat.astype('float') / confmat.sum(axis=1)[:, np.newaxis]
33+
fig, ax = plt.subplots()
34+
sns.heatmap(con, annot=True, fmt='.2f', xticklabels=uni, yticklabels=uni, cmap="YlGnBu")
35+
plt.ylabel('Actual')
36+
plt.xlabel('Predicted')
37+
plt.title('LDA')
38+
plt.show()

0 commit comments

Comments
 (0)