Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor store_model() method to improve safety and efficiency #245

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions modules/flowmldetection/flowmldetection.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,20 @@ def detect(self):
self.print(X_flow)
self.print(traceback.print_exc(),0,1)

def store_model(self):
"""
Store the trained model on disk
"""
self.print(f'Storing the trained model and scaler on disk.', 0, 2)
f = open('./modules/flowmldetection/model.bin', 'wb')
data = pickle.dumps(self.clf)
f.write(data)
f.close()
g = open('./modules/flowmldetection/scaler.bin', 'wb')
data = pickle.dumps(self.scaler)
g.write(data)
g.close()
def store_model(self):
"""
Store the trained model on disk if it has been updated
"""
if self.model_updated:
self.print(f'Storing the updated trained model and scaler on disk.', 0, 2)
with open('./modules/flowmldetection/model.bin', 'wb') as f:
pickle.dump(self.clf, f)
with open('./modules/flowmldetection/scaler.bin', 'wb') as g:
pickle.dump(self.scaler, g)
self.model_updated = False
else:
self.print(f'Trained model has not been updated. Not storing on disk.', 0, 2)


def read_model(self):
"""
Expand Down