In [2]:
import pandas as pd
import numpy as np
import pickle
In [10]:
df_file = pd.read_csv('../data/df_dropSub_less20_dropNaResult.csv',delimiter=",", skip_blank_lines = True,
error_bad_lines=False)
df_file = df_file.drop('Unnamed: 0',axis=1)
df_file = df_file.fillna(0)
df_file = df_file.replace(['A', 'B+', 'B', 'C+', 'C' , 'D+' , 'D' , 'F' , 'W' , 'S' , 'S#' , 'U' , 'U#'],
[8, 7, 7, 6 , 6, 5, 5, 4, 3, 2, 2, 1, 1])
In [11]:
df_file
Out[11]:
Unnamed: 0.1
3COURSEID
4RESULT
0STUDENTID
1ACADYEAR
2SEMESTER
AT316
AT326
BA291
CJ315
...
TA395
TH161
TU100
TU110
TU120
TU122
TU130
TU154
PROVINCEID
SCHOOLGPA
0
0
CS101
6
316644
2552
1
0
0
0
0
...
0
0
0
0
0
0
0
0
12
3.32
1
1
CS102
6
316644
2552
1
0
0
0
0
...
0
0
0
0
0
0
0
0
12
3.32
2
2
EL171
5
316644
2552
1
0
0
0
0
...
0
0
0
0
0
0
0
0
12
3.32
3
3
SC135
4
316644
2552
1
0
0
0
0
...
0
0
0
0
0
0
0
0
12
3.32
4
4
SC185
6
316644
2552
1
0
0
0
0
...
0
0
0
0
0
0
0
0
12
3.32
5
5
TH161
6
316644
2552
1
0
0
0
0
...
0
0
0
0
0
0
0
0
12
3.32
6
6
TU154
5
316644
2552
1
0
0
0
0
...
0
0
0
0
0
0
0
0
12
3.32
7
7
CS111
5
316644
2552
2
0
0
0
0
...
0
6
0
0
0
0
0
5
12
3.32
8
8
EL172
4
316644
2552
2
0
0
0
0
...
0
6
0
0
0
0
0
5
12
3.32
9
9
MA211
4
316644
2552
2
0
0
0
0
...
0
6
0
0
0
0
0
5
12
3.32
10
10
PY228
7
316644
2552
2
0
0
0
0
...
0
6
0
0
0
0
0
5
12
3.32
11
11
TU110
6
316644
2552
2
0
0
0
0
...
0
6
0
0
0
0
0
5
12
3.32
12
12
TU120
5
316644
2552
2
0
0
0
0
...
0
6
0
0
0
0
0
5
12
3.32
13
13
TU130
7
316644
2552
2
0
0
0
0
...
0
6
0
0
0
0
0
5
12
3.32
14
14
TU122
7
316644
2552
3
0
0
0
0
...
0
6
0
6
5
0
7
5
12
3.32
15
15
AT326
8
316644
2553
1
0
0
0
0
...
0
6
0
6
5
7
7
5
12
3.32
16
16
CS213
6
316644
2553
1
0
0
0
0
...
0
6
0
6
5
7
7
5
12
3.32
17
17
CS214
7
316644
2553
1
0
0
0
0
...
0
6
0
6
5
7
7
5
12
3.32
18
18
CS222
7
316644
2553
1
0
0
0
0
...
0
6
0
6
5
7
7
5
12
3.32
19
19
CS223
7
316644
2553
1
0
0
0
0
...
0
6
0
6
5
7
7
5
12
3.32
20
20
CS284
7
316644
2553
1
0
0
0
0
...
0
6
0
6
5
7
7
5
12
3.32
21
21
MA211
5
316644
2553
1
0
0
0
0
...
0
6
0
6
5
7
7
5
12
3.32
22
22
SW111
5
316644
2553
1
0
0
0
0
...
0
6
0
6
5
7
7
5
12
3.32
23
23
AT316
7
316644
2553
2
0
8
0
0
...
0
6
0
6
5
7
7
5
12
3.32
24
24
CS251
6
316644
2553
2
0
8
0
0
...
0
6
0
6
5
7
7
5
12
3.32
25
25
CS261
7
316644
2553
2
0
8
0
0
...
0
6
0
6
5
7
7
5
12
3.32
26
26
CS281
7
316644
2553
2
0
8
0
0
...
0
6
0
6
5
7
7
5
12
3.32
27
27
MA332
6
316644
2553
2
0
8
0
0
...
0
6
0
6
5
7
7
5
12
3.32
28
28
SC135
6
316644
2553
2
0
8
0
0
...
0
6
0
6
5
7
7
5
12
3.32
29
29
ST216
6
316644
2553
2
0
8
0
0
...
0
6
0
6
5
7
7
5
12
3.32
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
27965
31292
EL070
2
447240
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
48
3.75
27966
31293
MA211
4
447240
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
48
3.75
27967
31294
ST216
4
447240
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
48
3.75
27968
31295
TH161
6
447240
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
48
3.75
27969
31296
TU154
4
447240
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
48
3.75
27970
31297
CS101
5
447241
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
13
2.60
27971
31298
CS102
5
447241
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
13
2.60
27972
31299
CS105
5
447241
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
13
2.60
27973
31300
EL070
2
447241
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
13
2.60
27974
31301
MA211
3
447241
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
13
2.60
27975
31302
ST216
3
447241
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
13
2.60
27976
31303
TH161
5
447241
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
13
2.60
27977
31304
TU154
3
447241
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
13
2.60
27978
31313
CS101
5
447242
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
34
2.93
27979
31314
CS102
5
447242
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
34
2.93
27980
31315
CS105
5
447242
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
34
2.93
27981
31316
EL171
3
447242
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
34
2.93
27982
31317
MA211
3
447242
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
34
2.93
27983
31318
ST216
3
447242
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
34
2.93
27984
31319
TH161
6
447242
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
34
2.93
27985
31320
TU154
5
447242
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
34
2.93
27986
31325
SC185
3
447242
2557
2
0
0
0
0
...
0
6
0
0
0
0
0
5
34
2.93
27987
31329
CS101
4
447243
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
84
2.08
27988
31330
CS102
4
447243
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
84
2.08
27989
31331
CS105
4
447243
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
84
2.08
27990
31332
EL070
1
447243
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
84
2.08
27991
31333
MA211
4
447243
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
84
2.08
27992
31334
ST216
4
447243
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
84
2.08
27993
31335
TH161
4
447243
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
84
2.08
27994
31336
TU154
4
447243
2557
1
0
0
0
0
...
0
0
0
0
0
0
0
0
84
2.08
27995 rows × 118 columns
In [12]:
count_courseId = df_file["3COURSEID"].value_counts()
more20 = count_courseId
headers=list(df_file.columns.values)
subjects = []
countSub = 0
In [13]:
count = 0
subjects.sort()
precision_rf={}
df_precision = more20.drop('CS231').copy()
list_allsub = df_file.columns[4:]
allSubject_df = pd.DataFrame(columns=[subjects],index=[list_allsub])
top10_df = pd.DataFrame(columns=[subjects])
In [14]:
headers=list(df_file.columns.values)
subjects = []
countSub = 0
#Create dictionary of list subjects
for sub in df_file[headers[1]]:
if sub not in subjects:
subjects.append(sub)
countSub = countSub+1
In [15]:
subjects.sort()
In [16]:
subjects.remove('CS231')
In [17]:
len(subjects)
Out[17]:
110
In [18]:
subject = 'CS213'
print subject
df_sub = df_file[df_file['3COURSEID'] == subject]
df_sub = df_sub.iloc[np.random.permutation(len(df_sub))]
A = df_sub.as_matrix()
CS213
In [19]:
df_sub
Out[19]:
Unnamed: 0.1
3COURSEID
4RESULT
0STUDENTID
1ACADYEAR
2SEMESTER
AT316
AT326
BA291
CJ315
...
TA395
TH161
TU100
TU110
TU120
TU122
TU130
TU154
PROVINCEID
SCHOOLGPA
11501
11663
CS213
6
354654
2554
1
0
0
0
0
...
0
6
0
0
7
0
0
4
1
3.29
3869
3937
CS213
5
336716
2553
1
0
0
0
0
...
0
6
0
0
7
0
0
6
1
3.12
536
547
CS213
5
329174
2553
1
0
0
0
0
...
0
7
0
5
5
0
0
6
1
3.69
11762
11926
CS213
6
354661
2554
1
0
0
0
0
...
0
3
0
0
8
0
0
6
19
3.19
21470
22445
CS213
6
398014
2556
1
0
0
0
0
...
0
6
0
0
7
0
0
6
30
3.08
22552
23710
CS213
4
402947
2556
1
0
0
0
0
...
0
6
0
0
8
0
0
6
1
3.06
1560
1589
CS213
6
329196
2553
1
0
0
0
0
...
0
5
0
5
5
0
0
6
22
3.68
24717
26403
CS213
6
423617
2557
1
0
0
0
0
...
0
8
8
6
6
0
6
7
12
3.69
22157
23254
CS213
7
402934
2556
1
0
0
0
0
...
0
7
0
0
7
0
0
6
1
2.85
16941
17305
CS213
5
380308
2555
1
0
0
0
0
...
0
8
0
0
7
0
0
3
44
3.61
16
16
CS213
6
316644
2553
1
0
0
0
0
...
0
6
0
6
5
7
7
5
12
3.32
11473
11635
CS213
4
354653
2554
1
0
0
0
0
...
0
7
0
0
5
0
0
6
34
3.42
20705
21541
CS213
5
397400
2556
1
0
0
0
0
...
0
7
0
5
6
0
0
5
1
3.70
5247
5329
CS213
7
336747
2554
2
0
0
0
0
...
0
8
0
5
7
0
7
5
1
2.97
10980
11137
CS213
5
352728
2554
1
0
0
0
0
...
0
6
0
0
7
0
0
4
13
2.85
23261
24505
CS213
6
403244
2556
1
0
0
0
0
...
0
6
0
0
7
0
0
6
40
3.42
4738
4818
CS213
6
336735
2553
2
0
0
0
0
...
0
6
0
5
6
0
0
6
1
3.18
22229
23340
CS213
4
402936
2556
1
0
0
0
0
...
0
6
0
0
7
0
0
6
1
2.42
19220
19755
CS213
7
390269
2556
1
0
0
0
0
...
0
7
0
6
7
0
0
7
70
3.07
7697
7805
CS213
6
351665
2557
1
7
8
0
0
...
8
7
0
7
7
7
6
5
1
3.72
23883
25312
CS213
4
423579
2557
1
0
0
0
0
...
0
8
7
6
6
0
6
6
73
3.58
8971
9108
CS213
6
351694
2554
1
0
0
0
0
...
0
7
0
0
7
0
0
7
13
3.03
21889
22941
CS213
6
402925
2556
1
0
0
0
0
...
0
5
0
0
7
0
0
5
1
1.92
16416
16752
CS213
8
379816
2556
2
0
7
0
0
...
0
7
0
5
5
3
6
5
1
3.44
9093
9230
CS213
6
351697
2555
2
0
8
0
0
...
0
6
0
6
7
8
6
6
60
2.91
15365
15645
CS213
6
379786
2555
1
0
0
0
0
...
0
7
0
5
6
0
0
5
80
3.37
1734
1767
CS213
7
329200
2554
2
6
7
0
0
...
0
7
0
6
7
6
6
6
1
3.67
22853
24057
CS213
3
402957
2557
1
0
0
0
0
...
0
6
0
4
7
0
5
4
1
2.10
18457
18917
CS213
6
383161
2555
1
0
0
0
0
...
0
7
0
5
7
0
0
6
1
3.30
7042
7140
CS213
7
344245
2554
1
0
0
0
0
...
0
5
0
0
7
0
0
6
1
3.04
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
17863
18286
CS213
5
383144
2555
1
0
0
0
0
...
0
6
0
0
6
0
0
5
82
3.31
24373
25953
CS213
5
423602
2557
1
0
0
0
0
...
0
7
7
5
6
0
6
6
12
3.54
4580
4660
CS213
6
336731
2555
2
0
0
0
0
...
0
7
0
5
8
0
7
6
66
3.14
21983
23051
CS213
5
402929
2556
1
0
0
0
0
...
0
6
0
0
7
0
0
5
11
2.90
3943
4011
CS213
5
336718
2553
2
0
0
0
0
...
0
6
0
0
6
0
0
6
41
3.28
14650
14886
CS213
3
379764
2555
1
0
0
0
0
...
0
7
0
6
6
0
0
6
46
3.56
3935
4003
CS213
3
336718
2553
1
0
0
0
0
...
0
6
0
0
6
0
0
6
41
3.28
20161
20884
CS213
6
397378
2556
1
0
0
0
0
...
0
7
7
5
0
0
0
6
70
3.43
26084
28105
CS213
5
427180
2557
1
0
0
0
0
...
0
7
7
0
7
0
0
3
76
3.16
1288
1314
CS213
7
329190
2554
2
7
8
0
0
...
0
6
0
5
7
6
6
6
72
3.59
1656
1688
CS213
6
329198
2553
1
0
0
0
0
...
0
6
0
5
5
0
0
6
11
3.61
11189
11349
CS213
7
352732
2554
1
0
0
0
0
...
0
6
0
0
7
0
0
5
1
3.12
19557
20164
CS213
6
393365
2556
1
0
0
0
0
...
0
7
7
5
0
0
0
7
27
3.90
23086
24315
CS213
6
402967
2556
1
0
0
0
7
...
0
7
0
0
7
0
0
6
1
3.23
5174
5256
CS213
6
336746
2553
1
0
0
0
0
...
0
6
0
0
6
0
0
7
1
3.01
23623
24968
CS213
5
423568
2557
1
0
0
0
0
...
0
7
8
7
6
0
6
7
1
3.38
19281
19836
CS213
6
390940
2556
1
8
0
0
0
...
0
6
7
5
0
0
0
5
54
2.96
2072
2109
CS213
8
329208
2553
1
0
0
0
0
...
0
7
0
7
5
0
7
8
1
3.77
23241
24485
CS213
4
403243
2557
1
0
0
0
0
...
0
5
0
5
7
0
6
3
1
2.44
5223
5305
CS213
5
336747
2553
1
0
0
0
0
...
0
8
0
0
7
0
0
5
1
2.97
18878
19364
CS213
6
383172
2555
1
0
0
0
0
...
0
6
0
6
7
0
0
4
12
2.28
5593
5681
CS213
5
336755
2553
2
0
0
0
0
...
0
6
0
0
6
0
0
4
15
3.47
2944
2997
CS213
6
329232
2553
1
0
0
0
0
...
0
6
0
7
0
0
7
6
1
3.72
26601
28734
CS213
5
427211
2557
1
0
0
0
0
...
0
7
7
0
7
0
0
6
1
2.87
18167
18613
CS213
5
383153
2555
1
0
0
0
0
...
0
5
0
5
7
0
0
4
1
3.50
15810
16115
CS213
8
379799
2555
1
0
0
0
0
...
0
7
7
6
0
0
0
7
1
2.68
2510
2556
CS213
6
329218
2554
2
7
7
0
0
...
0
6
0
5
5
6
6
6
30
3.78
4051
4125
CS213
6
336720
2553
1
0
0
0
0
...
0
5
0
0
8
0
0
5
1
3.26
23308
24559
CS213
4
403246
2556
1
0
0
0
0
...
0
6
0
0
7
0
0
3
73
2.75
21017
21914
CS213
5
397413
2556
1
0
0
0
0
...
0
7
7
5
0
0
0
6
90
3.13
765 rows × 118 columns
In [26]:
def classify( X ):
with open('tree_drop/treeCS213.pic', 'rb') as pickleFile:
clf2 = pickle.load(pickleFile)
clf2.predict(X)
Grade=['A', 'B', 'C' , 'D' , 'F' , 'W' , 'S' , 'U' ,'na']
grade_predicted = Grade[::-1][clf2.predict(X)]
print "prediction: ",grade_predicted
return
In [29]:
A[:,6:116]
Out[29]:
array([[0L, 0L, 0L, ..., 0L, 0L, 4L],
[0L, 0L, 0L, ..., 0L, 0L, 6L],
[0L, 0L, 0L, ..., 0L, 0L, 6L],
...,
[0L, 0L, 0L, ..., 0L, 0L, 5L],
[0L, 0L, 0L, ..., 0L, 0L, 3L],
[0L, 0L, 0L, ..., 0L, 0L, 6L]], dtype=object)
In [37]:
X = A[0,6:116]
In [39]:
X
Out[39]:
array([0L, 0L, 0L, 0L, 0L, 0L, 0L, 6L, 5L, 0L, 5L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 5L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 7L, 0L, 0L, 0L, 0L,
0L, 0L, 6L, 0L, 6L, 0L, 5L, 0L, 0L, 7L, 7L, 0L, 0L, 0L, 0L, 8L, 0L,
0L, 6L, 0L, 0L, 7L, 0L, 0L, 4L], dtype=object)
In [40]:
X.shape
Out[40]:
(110L,)
In [41]:
classify( X );
prediction: C
In [42]:
X = A[1:2,6:116]
In [43]:
X.shape
Out[43]:
(1L, 110L)
In [44]:
classify( X );
prediction: D
In [47]:
def classify( X ):
for subject in subjects:
f = "tree_drop/tree%s.pic"%subject
with open(f, 'rb') as pickleFile:
clf2 = pickle.load(pickleFile)
clf2.predict(X)
Grade=['A', 'B', 'C' , 'D' , 'F' , 'W' , 'S' , 'U' ,'na']
grade_predicted = Grade[::-1][clf2.predict(X)]
print "prediction of %s: "%subject,grade_predicted
return
In [48]:
classify( X );
prediction of AT316: B
prediction of AT326: B
prediction of BA291: W
prediction of CJ315: B
prediction of CJ316: B
prediction of CJ317: B
prediction of CJ321: A
prediction of CS101: C
prediction of CS102: C
prediction of CS105: D
prediction of CS111: D
prediction of CS115: W
prediction of CS211: D
prediction of CS213: D
prediction of CS214: B
prediction of CS215: C
prediction of CS222: C
prediction of CS223: D
prediction of CS251: C
prediction of CS261: C
prediction of CS281: W
prediction of CS284: D
prediction of CS285: C
prediction of CS286: B
prediction of CS288: D
prediction of CS289: D
prediction of CS295: F
prediction of CS296: W
prediction of CS297: C
prediction of CS300: S
prediction of CS301: B
prediction of CS302: D
prediction of CS311: D
prediction of CS314: F
prediction of CS326: B
prediction of CS341: C
prediction of CS342: C
prediction of CS348: B
prediction of CS356: A
prediction of CS365: C
prediction of CS366: W
prediction of CS367: C
prediction of CS374: D
prediction of CS377: C
prediction of CS385: C
prediction of CS386: C
prediction of CS387: C
prediction of CS388: C
prediction of CS395: F
prediction of CS396: C
prediction of CS397: B
prediction of CS398: C
prediction of CS399: B
prediction of CS401: B
prediction of CS402: C
prediction of CS407: B
prediction of CS408: B
prediction of CS409: B
prediction of CS426: B
prediction of CS427: C
prediction of CS429: A
prediction of CS446: C
prediction of CS449: B
prediction of CS456: W
prediction of CS457: B
prediction of CS459: B
prediction of CS467: B
prediction of CS486: C
prediction of CS487: D
prediction of CS488: B
prediction of CS489: C
prediction of EL070: S
prediction of EL171: D
prediction of EL172: D
prediction of EL295: C
prediction of EL395: C
prediction of ES356: B
prediction of HO201: B
prediction of HR201: B
prediction of LA209: B
prediction of MA211: B
prediction of MA212: W
prediction of MA216: W
prediction of MA332: D
prediction of MW313: A
prediction of MW314: B
prediction of NS132: A
prediction of PY228: C
prediction of SC123: W
prediction of SC135: F
prediction of SC173: B
prediction of SC185: C
prediction of SO201: C
prediction of ST216: D
prediction of SW111: B
prediction of SW212: C
prediction of SW213: B
prediction of SW221: B
prediction of SW335: B
prediction of SW365: A
prediction of SW475: B
prediction of SW478: B
prediction of TA395: A
prediction of TH161: B
prediction of TU100: B
prediction of TU110: D
prediction of TU120: D
prediction of TU122: D
prediction of TU130: C
prediction of TU154: D
In [49]:
X
Out[49]:
array([[0L, 0L, 0L, 0L, 0L, 0L, 0L, 6L, 6L, 0L, 5L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 2L, 5L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 0L, 0L, 0L, 7L,
0L, 0L, 6L, 0L, 7L, 0L, 6L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 6L, 0L, 0L, 7L, 0L, 0L, 6L]], dtype=object)
In [50]:
X[-1]
Out[50]:
array([0L, 0L, 0L, 0L, 0L, 0L, 0L, 6L, 6L, 0L, 5L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 2L, 5L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 0L, 0L, 0L, 7L,
0L, 0L, 6L, 0L, 7L, 0L, 6L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 6L, 0L, 0L, 7L, 0L, 0L, 6L], dtype=object)
In [51]:
len(X[-1])
Out[51]:
110
In [53]:
X[-1][109]
Out[53]:
6L
In [55]:
X[-1][109] == 6
Out[55]:
True
In [56]:
subjects[109]
Out[56]:
'TU154'
In [57]:
def classify( X ):
for i in range(0,111):
if X[-1][i] == 0:
subject = subjects[i]
f = "tree_drop/tree%s.pic"%subject
with open(f, 'rb') as pickleFile:
clf2 = pickle.load(pickleFile)
clf2.predict(X)
Grade=['A', 'B', 'C' , 'D' , 'F' , 'W' , 'S' , 'U' ,'na']
grade_predicted = Grade[::-1][clf2.predict(X)]
print "prediction of %s: "%subject,grade_predicted
elif X[-1][i] != 0:
subject = subjects[i]
print "grade %s have already: "%subject
return
In [58]:
classify( X );
prediction of AT316: B
prediction of AT326: B
prediction of BA291: W
prediction of CJ315: B
prediction of CJ316: B
prediction of CJ317: B
prediction of CJ321: A
grade CS101 have already:
grade CS102 have already:
prediction of CS105: D
grade CS111 have already:
prediction of CS115: W
prediction of CS211: D
prediction of CS213: D
prediction of CS214: B
prediction of CS215: C
prediction of CS222: C
prediction of CS223: D
prediction of CS251: C
prediction of CS261: C
prediction of CS281: W
prediction of CS284: D
prediction of CS285: C
prediction of CS286: B
prediction of CS288: D
prediction of CS289: D
prediction of CS295: F
prediction of CS296: W
prediction of CS297: C
prediction of CS300: S
prediction of CS301: B
prediction of CS302: D
prediction of CS311: D
prediction of CS314: F
prediction of CS326: B
prediction of CS341: C
prediction of CS342: C
prediction of CS348: B
prediction of CS356: A
prediction of CS365: C
prediction of CS366: W
prediction of CS367: C
prediction of CS374: D
prediction of CS377: C
prediction of CS385: C
prediction of CS386: C
prediction of CS387: C
prediction of CS388: C
prediction of CS395: F
prediction of CS396: C
prediction of CS397: B
prediction of CS398: C
prediction of CS399: B
prediction of CS401: B
prediction of CS402: C
prediction of CS407: B
prediction of CS408: B
prediction of CS409: B
prediction of CS426: B
prediction of CS427: C
prediction of CS429: A
prediction of CS446: C
prediction of CS449: B
prediction of CS456: W
prediction of CS457: B
prediction of CS459: B
prediction of CS467: B
prediction of CS486: C
prediction of CS487: D
prediction of CS488: B
prediction of CS489: C
grade EL070 have already:
grade EL171 have already:
grade EL172 have already:
prediction of EL295: C
prediction of EL395: C
prediction of ES356: B
prediction of HO201: B
prediction of HR201: B
prediction of LA209: B
grade MA211 have already:
prediction of MA212: W
prediction of MA216: W
prediction of MA332: D
grade MW313 have already:
prediction of MW314: B
prediction of NS132: A
grade PY228 have already:
prediction of SC123: W
grade SC135 have already:
prediction of SC173: B
grade SC185 have already:
prediction of SO201: C
prediction of ST216: D
prediction of SW111: B
prediction of SW212: C
prediction of SW213: B
prediction of SW221: B
prediction of SW335: B
prediction of SW365: A
prediction of SW475: B
prediction of SW478: B
prediction of TA395: A
grade TH161 have already:
prediction of TU100: B
prediction of TU110: D
grade TU120 have already:
prediction of TU122: D
prediction of TU130: C
grade TU154 have already:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-58-712e81004f92> in <module>()
----> 1 classify( X );
<ipython-input-57-26a52f3a5ad9> in classify(X)
1 def classify( X ):
2 for i in range(0,111):
----> 3 if X[-1][i] == 0:
4 subject = subjects[i]
5 f = "tree_drop/tree%s.pic"%subject
IndexError: index 110 is out of bounds for axis 0 with size 110
In [63]:
def classify( X ):
for i in range(0,110):
if X[-1][i] == 0:
subject = subjects[i]
f = "tree_drop/tree%s.pic"%subject
with open(f, 'rb') as pickleFile:
clf2 = pickle.load(pickleFile)
clf2.predict(X)
Grade=['A', 'B', 'C' , 'D' , 'F' , 'W' , 'S' , 'U' ,'na']
grade_predicted = Grade[::-1][clf2.predict(X)]
print "prediction of %s: "%subject,grade_predicted
elif X[-1][i] != 0:
subject = subjects[i]
#print "grade %s have already: "%subject
Grade=['A', 'B', 'C' , 'D' , 'F' , 'W' , 'S' , 'U' ,'na']
truth=Grade[::-1][X[-1][i]]
print "grade %s has already is "%subject,truth
return
In [64]:
X
Out[64]:
array([[0L, 0L, 0L, 0L, 0L, 0L, 0L, 6L, 6L, 0L, 5L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 2L, 5L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 0L, 0L, 0L, 7L,
0L, 0L, 6L, 0L, 7L, 0L, 6L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 6L, 0L, 0L, 7L, 0L, 0L, 6L]], dtype=object)
In [65]:
X.shape
Out[65]:
(1L, 110L)
In [66]:
classify( X );
prediction of AT316: B
prediction of AT326: B
prediction of BA291: W
prediction of CJ315: B
prediction of CJ316: B
prediction of CJ317: B
prediction of CJ321: A
grade CS101 has already is C
grade CS102 has already is C
prediction of CS105: D
grade CS111 has already is D
prediction of CS115: W
prediction of CS211: D
prediction of CS213: D
prediction of CS214: B
prediction of CS215: C
prediction of CS222: C
prediction of CS223: D
prediction of CS251: C
prediction of CS261: C
prediction of CS281: W
prediction of CS284: D
prediction of CS285: C
prediction of CS286: B
prediction of CS288: D
prediction of CS289: D
prediction of CS295: F
prediction of CS296: W
prediction of CS297: C
prediction of CS300: S
prediction of CS301: B
prediction of CS302: D
prediction of CS311: D
prediction of CS314: F
prediction of CS326: B
prediction of CS341: C
prediction of CS342: C
prediction of CS348: B
prediction of CS356: A
prediction of CS365: C
prediction of CS366: W
prediction of CS367: C
prediction of CS374: D
prediction of CS377: C
prediction of CS385: C
prediction of CS386: C
prediction of CS387: C
prediction of CS388: C
prediction of CS395: F
prediction of CS396: C
prediction of CS397: B
prediction of CS398: C
prediction of CS399: B
prediction of CS401: B
prediction of CS402: C
prediction of CS407: B
prediction of CS408: B
prediction of CS409: B
prediction of CS426: B
prediction of CS427: C
prediction of CS429: A
prediction of CS446: C
prediction of CS449: B
prediction of CS456: W
prediction of CS457: B
prediction of CS459: B
prediction of CS467: B
prediction of CS486: C
prediction of CS487: D
prediction of CS488: B
prediction of CS489: C
grade EL070 has already is S
grade EL171 has already is D
grade EL172 has already is D
prediction of EL295: C
prediction of EL395: C
prediction of ES356: B
prediction of HO201: B
prediction of HR201: B
prediction of LA209: B
grade MA211 has already is F
prediction of MA212: W
prediction of MA216: W
prediction of MA332: D
grade MW313 has already is B
prediction of MW314: B
prediction of NS132: A
grade PY228 has already is C
prediction of SC123: W
grade SC135 has already is B
prediction of SC173: B
grade SC185 has already is C
prediction of SO201: C
prediction of ST216: D
prediction of SW111: B
prediction of SW212: C
prediction of SW213: B
prediction of SW221: B
prediction of SW335: B
prediction of SW365: A
prediction of SW475: B
prediction of SW478: B
prediction of TA395: A
grade TH161 has already is C
prediction of TU100: B
prediction of TU110: D
grade TU120 has already is B
prediction of TU122: D
prediction of TU130: C
grade TU154 has already is C
In [67]:
y = []
def classify( X ):
for i in range(0,110):
if X[-1][i] == 0:
subject = subjects[i]
f = "tree_drop/tree%s.pic"%subject
with open(f, 'rb') as pickleFile:
clf2 = pickle.load(pickleFile)
clf2.predict(X)
Grade=['A', 'B', 'C' , 'D' , 'F' , 'W' , 'S' , 'U' ,'na']
grade_predicted = Grade[::-1][clf2.predict(X)]
print "prediction of %s: "%subject,grade_predicted
y.append(grade_predicted)
elif X[-1][i] != 0:
subject = subjects[i]
Grade=['A', 'B', 'C' , 'D' , 'F' , 'W' , 'S' , 'U' ,'na']
grade_truth=Grade[::-1][X[-1][i]]
print "grade %s has already is "%subject,grade_truth
y.append(grade_truth)
print "list of all grade predicted is %s"%y
return
In [68]:
classify(X)
prediction of AT316: B
prediction of AT326: B
prediction of BA291: W
prediction of CJ315: B
prediction of CJ316: B
prediction of CJ317: B
prediction of CJ321: A
grade CS101 has already is C
grade CS102 has already is C
prediction of CS105: D
grade CS111 has already is D
prediction of CS115: W
prediction of CS211: D
prediction of CS213: D
prediction of CS214: B
prediction of CS215: C
prediction of CS222: C
prediction of CS223: D
prediction of CS251: C
prediction of CS261: C
prediction of CS281: W
prediction of CS284: D
prediction of CS285: C
prediction of CS286: B
prediction of CS288: D
prediction of CS289: D
prediction of CS295: F
prediction of CS296: W
prediction of CS297: C
prediction of CS300: S
prediction of CS301: B
prediction of CS302: D
prediction of CS311: D
prediction of CS314: F
prediction of CS326: B
prediction of CS341: C
prediction of CS342: C
prediction of CS348: B
prediction of CS356: A
prediction of CS365: C
prediction of CS366: W
prediction of CS367: C
prediction of CS374: D
prediction of CS377: C
prediction of CS385: C
prediction of CS386: C
prediction of CS387: C
prediction of CS388: C
prediction of CS395: F
prediction of CS396: C
prediction of CS397: B
prediction of CS398: C
prediction of CS399: B
prediction of CS401: B
prediction of CS402: C
prediction of CS407: B
prediction of CS408: B
prediction of CS409: B
prediction of CS426: B
prediction of CS427: C
prediction of CS429: A
prediction of CS446: C
prediction of CS449: B
prediction of CS456: W
prediction of CS457: B
prediction of CS459: B
prediction of CS467: B
prediction of CS486: C
prediction of CS487: D
prediction of CS488: B
prediction of CS489: C
grade EL070 has already is S
grade EL171 has already is D
grade EL172 has already is D
prediction of EL295: C
prediction of EL395: C
prediction of ES356: B
prediction of HO201: B
prediction of HR201: B
prediction of LA209: B
grade MA211 has already is F
prediction of MA212: W
prediction of MA216: W
prediction of MA332: D
grade MW313 has already is B
prediction of MW314: B
prediction of NS132: A
grade PY228 has already is C
prediction of SC123: W
grade SC135 has already is B
prediction of SC173: B
grade SC185 has already is C
prediction of SO201: C
prediction of ST216: D
prediction of SW111: B
prediction of SW212: C
prediction of SW213: B
prediction of SW221: B
prediction of SW335: B
prediction of SW365: A
prediction of SW475: B
prediction of SW478: B
prediction of TA395: A
grade TH161 has already is C
prediction of TU100: B
prediction of TU110: D
grade TU120 has already is B
prediction of TU122: D
prediction of TU130: C
grade TU154 has already is C
list of all grade predicted is ['B', 'B', 'W', 'B', 'B', 'B', 'A', 'C', 'C', 'D', 'D', 'W', 'D', 'D', 'B', 'C', 'C', 'D', 'C', 'C', 'W', 'D', 'C', 'B', 'D', 'D', 'F', 'W', 'C', 'S', 'B', 'D', 'D', 'F', 'B', 'C', 'C', 'B', 'A', 'C', 'W', 'C', 'D', 'C', 'C', 'C', 'C', 'C', 'F', 'C', 'B', 'C', 'B', 'B', 'C', 'B', 'B', 'B', 'B', 'C', 'A', 'C', 'B', 'W', 'B', 'B', 'B', 'C', 'D', 'B', 'C', 'S', 'D', 'D', 'C', 'C', 'B', 'B', 'B', 'B', 'F', 'W', 'W', 'D', 'B', 'B', 'A', 'C', 'W', 'B', 'B', 'C', 'C', 'D', 'B', 'C', 'B', 'B', 'B', 'A', 'B', 'B', 'A', 'C', 'B', 'D', 'B', 'D', 'C', 'C']
In [ ]:
Content source: wasit7/book_pae
Similar notebooks: