-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinallcode.py
93 lines (77 loc) · 2.51 KB
/
finallcode.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#import the libraries
import sys
import numpy as np # linear algebra
import pandas as pd
<<<<<<< HEAD
import sklearn
from sklearn.model_selection import train_test_split
=======
import sklearn
from sklearn import linear_model
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.tree import DecisionTreeRegressor
>>>>>>> f79c30415f267038297d68510fd26a61cd34cb09
from sklearn import preprocessing
from sklearn.svm import SVC
from sklearn import tree
from sklearn.tree import DecisionTreeClassifier
print("check")
df = pd.read_csv('./public/hack2.csv')
print("morning")
hour =int(sys.argv[1])
date = int(sys.argv[2])
month = int(sys.argv[3])
year = int(sys.argv[4])
longitude = float(sys.argv[5])
latitude = float(sys.argv[6])
print(hour)
x = [[hour,date,month,year,longitude,latitude]]
a = []
#rape
copy = df.copy()
replace_map = {'CRIME' : {'Attempt to Murder' : 0, 'Harassment' : 0 , 'Rape' : 1, 'Theft' : 0}}
copy.replace(replace_map, inplace = True)
target = copy['CRIME']
decision_tree = DecisionTreeClassifier(max_depth= 6, class_weight = {0:.4, 1 : 0.6})
decision_tree.fit(df.drop(columns = 'CRIME') , target)
p = decision_tree.predict_proba(x)[:,1]
a.append(p[0])
#murder
copy = df.copy()
print("hello")
replace_map = {'CRIME' : {'Attempt to Murder' : 1, 'Harassment' : 0 , 'Rape' : 0, 'Theft' : 0}}
copy.replace(replace_map, inplace = True)
target = copy['CRIME']
from sklearn.linear_model import LogisticRegression
lr = LogisticRegression(random_state = 1, class_weight = {0: 0.07, 1: 0.93})
lr.fit(df.drop(columns = 'CRIME') , target)
p = lr.predict_proba(x)[:,1]
a.append(p[0])
#harassment
copy = df.copy()
replace_map = {'CRIME' : {'Attempt to Murder' : 0, 'Harassment' : 1 , 'Rape' : 0, 'Theft' : 0}}
copy.replace(replace_map, inplace = True)
target = copy['CRIME']
clf = SVC(gamma= 2,class_weight = {0: 0.05, 1: 0.95}, probability = True)
clf.fit(df.drop(columns = 'CRIME') , target)
p = clf.predict_proba(x)[:,1]
a.append(p[0])
#theft
copy = df.copy()
replace_map = {'CRIME' : {'Attempt to Murder' : 0, 'Harassment' : 0 , 'Rape' : 1, 'Theft' : 0}}
copy.replace(replace_map, inplace = True)
target = copy['CRIME']
clr = SVC(gamma= 2,class_weight = {0: 0.05, 1: 0.95}, probability = True)
clr.fit(df.drop(columns = 'CRIME') , target)
p = clr.predict_proba(x)[:,1]
a.append(p[0])
print(a)
import math
np.array(a)
class_weights = [0.4, 0.2, 0.3, 0.1]
np.array(class_weights)
p = np.multiply(a,class_weights)
ans = 1/(1+ math.exp(-1*(sum(p))))
print(ans)
#0.6317589799363152