|
9 | 9 | import theano
|
10 | 10 | from sklearn.ensemble import RandomForestClassifier
|
11 | 11 | from sklearn.svm import SVC
|
| 12 | +from sklearn.preprocessing import MinMaxScaler |
12 | 13 | from data import load_data
|
13 | 14 | import random
|
14 | 15 |
|
@@ -46,12 +47,15 @@ def rf(traindata,trainlabel,testdata,testlabel):
|
46 | 47 | (trainlabel,testlabel) = (label[0:30000],label[30000:])
|
47 | 48 | #use origin_model to predict testdata
|
48 | 49 | origin_model = cPickle.load(open("model.pkl","rb"))
|
| 50 | + #print(origin_model.layers) |
49 | 51 | pred_testlabel = origin_model.predict_classes(testdata,batch_size=1, verbose=1)
|
50 | 52 | num = len(testlabel)
|
51 | 53 | accuracy = len([1 for i in range(num) if testlabel[i]==pred_testlabel[i]])/float(num)
|
52 | 54 | print(" Origin_model Accuracy:",accuracy)
|
53 | 55 | #define theano funtion to get output of FC layer
|
54 |
| - get_feature = theano.function([origin_model.layers[0].input],origin_model.layers[11].get_output(train=False),allow_input_downcast=False) |
| 56 | + get_feature = theano.function([origin_model.layers[0].input],origin_model.layers[9].output,allow_input_downcast=False) |
55 | 57 | feature = get_feature(data)
|
56 | 58 | #train svm using FC-layer feature
|
| 59 | + scaler = MinMaxScaler() |
| 60 | + feature = scaler.fit_transform(feature) |
57 | 61 | svc(feature[0:30000],label[0:30000],feature[30000:],label[30000:])
|
0 commit comments