Skip to content

Instantly share code, notes, and snippets.

@yashprakash13
Created December 26, 2021 16:37
Show Gist options
  • Save yashprakash13/ba73e8596be049b1ba072e59cffeb901 to your computer and use it in GitHub Desktop.
Save yashprakash13/ba73e8596be049b1ba072e59cffeb901 to your computer and use it in GitHub Desktop.
# MODEL Pipeline
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import confusion_matrix, accuracy_score
import matplotlib.pyplot as plt
# random forest classifier
rf_classifier = RandomForestClassifier(n_estimators = 11, criterion='entropy', random_state=0)
rf_model_pipeline = Pipeline(steps=[
('preprocessing', columns_transformer),
('rf_model', rf_classifier),
])
rf_model_pipeline.fit(X_train, y_train)
# predict on test set
y_pred = rf_model_pipeline.predict(X_test)
# calculate accuracy
ac = accuracy_score(y_test, y_pred)
print(f"Accuracy= {ac}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment