-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
41 lines (32 loc) · 1.12 KB
/
models.py
File metadata and controls
41 lines (32 loc) · 1.12 KB
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
37
38
39
40
41
import numpy as np
from sklearn.svm import SVR
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.model_selection import GridSearchCV
from utils import Utils
class Models:
def __init__(self):
self.reg = {"SVR": SVR(), "GRADIENT": GradientBoostingRegressor()}
self.params = {
"SVR": {
"kernel": ["linear", "poly", "rbf"],
"gamma": ["auto", "scale"],
"C": [1, 4, 10],
},
"GRADIENT": {
"loss": ["squared_error", "absolute_error"],
"learning_rate": [0.01, 0.05, 0.1],
},
}
def grid_training(self, X, y):
best_score = 999
best_model = None
for name, reg in self.reg.items():
grid_reg = GridSearchCV(reg, self.params[name], cv=3).fit(
X, y.values.ravel()
)
score = np.abs(grid_reg.best_score_)
if score < best_score:
best_score = score
best_model = grid_reg.best_estimator_
utils = Utils()
utils.model_export(best_model, best_score)