Iris Flower Classification Using ML - by Modassir - Medium
Iris Flower Classification Using ML - by Modassir - Medium
Get unlimited access to the best of Medium for less than $1/week. Become a member
Iris Flower
Overview
https://medium.com/@mn.zamindar/iris-flower-classification-using-ml-29277b18b233#:~:text=Machine Learning Models%3A,Achieved an accuracy of 100%25. 2/21
4/29/24, 1:39 PM Iris Flower Classification Using ML | by Modassir | Medium
Data Exploration
Before diving into machine learning models, let’s explore the dataset. We
load the data into a pandas data frame, perform basic statistical analysis, and
visualize the distribution of features. The Seaborn library helps us create
informative visualizations, such as count plots and pair plots, which offer
insights into the relationships between different features. The Iris dataset
includes features such as sepal length, sepal width, petal length, and petal
width. The data is split into training and testing sets for model evaluation.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn import datasets
from sklearn.svm import SVC
from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score
df = pd.read_csv("/content/IRIS.csv")
X = df[['sepal_length','sepal_width','petal_length','petal_width']]
y = df['species']
# Standardize the features by removing the mean and scaling to unit variance
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
df.isnull().sum()
Feature Visualization
A pair plot is generated to visualize the relationships between features for
each iris species.
These models are trained and evaluated on a testing set to measure their
accuracy. The scikit-learn library simplifies the implementation of these
models, making it accessible even for those new to machine learning.
# Decision Tree
dt_classifier = DecisionTreeClassifier(random_state=42)
dt_classifier.fit(X_train, y_train)
y_pred_dt = dt_classifier.predict(X_test)
accuracy_dt = accuracy_score(y_test, y_pred_dt)
# Print accuracies
print(f"SVM Accuracy: {accuracy_svm * 100:.2f}%")
print(f"k-NN Accuracy: {accuracy_knn * 100:.2f}%")
print(f"Decision Tree Accuracy: {accuracy_dt * 100:.2f}%")
Correlation Matrix
A heatmap displays the correlation matrix of the feature set.
Hyperparameter Tuning
Conclusion
In conclusion, the Iris Flower Classification project provides a hands-on
exploration of machine learning techniques. Through data exploration,
https://medium.com/@mn.zamindar/iris-flower-classification-using-ml-29277b18b233#:~:text=Machine Learning Models%3A,Achieved an accuracy of 100%25. 12/21
4/29/24, 1:39 PM Iris Flower Classification Using ML | by Modassir | Medium
This project serves as an excellent starting point for those new to machine
learning, offering practical insights into data preprocessing, model training,
and performance evaluation. Feel free to explore the code, experiment with
different models, and contribute to the project’s growth.
How to Use
By engaging with this project, you’ll not only enhance your understanding of
machine learning but also contribute to a valuable resource for others
exploring this fascinating field.
Happy coding!
Modassir
If you find the article helpful, please like and comment on this.
Data Science
8 Followers
12 min read · Jan 22, 2024 4 min read · Jul 26, 2023
1 53
“In the realm of data, where car enthusiasts Data Science is an interdisciplinary field that
and algorithms collide, a fascinating journey… combines scientific methods, algorithms,…
5 min read · Jan 22, 2024 6 min read · Jul 30, 2023
100
18 min read · Feb 23, 2024 4 min read · Apr 10, 2024
123
Lists
RG Data Notes
2 3
433 3
Help Status About Careers Blog Privacy Terms Text to speech Teams