Advertisement
gk231192

Module 9.2 Random Forest

Jul 3rd, 2025
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. # 5. Random Forest
  2. # What it does: Combines many decision trees. Each tree votes, and the most common vote wins.
  3. # Use Case: Credit scoring, fraud detection.
  4.  
  5. from sklearn.ensemble import RandomForestClassifier
  6.  
  7. rf = RandomForestClassifier(n_estimators=100, random_state=42)
  8. rf.fit(X_train, y_train)
  9. y_pred = rf.predict(X_test)
  10.  
  11. print("Random Forest Confusion Matrix:\n", confusion_matrix(y_test, y_pred))
  12. print("\nRandom Forest Classification Report:\n", classification_report(y_test, y_pred))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement