Skip to content

Commit

Permalink
Accuracy over iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
tedgravlin committed Dec 3, 2023
1 parent 4e1f6ff commit c60315a
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from sklearn.metrics import classification_report
from sklearn.preprocessing import StandardScaler
from scipy.sparse import hstack
import matplotlib.pyplot as plot
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(1)

# FUNCTION: Train the model and store it locally
def create_model():
Expand Down Expand Up @@ -49,12 +51,37 @@ def create_model():
batch_size=128,
hidden_layer_sizes=(256),
learning_rate='adaptive',
max_iter=20,
verbose=True,
)

# Fit the model
model.fit(features_train, y_train)
# The number of epochs to run
N_EPOCHS = 10
N_CLASSES = np.unique(y_train)

scores_train = []
scores_test = []

# EPOCH
epoch = 0
while epoch < N_EPOCHS:
print('Epoch: ', epoch)
model.partial_fit(features_train, y_train, classes=N_CLASSES)

# SCORE TRAIN
scores_train.append(model.score(features_train, y_train))

# SCORE TEST
scores_test.append(model.score(features_test, y_test))

epoch += 1

# Plot accuracy over iterations
plt.plot(scores_train, color='green', alpha=0.8, label='Train')
plt.plot(scores_test, color='magenta', alpha=0.8, label='Test')
plt.title("Accuracy over epochs", fontsize=14)
plt.xlabel('Epochs')
plt.legend(loc='upper left')
plt.show()

# Predicting the test set results
predictions = model.predict(features_test)
Expand All @@ -70,9 +97,6 @@ def create_model():
# Print the model accuracy
print("Accuracy: ", model.score(features_test,y_test) * 100)

# TODO: Accuracy over each iteration
# TODO: Validation over each iteration

# Store the model in storage
joblib.dump(model,"./models/model.pkl")
# Store the vectorizer in storage
Expand Down

0 comments on commit c60315a

Please sign in to comment.