-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_analytics_project.py
89 lines (79 loc) · 2.41 KB
/
data_analytics_project.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
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 14 10:16:38 2017
@author: evanc
"""
import pandas as pd
df = pd.read_csv("C:\\Users\\evanc\\Python\\Data Analytics Project\\data.csv")
def process_categorical():
# currently categories are represented by integers and stored as such.
# We need to change them to categorical so we can get the dummies.
global df
categories = ["Gender",
"Ethnicitiy",
"Citizen_of_US",
"Education2",
"Language",
"TestedForHIV",
"EverSmokedWeed",
"EverHardDrug",
"EverUseCocaine",
"EverInjectDrugNeedle",
"BeenToRehab"
,"CoveredByHealthCare"
,'CoveredByPrivate'
,'CoveredByPublicHC'
,'EverHadHepB'
,'EverHadHepC'
,'GenealHealthCondition'
,'Fem12mosUnablePregnant'
,'FemEverHadReproductiveInfect'
,'FemEverBeenPregn'
,'FemCurrentlyPregnant'
,'BothEverHadSex'
,'MalesEverHadVaginalSex'
,'MalesEverOralSexWithFemale'
,'MalesEverHadAnalSexFemales'
,'MalesEverHadAnalSexMales'
,'FemalesEverHadSexWithMan'
,'FemalesEverHadOralSex'
,'FemalesEverHadAnalSex'
,'FemalesEverHadSexWithFemale'
,'FemalesEverHadHPV'
,'BothEverHadHerpes'
,'BothEverHadGenitalWarts'
,'BothEverHadGono'
,'BothEverHadChl'
,'SexualOrientation']
for i in range(len(categories)):
category = categories[i]
df[category] = df[category].astype('category')
def train_and_target():
global target
global df
global train
df.set_index("SEQN", inplace = True)
target = df.ChlamydiaResults
df.drop("ChlamydiaResults", axis = 1, inplace = True)
train = df
train = pd.get_dummies(train)
def run_svm():
weights = {0:67.42, 1:892.54}
from sklearn import svm
from sklearn.model_selection import cross_val_score
sv = svm.SVC(C=3, class_weight = weights)
clf = sv.fit(train,target)
scores = cross_val_score(clf,train,target,cv=10)
print(scores)
def run_decision_tree():
from sklearn import tree
from sklearn.model_selection import cross_val_score
tree = tree.DecisionTreeClassifier(class_weight ='balanced')
clf = tree.fit(train,target)
scores = cross_val_score(clf,train,target,cv =10)
print(scores)
if __name__ == "__main__":
process_categorical()
train_and_target()
run_svm()
run_decision_tree()