SVC file:///home/oslab-09/Downloads/SVC.
html
In [5]: import pandas as pd
df=pd.read_csv('Iris.csv')
df.shape
df.columns
Out[5]: Index(['Id', 'SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm',
'Species'],
dtype='object')
In [8]: df.drop('Id',axis=1,inplace=True)
df.columns
Out[8]: Index(['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm',
'Species'],
dtype='object')
In [12]: from sklearn.preprocessing import LabelEncoder
le=LabelEncoder()
df['Species'] = le.fit_transform(df['Species'])
In [13]: X=df.drop('Species',axis=1)
Y=df['Species']
X.head
Out[13]: <bound method NDFrame.head 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/SVC.html
In [14]: Y.head
Out[14]: <bound method NDFrame.head 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 sklearn.svm import SVC
model=SVC(kernel='linear')
model.fit(X_train,y_train)
Out[16]: ▾ SVC
SVC(kernel='linear')
In [18]: print(df.dtypes)
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/SVC.html
new_data = pd.DataFrame([[sepal_len, sepal_wid, petal_len, petal_wid]],
columns=X.columns)
prediction=model.predict(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