-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperformance-metrics-classical-ML.py
More file actions
56 lines (47 loc) · 2.94 KB
/
performance-metrics-classical-ML.py
File metadata and controls
56 lines (47 loc) · 2.94 KB
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
48
49
50
51
52
53
54
55
56
import matplotlib.pyplot as plt
import pandas as pd
# Data for Logistic Regression
data_logistic_regression = {
"Step": range(1, 11),
"Precision": [0.40, 0.14, 0.96, 0.96, 0.40, 0.40, 0.96, 0.96, 0.97, 0.96],
"Recall": [0.63, 0.37, 0.96, 0.96, 0.63, 0.63, 0.96, 0.96, 0.97, 0.96],
"F1 Score": [0.49, 0.20, 0.96, 0.96, 0.49, 0.49, 0.96, 0.96, 0.97, 0.96]
}
# Data for Support Vector Machine (SVM)
data_svm = {
"Step": range(1, 11),
"Precision": [0.40, 0.40, 0.40, 0.40, 0.97, 0.97, 0.97, 0.97, 0.96, 0.96],
"Recall": [0.63, 0.63, 0.63, 0.63, 0.97, 0.97, 0.97, 0.97, 0.96, 0.96],
"F1 Score": [0.49, 0.49, 0.49, 0.49, 0.97, 0.97, 0.97, 0.97, 0.96, 0.96]
}
# Data for Random Forest
data_random_forest = {
"Step": range(1, 15),
"Precision": [0.82, 0.82, 0.32, 0.82, 0.82, 0.86, 0.89, 0.89, 0.96, 0.96, 0.96, 0.96, 0.96, 0.96],
"Recall": [0.50, 0.50, 0.50, 0.52, 0.53, 0.67, 0.75, 0.77, 0.93, 0.93, 0.93, 0.93, 0.93, 0.93],
"F1 Score": [0.39, 0.40, 0.39, 0.42, 0.46, 0.67, 0.77, 0.79, 0.94, 0.94, 0.94, 0.94, 0.94, 0.94]
}
# Convert to DataFrames
df_logistic_regression = pd.DataFrame(data_logistic_regression)
df_svm = pd.DataFrame(data_svm)
df_random_forest = pd.DataFrame(data_random_forest)
# Plot Precision, Recall, and F1 Score Comparison for Logistic Regression, SVM, and Random Forest
plt.figure(figsize=(12, 6))
# Logistic Regression
plt.plot(df_logistic_regression["Step"], df_logistic_regression["Precision"], marker='o', linestyle='-', linewidth=2, color='purple', label="Logistic Regression Precision")
plt.plot(df_logistic_regression["Step"], df_logistic_regression["Recall"], marker='s', linestyle='--', linewidth=2, color='purple', label="Logistic Regression Recall", alpha=0.8)
plt.plot(df_logistic_regression["Step"], df_logistic_regression["F1 Score"], marker='d', linestyle=':', linewidth=2, color='purple', label="Logistic Regression F1 Score", alpha=0.6)
# SVM
plt.plot(df_svm["Step"], df_svm["Precision"], marker='o', linestyle='-', linewidth=2, color='brown', label="SVM Precision")
plt.plot(df_svm["Step"], df_svm["Recall"], marker='s', linestyle='--', linewidth=2, color='brown', label="SVM Recall", alpha=0.8)
plt.plot(df_svm["Step"], df_svm["F1 Score"], marker='d', linestyle=':', linewidth=2, color='brown', label="SVM F1 Score", alpha=0.6)
# Random Forest
plt.plot(df_random_forest["Step"], df_random_forest["Precision"], marker='o', linestyle='-', linewidth=2, color='darkgreen', label="Random Forest Precision")
plt.plot(df_random_forest["Step"], df_random_forest["Recall"], marker='s', linestyle='--', linewidth=2, color='darkgreen', label="Random Forest Recall", alpha=0.8)
plt.plot(df_random_forest["Step"], df_random_forest["F1 Score"], marker='d', linestyle=':', linewidth=2, color='darkgreen', label="Random Forest F1 Score", alpha=0.6)
plt.xlabel("Step")
plt.ylabel("Score (%)")
plt.title("Precision, Recall, and F1 Score Comparison: Logistic Regression vs. SVM vs. Random Forest")
plt.legend()
plt.grid(True)
plt.show()