-
Notifications
You must be signed in to change notification settings - Fork 4
/
train_completed.py
33 lines (26 loc) · 1002 Bytes
/
train_completed.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
import pickle
from boxkite.monitoring.service import ModelMonitoringService
from sklearn.datasets import load_diabetes
from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score
from sklearn.model_selection import train_test_split
def main():
bunch = load_diabetes()
X_train, X_test, Y_train, Y_test = train_test_split(bunch.data, bunch.target)
model = LinearRegression()
model.fit(X_train, Y_train)
Y_pred = model.predict(X_test)
print("Score: %.2f" % r2_score(Y_test, Y_pred))
with open("./model.pkl", "wb") as f:
pickle.dump(model, f)
features = zip(*[bunch.feature_names, X_train.T])
# features = [("age", [33, 23, 54, ...]), ("sex", [0, 1, 0]), ...]
inference = list(Y_pred)
# inference = [235.01351432, 211.79644624, 121.54947698, ...]
ModelMonitoringService.export_text(
features=features,
inference=inference,
path="./histogram.prom",
)
if __name__ == "__main__":
main()