-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
47 lines (37 loc) · 1.64 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from data.load_data import load_mnist_data
from visualisation.plot_functions import plot_digit, plot_digits
from models.sgd_classifier import train_sgd_classifier, predict_digit, cross_validate_sgd
from models.dummy_classifier import evaluate_dummy_classifier
from evaluation.metrics import calculate_metrics, plot_precision_recall_vs_threshold, plot_precision_vs_recall, plot_roc_curve
from models.random_forest_classifier import evaluate_random_forest
from models.svm_classifier import evaluate_svm
from models.knn_classifier import evaluate_knn
from evaluation.cross_validation import stratified_k_fold_cross_validation
import matplotlib.pyplot as plt
# Load the MNIST data
X_train, X_test, y_train, y_test = load_mnist_data()
# Visualize a digit
some_digit = X_train[0]
plot_digit(some_digit)
plt.show()
# Train and evaluate the SGD classifier
sgd_clf, y_train_5, y_test_5 = train_sgd_classifier(X_train, y_train)
y_scores = cross_validate_sgd(sgd_clf, X_train, y_train_5)
calculate_metrics(y_train_5, y_scores)
# Perform Stratified K-Fold cross-validation
stratified_k_fold_cross_validation(sgd_clf, X_train, y_train_5)
# Train and evaluate the Dummy classifier
evaluate_dummy_classifier(X_train, y_train_5)
# Plot precision-recall and ROC curves
plot_precision_recall_vs_threshold(y_train_5, y_scores)
plt.show()
plot_precision_vs_recall(y_train_5, y_scores)
plt.show()
plot_roc_curve(y_train_5, y_scores)
plt.show()
# Train and evaluate the Random Forest classifier
evaluate_random_forest(X_train, y_train_5)
# Train and evaluate the SVM classifier
evaluate_svm(X_train, y_train)
# Train and evaluate the KNN classifier
evaluate_knn(X_train, y_train, X_test, y_test)