-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_model.py
More file actions
29 lines (23 loc) · 747 Bytes
/
train_model.py
File metadata and controls
29 lines (23 loc) · 747 Bytes
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
import json
from pickle import dump
import pandas as pd
from sklearn.datasets import make_classification
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
# fit model
X, y = make_classification(
n_samples = 100000,
n_informative = 10,
random_state = 5
)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=42)
model = RandomForestClassifier()
model.fit(X_train, y_train)
# save model
dump(model, open('prod_model.joblib', 'wb'))
# save test set
test_df = pd.DataFrame(X_test)
test_df['outcome'] = y_test
dump(test_df, open('test_df.joblib', 'wb'))
print('New model & new test data set created and saved to disk.')