Skip to content

Commit 1042a29

Browse files
committed
seperated out the model metrics into its own notebook, and put functions in the model.py file
1 parent 74a940f commit 1042a29

6 files changed

+654
-89
lines changed
180 Bytes
Loading

Notebooks/02_Baseline Model.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
},
5454
{
5555
"cell_type": "code",
56-
"execution_count": 5,
56+
"execution_count": 3,
5757
"id": "17b38552-4ffe-4ac9-b9ba-2ee96faa0e8d",
5858
"metadata": {
5959
"tags": []
@@ -142,7 +142,7 @@
142142
},
143143
{
144144
"cell_type": "code",
145-
"execution_count": 8,
145+
"execution_count": 5,
146146
"id": "48a01f31-0afb-4cc5-9de3-3f0b4e4a3eba",
147147
"metadata": {},
148148
"outputs": [],

Notebooks/03_Neural_network.ipynb

+88-84
Large diffs are not rendered by default.

Notebooks/04_Model_evaluation.ipynb

+546
Large diffs are not rendered by default.

Notebooks/scores.csv

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
,Accuracy,Precision,Recall,F1 Score
22
baseline,0.4698703279938978,0.4683084749604378,0.4698703279938978,0.4635669509975083
3-
Neural Network,0.8520213577421816,0.850317486655664,0.8520213577421816,0.846736447406065
4-
Neural Network: regularization,0.8245614035087719,0.8200834793533461,0.8245614035087719,0.8186455106705496
3+
Neural Network: No regularization,0.8779557589626239,0.875790866125634,0.8779557589626239,0.8729339270233065
4+
Neural Network: With Regularization,0.8527841342486652,0.849915756851124,0.8527841342486652,0.8447039064139434

modules/model.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from sklearn.metrics import confusion_matrix, precision_score, recall_score, f1_score, accuracy_score
77
import seaborn as sns
88
import matplotlib.pyplot as plt
9-
9+
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, confusion_matrix
1010

1111
'''
1212
This portion uses code from a previous project from this [notebook](https://github.com/DerikVo/DSI_project_4_plant_disease/blob/main/notebooks/01_Potato_PlantVillageEDA.ipynb).
@@ -184,3 +184,18 @@ def plot_confusion_matrix(confusion_matrix, class_paths, title):
184184
plt.savefig(f'../Created_images/{title} confusion matrix.png')
185185
#displays the image
186186
plt.show()
187+
188+
189+
190+
def model_metrics(true_classes, predicted_classes, title):
191+
'''
192+
Calculate accuracy, precision, recall, and F1 score.
193+
Also passes a title argument that titles the index for the model being used
194+
'''
195+
accuracy = accuracy_score(true_classes, predicted_classes)
196+
precision = precision_score(true_classes, predicted_classes, average='weighted')
197+
recall = recall_score(true_classes, predicted_classes, average='weighted')
198+
f1 = f1_score(true_classes, predicted_classes, average='weighted')
199+
data = {'Accuracy': [accuracy], 'Precision': [precision], 'Recall': [recall], 'F1 Score': [f1]}
200+
df = pd.DataFrame(data, index=[f'{title}'])
201+
return df

0 commit comments

Comments
 (0)