-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.py
More file actions
43 lines (36 loc) · 990 Bytes
/
code.py
File metadata and controls
43 lines (36 loc) · 990 Bytes
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
import pandas as pd
import math
coeffs = pd.read_table('inputs/logreg_coefficients.txt',quoting = 3,header =None)
data = pd.read_table('inputs/test_movies.txt',quoting = 3,header =None)
#print data
print len(data)
#print coeffs
minimum_calc=[]
results=[]
for d in data[0]:
crew = d.split()
crew=list(set(crew))
hyp=0
for c in crew:
if any(coeffs[0]==c):
hyp=float(float(1*coeffs[coeffs[0]==c][1])+float(hyp))
#print hyp
#raw_input()
else:
hyp=hyp+1*0
results.append([d,float(math.exp(hyp))/float(1+float(math.exp(hyp)))])
for r in results:
current = r[0].split()
current=list(set(current))
temp=[]
for c in current:
if any(coeffs[0]==c):
temp.append([c,coeffs[coeffs[0]==c][1]]
for r in results:
if r[1]>0.5:
r[1]=1
else:
r[1]=0
results = pd.DataFrame(results,index=None, columns=None)
print results
results.to_csv('predicted_values.csv')