n_trees = 200 ploty = [-6, 6, 100] plotx = [-6, 6, 100] X, Y = make_spiral(n_arms=n_classes, noise=.4) ############################################################################## parameters = {'kernel': ['rbf'], 'C': [1, 10, 100, 1000, 10000, 100000], 'gamma': [10 ** x for x in range(-5, 3)], 'probability':[True]} svr = svm.SVC() clf = grid_search.GridSearchCV(svr, parameters) clf.fit(X, Y.ravel()) svmp = probaproxy(clf.predict_proba) plt.figure() point_prob_plot(svmp, X, Y, plotx, ploty) plt.title('RBF kernel SVM $(\gamma=%d, C=%f)$' % (clf.best_params_['gamma'], clf.best_params_['C'])) plt.savefig('spiral_svm.png') plt.show() ############################################################################## parameters = {'C': [1, 10, 100, 1000, 10000], 'probability': [True]} svr = svm.SVC(kernel='linear', max_iter=20000) clf = grid_search.GridSearchCV(svr, parameters) clf.fit(X, Y.ravel()) svmp = probaproxy(clf.predict_proba)
h = SimpleNode(sx, 2, 4) h2 = SimpleNode(h, 4, 2) out = SimpleNode(h2, 2, 1, nlin=pynnet.nlins.sigmoid) cost = errors.mse(out, sy) theano.config.blas.ldflags = '' eval = theano.function([sx], out.output) test = theano.function([sx, sy], cost.output) train = theano.function([sx, sy], cost.output, updates=get_updates(cost.params, cost.output, 0.01)) print("Error at start:", test(X, Y)) for i in range(200000): train(X, Y) print("Error after 200000:", test(X, Y)) def pfunc(x): return 1. - eval(x) clp = probaproxy(pfunc) plt.figure() point_prob_plot(clp, X, Y, plotx, ploty) plt.title('ANN (2 hidden layers, 4, 2)') plt.savefig('spiral_ann.png') plt.show()
plotx = [-6, 6, 100] X, Y = make_spiral(n_arms=n_classes, noise=.4) ############################################################################## parameters = { 'kernel': ['rbf'], 'C': [1, 10, 100, 1000, 10000, 100000], 'gamma': [10**x for x in range(-5, 3)], 'probability': [True] } svr = svm.SVC() clf = grid_search.GridSearchCV(svr, parameters) clf.fit(X, Y.ravel()) svmp = probaproxy(clf.predict_proba) plt.figure() point_prob_plot(svmp, X, Y, plotx, ploty) plt.title('RBF kernel SVM $(\gamma=%d, C=%f)$' % (clf.best_params_['gamma'], clf.best_params_['C'])) plt.savefig('spiral_svm.png') plt.show() ############################################################################## parameters = {'C': [1, 10, 100, 1000, 10000], 'probability': [True]} svr = svm.SVC(kernel='linear', max_iter=20000) clf = grid_search.GridSearchCV(svr, parameters) clf.fit(X, Y.ravel()) svmp = probaproxy(clf.predict_proba)
#%% Build ANN. sx = theano.tensor.matrix('x') sy = theano.tensor.matrix('y') h = SimpleNode(sx, 2, 4) h2 = SimpleNode(h, 4, 2) out = SimpleNode(h2, 2, 1, nlin=pynnet.nlins.sigmoid) cost = errors.mse(out, sy) theano.config.blas.ldflags='' eval = theano.function([sx], out.output) test = theano.function([sx, sy], cost.output) train = theano.function([sx, sy], cost.output, updates=get_updates(cost.params, cost.output, 0.01)) print("Error at start:", test(X, Y)) for i in range(200000): train(X, Y) print("Error after 200000:", test(X, Y)) def pfunc(x): return 1. - eval(x) clp = probaproxy(pfunc) plt.figure() point_prob_plot(clp, X, Y, plotx, ploty) plt.title('ANN (2 hidden layers, 4, 2)') plt.savefig('spiral_ann.png') plt.show()