-
Notifications
You must be signed in to change notification settings - Fork 0
/
ml.py
37 lines (28 loc) · 828 Bytes
/
ml.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
import numpy as np
from sklearn import linear_model, datasets
import csv
import pickle
with open("x.csv", 'rb') as x_file:
reader = csv.reader(x_file, delimiter=' ')
X_train = []
for row in reader:
temp = row[0].split(',')
temp[5] = float(temp[5])
for i in range(len(temp)):
temp[i] = int(temp[i])
X_train.append(temp)
with open("y.csv", 'rb') as y_file:
reader = csv.reader(y_file, delimiter=' ')
Y_train_pre = []
for row in reader:
Y_train_pre.append(int(row[0]))
Y_train = []
Y_train.append(Y_train_pre)
Y_train = np.array(Y_train).reshape((-1,1))
logreg = linear_model.LogisticRegression(C=1e5)
logreg.fit(X_train, Y_train.ravel())
with open('logmodel.pkl', 'wb') as fid:
pickle.dump(logreg, fid, 2)
X = ([[20, 20000, 20000, 3, 1000, 500, 0, 0]])
result = logreg.predict(X)
print result