from sklearn import tree def sklearn_tree(features, labels): clf = tree.DecisionTreeClassifier() clf.fit(features, labels) return clf if __name__ == '__main__': from load_data import split_train_data,evaliate tfs, tls, vfs, vls = split_train_data() i = 0 mean_acc = 0 for (tfeatures,tlabels,vfeatures,vlabels) in zip(tfs, tls, vfs, vls): print('tree : ', i, ' start') clf = sklearn_tree(tfeatures, tlabels) predict = clf.predict(vfeatures) accuracy = evaliate(predict, vlabels) mean_acc += accuracy i += 1 print('tree ', i, ' :', accuracy) print('mean acc : ', mean_acc / 10)
for (features, labels, vfeatures, vlabels) in zip(tfs, tls, vfs, vls): print('net : ', i, ' train') features = nd.array(features) labels = nd.array(np.array(labels)) vfeatures = nd.array(np.array(vfeatures)) vlabels = nd.array(np.array(vlabels)) net = train(features, labels, './params/nn.params') net = inter_output(net, 12) features = net(features) clf = sklearn_tree(features.asnumpy(), labels.asnumpy()) vfeatures = net(vfeatures) predict = clf.predict(vfeatures.asnumpy()) print(net) accuracy = evaliate(predict, vlabels.asnumpy()) print('accracy :', accuracy) # predict = net(vfeatures) # predict = predict_label(predict) # i = i+1 # acc = accuracy(predict, vlabels) # mean_acc += acc # print('acc : ',acc) break print('mean acc : ', mean_acc / 10) # train_features = nd.array(train_features,ctx=mx.cpu()) # train_labels = nd.array(train_labels,ctx=mx.cpu()) # net = train(train_features, train_labels) # test_features = nd.array(test_features) # print('start predict') # predict = net(test_features)