0% found this document useful (0 votes)
15 views3 pages

Iris Flower Classification with SVC

The document describes a Python script that uses the SVC (Support Vector Classification) model to classify iris flower species based on measurements. It includes data preprocessing steps such as dropping the 'Id' column and encoding the 'Species' labels, followed by splitting the dataset into training and testing sets. Finally, the model is trained and used to predict the species of a flower based on user-provided measurements.

Uploaded by

shraddha.clg0905
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Iris Flower Classification with SVC

The document describes a Python script that uses the SVC (Support Vector Classification) model to classify iris flower species based on measurements. It includes data preprocessing steps such as dropping the 'Id' column and encoding the 'Species' labels, followed by splitting the dataset into training and testing sets. Finally, the model is trained and used to predict the species of a flower based on user-provided measurements.

Uploaded by

shraddha.clg0905
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SVC file:///home/oslab-09/Downloads/SVC.

html

In [5]: import pandas as pd


df=pd.read_csv('[Link]')
[Link]
[Link]

Out[5]: Index(['Id', 'SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm',


'Species'],
dtype='object')

In [8]: [Link]('Id',axis=1,inplace=True)
[Link]

Out[8]: Index(['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm',


'Species'],
dtype='object')

In [12]: from [Link] import LabelEncoder


le=LabelEncoder()
df['Species'] = le.fit_transform(df['Species'])

In [13]: X=[Link]('Species',axis=1)
Y=df['Species']
[Link]

Out[13]: <bound method [Link] of SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm


0 5.1 3.5 1.4 0.2
1 4.9 3.0 1.4 0.2
2 4.7 3.2 1.3 0.2
3 4.6 3.1 1.5 0.2
4 5.0 3.6 1.4 0.2
.. ... ... ... ...
145 6.7 3.0 5.2 2.3
146 6.3 2.5 5.0 1.9
147 6.5 3.0 5.2 2.0
148 6.2 3.4 5.4 2.3
149 5.9 3.0 5.1 1.8

[150 rows x 4 columns]>

1 of 3 01/09/25, 15:18
SVC file:///home/oslab-09/Downloads/[Link]

In [14]: [Link]

Out[14]: <bound method [Link] of 0 0


1 0
2 0
3 0
4 0
..
145 2
146 2
147 2
148 2
149 2
Name: Species, Length: 150, dtype: int64>

In [15]: from sklearn.model_selection import train_test_split


X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.2, random_state=42)

In [16]: from [Link] import SVC


model=SVC(kernel='linear')
[Link](X_train,y_train)

Out[16]: ▾ SVC

SVC(kernel='linear')

In [18]: print([Link])

SepalLengthCm float64
SepalWidthCm float64
PetalLengthCm float64
PetalWidthCm float64
Species int64
dtype: object

In [20]: print("Enter flower Mearurment in cm")


sepal_len=float(input("Sepal Length"))
sepal_wid=float(input("Sepal width"))
petal_len=float(input("Petal Length"))
petal_wid=float(input("Petal Width"))

2 of 3 01/09/25, 15:18
SVC file:///home/oslab-09/Downloads/[Link]

new_data = [Link]([[sepal_len, sepal_wid, petal_len, petal_wid]],


columns=[Link])
prediction=[Link](new_data)
species_name=le.inverse_transform(prediction)
print(species_name)

Enter flower Mearurment in cm


Sepal Length5.1
Sepal width3.5
Petal Length1.4
Petal Width0.2
['Iris-setosa']

In [ ]:

3 of 3 01/09/25, 15:18

You might also like