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 sklearn.datasets as datasets | |
import pandas as pd | |
from sklearn.model_selection import train_test_split | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.pipeline import Pipeline | |
from sklearn.ensemble import RandomForestRegressor | |
from sklearn.decomposition import PCA |
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
df = pd.read_csv('df.csv', sep = ',') | |
df.head() |
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
X = df[['GDP','UnemploymentRate']] | |
y = df['Revenue'] | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0) |
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
regr = RandomForestRegressor(random_state = 100,bootstrap = True, max_depth=2,max_features=2,min_samples_leaf=3,min_samples_split=5,n_estimators=3) | |
pipe = Pipeline([ | |
('scaler', StandardScaler()), | |
('reduce_dim', PCA()), | |
('regressor', regr) | |
]) | |
pipe.fit(X_train,y_train) | |
ypipe=pipe.predict(X_test) |
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
conda install pydotplus | |
conda install graphviz |
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.externals.six import StringIO | |
from IPython.display import Image | |
from sklearn.tree import export_graphviz | |
import pydotplus | |
import os | |
os.environ['PATH'] = os.environ['PATH']+';'+os.environ['CONDA_PREFIX']+r"\Library\bin\graphviz" | |
dot_data = StringIO() | |
export_graphviz(pipe.named_steps['regressor'].estimators_[0], out_file=dot_data) | |
graph = pydotplus.graph_from_dot_data(dot_data.getvalue()) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
OlderNewer