<jupyter_start><jupyter_text>Random Forests<jupyter_code>import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/gumdropsteve/datasets/master/iris.csv')

df = df.drop('species', axis=1)

df.sample(5)<jupyter_output><empty_output><jupyter_text>Train Test Split<jupyter_code>from sklearn.model_selection import train_test_split

X = df.drop('target', axis=1)
y = df.target

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)<jupyter_output><empty_output><jupyter_text>Random Forest Classifier
https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html | [Bootstrapping](https://en.wikipedia.org/wiki/Bootstrapping_(statistics))<jupyter_code>from sklearn.ensemble import RandomForestClassifier

RandomForestClassifier()
rfc = RandomForestClassifier()

rfc.fit(X_train, y_train)
preds = rfc.predict(X_test)

preds[-5: ]
from sklearn.metrics import accuracy_score

accuracy_score(y_test, preds)
from sklearn.metrics import plot_confusion_matrix

rfc = RandomForestClassifier()

rfc.fit(X_train, y_train)

plot_confusion_matrix(estimator=rfc, X=X_test, y_true=y_test, 
                      display_labels=['setosa', 'versicolor', 'virginica'])
from sklearn.metrics import plot_confusion_matrix

rfc = RandomForestClassifier()

rfc.fit(X_train, y_train)

plot_confusion_matrix(estimator=rfc, X=X_test, y_true=y_test, 
                      display_labels=['setosa', 'versicolor', 'virginica'],
                      cmap='Blues')<jupyter_output><empty_output><jupyter_text>Random Forest Regressor
https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestRegressor.html<jupyter_code>from sklearn.ensemble import RandomForestRegressor

RandomForestRegressor()
rfr = RandomForestRegressor()

rfr.fit(X_train, y_train)
preds = rfr.predict(X_test)

preds[-5: ]<jupyter_output><empty_output><jupyter_text>To evaluate, look at the possible input args... `criterion{“mse”, “mae”}, default=”mse”`<jupyter_code>from sklearn.metrics import mean_squared_error

mean_squared_error(y_test, preds)
from sklearn.metrics import mean_absolute_error

mean_absolute_error(y_test, preds)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup