Last active
April 15, 2017 21:14
-
-
Save MechCoder/473b9d84efa7a47a8c481e30aa766fd1 to your computer and use it in GitHub Desktop.
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
from sklearn.datasets import load_boston | |
from sklearn.model_selection import train_test_split | |
from sklearn.tree import DecisionTreeRegressor | |
from sklearn.ensemble import RandomForestRegressor | |
boston = load_boston() | |
X, y = boston.data, boston.target | |
X_train, X_test, y_train, y_test = train_test_split( | |
X, y, train_size=0.6, test_size=0.4, random_state=0) | |
X_train = np.array(X_train, dtype=np.float32) | |
X_test = np.array(X_test, dtype=np.float32) | |
dt = DecisionTreeRegressor(random_state=0) | |
rf = RandomForestRegressor( | |
random_state=0, bootstrap=False, max_depth=None) | |
rf.fit(X_train, y_train) | |
for est in rf.estimators_: | |
print(est.predict(X_test[:3])) | |
print("From tree") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment