-
Notifications
You must be signed in to change notification settings - Fork 0
/
l_re_test.py
68 lines (42 loc) · 1.56 KB
/
l_re_test.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
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 9 17:52:35 2018
@author: noch
"""
import pandas as pd
from data_prepared import read_data, prepare_data_div
from regression import logistic_regression, test_with_id, predict
i = 2 # for the 1st dataset
f= open("/Users/noch/Documents/workspace/data_challenge/result/Y/Yte_lg_"+str(i)+".csv","a+")
#i = 1 # for the 2nd dataset
#f = open("/home/jibril/Desktop/data_challenge/result/Yte_lg_"+str(i)+".csv","a+")
isTr = 1
print("\n testing on Xtr" +str(i)+ ", Ytr" +str(i))
Xtr = read_data("Xtr"+str(i), isTr)
Ytr = read_data("Ytr"+str(i), isTr)
Ytr['Bound'][Ytr['Bound'] == 0] = -1
isTr = 0
Xte = read_data("Xte"+str(i), isTr)
Xte['Id'] = pd.DataFrame({'Id':range(i*1000, (i+1) * 1000)})
nm_char = 6
print("preparing data..")
Xtr_p = prepare_data_div(Xtr, nm_char)
Xtr_p['Bound'] = Ytr['Bound']
Xte_p = prepare_data_div(pd.DataFrame(Xte['DNA']), nm_char)
#Xte_p['Id'] = Xte['Id']
#Xtr_p = Xtr_p.sample(frac=1)
X_tr = pd.DataFrame.as_matrix(Xtr_p.iloc[:,:-1])
Y_tr = pd.DataFrame.as_matrix(Xtr_p['Bound']).astype(float).tolist()
print("training logistic regression..")
w = logistic_regression(X_tr, Y_tr, num_steps = 50, learning_rate = 5e-5, add_intercept=True)
print("predicting the test set..")
result_tmp = predict(Xte_p, w) #filter the value
result = test_with_id(result_tmp, Xte['Id'])
result['Bound'][result['Bound'] == -1] = 0
s = ""
for index, row in result.iterrows():
s = s + str(int(row['Id'])) + "," + str(int(row['Bound'])) + "\n"
f.write(s)
print("finish!")
f.close()