Created
June 10, 2016 19:38
-
-
Save robenalt/b19404326dd129d2a5e97476885c4774 to your computer and use it in GitHub Desktop.
sklearn random forest template
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
%matplotlib inline | |
import pandas as pd | |
import numpy as np | |
from sklearn.ensemble import RandomForestClassifier | |
from sklearn.cross_validation import train_test_split | |
from sklearn.metrics import classification_report | |
from sklearn.metrics import confusion_matrix | |
from sklearn.metrics import accuracy_score | |
from sklearn.metrics import recall_score | |
from sklearn.metrics import precision_score | |
## set train and target here | |
X_train, X_test, y_train, y_test = train_test_split(train, target, test_size=0.33, random_state=83) | |
rf = RandomForestClassifier(n_estimators=100,n_jobs=3) | |
rf.fit(X_train, y_train) | |
imp = zip(col_names[1:],rf.feature_importances_) | |
sorted(imp, key=lambda x: -x[1]) | |
y_pred = rf.predict(X_test) | |
accuracy_score(y_test, y_pred) | |
test_pred_proba = rf.predict_proba(X_test) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment