forked from VertaAI/modeldb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleSampleWithModelDB.py
54 lines (40 loc) · 1.25 KB
/
SimpleSampleWithModelDB.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pandas as pd
from sklearn import linear_model
from sklearn.metrics import accuracy_score
from modeldb.sklearn_native.ModelDbSyncer import *
from modeldb.sklearn_native import SyncableMetrics
DATA_PATH = '../../../../data/'
'''
Source: http://archive.ics.uci.edu/ml/datasets/default+of+credit+card+clients
'''
# modeldb start
name = "simple sample"
author = "srinidhi"
description = "simple LR for credit default prediction"
syncer_obj = Syncer(
NewOrExistingProject(name, author, description),
DefaultExperiment(),
NewExperimentRun("credit test"))
# modeldb end
# modeldb start
df = pd.read_csv_sync(DATA_PATH + 'credit-default.csv', skiprows=[0])
# modeldb end
target = df['default payment next month']
df = df[["LIMIT_BAL", "SEX", "EDUCATION", "MARRIAGE", "AGE"]]
x_train, x_test, y_train, y_test = cross_validation.train_test_split_sync(
df, target, test_size=0.3)
lr = linear_model.LogisticRegression(C=2)
# modeldb start
lr.fit_sync(x_train, y_train)
# modeldb end
# modeldb start
y_pred = lr.predict_sync(x_test)
# modeldb end
# modeldb start
score = SyncableMetrics.compute_metrics(
lr, accuracy_score, y_test, y_pred, x_train, "features",
'default payment next month')
# modeldb end
# modeldb start
syncer_obj.sync()
# modeldb end