-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
148 lines (111 loc) · 3.5 KB
/
test.py
File metadata and controls
148 lines (111 loc) · 3.5 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder
from sklearn import model_selection
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_score
from sklearn.metrics import classification_report, confusion_matrix
training_set = pd.read_csv('TRAINING.csv')
training_set.fillna(0, inplace = True)
#id = training_set['id']
Area = training_set['Area(total)']
Troom = training_set['Troom']
Nbedrooms = training_set['Nbedrooms']
Nbwashrooms = training_set['Nbwashrooms']
Twashrooms = training_set['Twashrooms']
RoofArea = training_set['Roof(Area)']
Lawn = training_set['Lawn(Area)']
Nfloors = training_set['Nfloors']
Api = training_set['API']
Anb = training_set['ANB']
Grade = training_set['Grade']
prices = training_set['Price']
new_training_set = {}
# roof = training_set['roof']
# r = []
# for i in roof:
# if i == 0:
# r.append("NO")
# else:
# i = i.upper()
# r.append(i)
new_prices = []
for i in prices:
new_prices.append(int(i[0:4]))
#new_training_set['id'] = id
new_training_set['Area'] = Area
new_training_set['Troom'] = Troom
new_training_set['Nbwashrooms'] = Nbwashrooms
new_training_set['Nbedrooms'] = Nbedrooms
new_training_set['Twashrooms'] = Twashrooms
new_training_set['Roof'] = RoofArea
new_training_set['Lawn'] = Lawn
new_training_set['Nfloors'] = Nfloors
new_training_set['Api'] = Api
new_training_set['Anb'] = Anb
new_training_set['Price'] = new_prices
new_training_set['Grade'] = Grade
new_training_set = pd.DataFrame(new_training_set)
test_set = pd.read_csv('TEST.csv')
test_set.fillna(0, inplace = True)
#idt = test_set['id']
Areat = test_set['Area(total)']
Troomt = test_set['Troom']
Nbedroomst = test_set['Nbedrooms']
Nbwashroomst = test_set['Nbwashrooms']
Twashroomst = test_set['Twashrooms']
Rooft = test_set['Roof(Area)']
Lawnt = test_set['Lawn(Area)']
Nfloorst = test_set['Nfloors']
Apit = test_set['API']
Anbt = test_set['ANB']
#rooft = test_set['roof']
new_test_set = {}
# rt = []
# for i in rooft:
# if i == 0:
# rt.append("NO")
# else:
# i = i.upper()
# rt.append(i)
pricest = test_set['Price']
new_prices_test = []
for i in pricest:
new_prices_test.append(int(i[0:4]))
new_test_set['Area'] = Areat
new_test_set['Troom'] = Troomt
new_test_set['Nbedrooms'] = Nbedroomst
new_test_set['Nbwashrooms'] = Nbwashroomst
new_test_set['Twashrooms'] = Twashroomst
#new_test_set['roof'] = rt
new_test_set['Roof'] = Rooft
new_test_set['Lawn'] = Lawnt
new_test_set['Nfloors'] = Nfloorst
new_test_set['Api'] = Apit
new_test_set['Anb'] = Anbt
new_test_set['Price'] = new_prices_test
new_test_set = pd.DataFrame(new_test_set)
X = new_training_set.drop('Grade',axis=1)
y = new_training_set['Grade']
#X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, shuffle=False)
rfc = RandomForestClassifier(n_estimators = 150, criterion="entropy")
rfc.fit(X,y)
rfc_predict = rfc.predict(new_test_set)
a={}
id=[]
for i in range (1,3300):
id.append(i)
a['id']=pd.Series(id)
a['Grade']=pd.Series(rfc_predict)
a=pd.DataFrame(a)
a.to_csv("Output.csv",index=False)
#rfc_cv_score = cross_val_score(rfc, X, y, cv=10, scoring='roc_auc')
print("=== Classification Report ===")
#print(classification_report(y_test, rfc_predict))
print('\n')
print("=== All AUC Scores ===")
#print(rfc_cv_score)
print('\n')
print("=== Mean AUC Score ===")
print("Mean AUC Score - Random Forest: ", rfc_cv_score.mean())