Skip to content

Commit 16df167

Browse files
authored
Create intro_1.py
1 parent 056e7f5 commit 16df167

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

Tutorials/intro_1.py

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import pandas as pd
2+
3+
import matplotlib.pyplot as plt
4+
5+
from sklearn.datasets import load_iris
6+
7+
from sklearn.model_selection import train_test_split
8+
9+
from sklearn.ensemble import RandomForestClassifier
10+
11+
from sklearn.metrics import accuracy_score
12+
13+
14+
15+
# Load the Iris dataset
16+
17+
iris = load_iris()
18+
19+
data = pd.DataFrame(data=iris.data, columns=iris.feature_names)
20+
21+
target = pd.Series(data=iris.target)
22+
23+
24+
25+
# Data Exploration
26+
27+
print("Dataset Description:")
28+
29+
print(data.describe())
30+
31+
32+
33+
# Data Visualization
34+
35+
data.plot(kind='box', subplots=True, layout=(2, 2), sharex=False, sharey=False)
36+
37+
plt.show()
38+
39+
40+
41+
# Train-test split
42+
43+
X_train, X_test, y_train, y_test = train_test_split(data, target, test_size=0.2, random_state=42)
44+
45+
46+
47+
# Train a Random Forest Classifier
48+
49+
rf_classifier = RandomForestClassifier(n_estimators=100, random_state=42)
50+
51+
rf_classifier.fit(X_train, y_train)
52+
53+
54+
55+
# Make predictions
56+
57+
y_pred = rf_classifier.predict(X_test)
58+
59+
60+
61+
# Calculate accuracy
62+
63+
accuracy = accuracy_score(y_test, y_pred)
64+
65+
print("Accuracy:", accuracy)

0 commit comments

Comments
 (0)