Created
May 12, 2017 20:31
-
-
Save iandewancker/a13357e98231e51864612b805422d08f to your computer and use it in GitHub Desktop.
RF vs MLP sandbox for learning the "if" function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import sklearn.ensemble | |
from sklearn.neural_network import MLPClassifier | |
X = np.random.uniform(low=0, high=5000000,size=(10000,2)) | |
y = np.array(X[:,0] > X[:,1],dtype=int) | |
X_test = np.random.uniform(low=0,high=5000000,size=(10000,2)) | |
y_test = np.array(X_test[:,0] > X_test[:,1],dtype=int) | |
clf_rf = sklearn.ensemble.RandomForestClassifier(n_estimators=50,criterion='entropy', max_depth=2) | |
clf_rf.fit(X,y) | |
clf_mlp = MLPClassifier(solver='adam', activation='relu',alpha=1e-5, hidden_layer_sizes=(1), random_state=1, max_iter=1000) | |
clf_mlp.fit(X,y) | |
print "RF SCORE :",clf_rf.score(X_test,y_test) | |
print "MLP SCORE :",clf_mlp.score(X_test,y_test) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment