-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
36 lines (29 loc) · 881 Bytes
/
model.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
27
28
29
30
31
32
33
34
35
36
# coding=utf-8
from features import loadFeatures
from adaboost import Adaboost
from setting import MODEL_CACHE_FILE
from numpy import random
import pickle
def getModel():
featureMat = loadFeatures()
print("features loading over...")
random.shuffle(featureMat)
train_data = featureMat[:5000, :-1]
train_label = featureMat[:5000, -1].reshape(-1, 1)
clf = Adaboost(n_estimators=30, debug=True)
clf.fit(train_data, train_label)
return clf
def calAndSaveModel():
"""save trained model as a cache file
:return:
"""
model = getModel()
modelFile = open(MODEL_CACHE_FILE, "wb")
print(modelFile)
pickle.dump(model, modelFile, -1)
modelFile.close()
def loadModel():
modelFile = open(MODEL_CACHE_FILE, "rb")
model = pickle.load(modelFile)
modelFile.close()
return model