forked from lazyprogrammer/machine_learning_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_trainer.py
26 lines (21 loc) · 830 Bytes
/
app_trainer.py
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
from __future__ import print_function, division
from builtins import range, input
# Note: you may need to update your version of future
# sudo pip install -U future
# https://deeplearningcourses.com/c/data-science-supervised-machine-learning-in-python
# https://www.udemy.com/data-science-supervised-machine-learning-in-python
import pickle
import numpy as np
from util import get_data
from sklearn.ensemble import RandomForestClassifier
if __name__ == '__main__':
X, Y = get_data()
Ntrain = len(Y) // 4
Xtrain, Ytrain = X[:Ntrain], Y[:Ntrain]
model = RandomForestClassifier()
model.fit(Xtrain, Ytrain)
# just in case you're curious
Xtest, Ytest = X[Ntrain:], Y[Ntrain:]
print("test accuracy:", model.score(Xtest, Ytest))
with open('mymodel.pkl', 'wb') as f:
pickle.dump(model, f)