-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
83 lines (75 loc) · 3.31 KB
/
models.py
File metadata and controls
83 lines (75 loc) · 3.31 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import logging
from lightgbm import LGBMClassifier, LGBMRegressor
from xgboost import XGBClassifier, XGBRegressor
from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
class Model:
def __init__(self):
self.logger = logging.getLogger(__name__)
def rfc(self, X_train, y_train, n_est, r_state=42):
"""this function just using Random forest classification model
for training and adjust some parameters of this model"""
try:
model = RandomForestClassifier(n_estimators=n_est,
random_state=r_state)
model.fit(X_train, y_train)
return model
except Exception as e:
self.logger.error(f"An error occurred: {e}")
return None
def xgbc(self, X_train, y_train, n_est, r_state=42):
"""this function just using Extreme Gradient Boosting classification
model for training and adjust some parameters of this model"""
try:
model = XGBClassifier(n_estimators=n_est,
random_state=r_state)
model.fit(X_train, y_train)
return model
except Exception as e:
self.logger.error(f"An error occurred: {e}")
return None
def lgbmc(self, X_train, y_train, n_est, r_state=42):
"""this function just using light gradient boosting machine
classification model for training and adjust some parameters
of this model"""
try:
model = LGBMClassifier(n_estimators=n_est,
random_state=r_state)
model.fit(self, X_train, y_train)
return model
except Exception as e:
self.logger.error(f"An error occurred: {e}")
return None
def rfr(self, X_train, y_train, n_est, r_state=42):
"""this function just using Random forest regression model
for training and adjust some parameters of this model"""
try:
model = RandomForestRegressor(n_estimators=n_est,
random_state=r_state)
model.fit(X_train, y_train)
return model
except Exception as e:
self.logger.error(f"An error occurred: {e}")
return None
def xgbr(self, X_train, y_train, n_est, r_state=42):
"""this function just using Extreme Gradient Boosting regression
model for training and adjust some parameters of this model"""
try:
model = XGBRegressor(n_estimators=n_est,
random_state=r_state)
model.fit(X_train, y_train)
return model
except Exception as e:
self.logger.error(f"An error occurred: {e}")
return None
def lgbmr(self, X_train, y_train, n_est, r_state=42):
"""this function just using light gradient boosting machine
regression model for training and adjust some parameters
of this model"""
try:
model = LGBMRegressor(n_estimators=n_est,
random_state=r_state)
model.fit(self, X_train, y_train)
return model
except Exception as e:
self.logger.error(f"An error occurred: {e}")
return None