Skip to content

Commit

Permalink
Create intro_1.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Adesoji1 authored Aug 20, 2024
1 parent 056e7f5 commit 16df167
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions Tutorials/intro_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import pandas as pd

import matplotlib.pyplot as plt

from sklearn.datasets import load_iris

from sklearn.model_selection import train_test_split

from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import accuracy_score



# Load the Iris dataset

iris = load_iris()

data = pd.DataFrame(data=iris.data, columns=iris.feature_names)

target = pd.Series(data=iris.target)



# Data Exploration

print("Dataset Description:")

print(data.describe())



# Data Visualization

data.plot(kind='box', subplots=True, layout=(2, 2), sharex=False, sharey=False)

plt.show()



# Train-test split

X_train, X_test, y_train, y_test = train_test_split(data, target, test_size=0.2, random_state=42)



# Train a Random Forest Classifier

rf_classifier = RandomForestClassifier(n_estimators=100, random_state=42)

rf_classifier.fit(X_train, y_train)



# Make predictions

y_pred = rf_classifier.predict(X_test)



# Calculate accuracy

accuracy = accuracy_score(y_test, y_pred)

print("Accuracy:", accuracy)

0 comments on commit 16df167

Please sign in to comment.