GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Added Random Forest Classifier (#1738) · jusing-es/Python@10fc90c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • machine_learning
    • random_forest_classifier.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎machine_learning/random_forest_classifier.py‎

Copy file name to clipboard
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Random Forest Classifier Example
2+
3+
from sklearn.datasets import load_iris
4+
from sklearn.model_selection import train_test_split
5+
from sklearn.ensemble import RandomForestClassifier
6+
from sklearn.metrics import plot_confusion_matrix
7+
import matplotlib.pyplot as plt
8+
9+
10+
def main():
11+
12+
"""
13+
Random Tree Classifier Example using sklearn function.
14+
Iris type dataset is used to demonstrate algorithm.
15+
"""
16+
17+
# Load Iris house price dataset
18+
iris = load_iris()
19+
20+
# Split dataset into train and test data
21+
X = iris["data"] # features
22+
Y = iris["target"]
23+
x_train, x_test, y_train, y_test = train_test_split(
24+
X, Y, test_size=0.3, random_state=1
25+
)
26+
27+
# Random Forest Classifier
28+
rand_for = RandomForestClassifier(random_state=42, n_estimators=100)
29+
rand_for.fit(x_train, y_train)
30+
31+
# Display Confusion Matrix of Classifier
32+
plot_confusion_matrix(
33+
rand_for,
34+
x_test,
35+
y_test,
36+
display_labels=iris["target_names"],
37+
cmap="Blues",
38+
normalize="true",
39+
)
40+
plt.title("Normalized Confusion Matrix - IRIS Dataset")
41+
plt.show()
42+
43+
44+
if __name__ == "__main__":
45+
main()

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.