"""
<p style="color:purple; font-weight:bold; text-align:center; font-size:50px;">Classification on linearly separable data by using linear Support Vector Machine</p>
"""
"""
<span style="color:red; font-weight:bold;">Problem : </span> In this notebook, I will build a model which classify the species of Iris. In this problem I will use Iris dataset. This data is linearly separable data. So I will build a model by using linear support vector machine.
"""
"""
I will import some requires libraries to read a dataset, and will read data and print it.
"""
import numpy as np
import pandas as pd
df = pd.read_csv('../input/iris-data/Iris.csv')
df
"""
<span style="color:red; font-weight:bold;">Data Preprocessing : </span> Now it's turn to preprocess the data. I will convert "Species" attribute of non-numeric data into the numeric data. For that I will use LabelEncoder from sklearn library of python.
"""
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
df.Species = le.fit_transform(df.Species)
df
df.describe()
"""
In the above result, we can see that there is 150 count for all attributes. This says that there is not a null value in any attribute. We know null values always creates a problem. So, we should fill all null values with its mean values or most frequently used value. In this case there is no null value. So, I can go ahead.
"""
"""
<span style="color:red; font-weight:bold;">Data Vidualization : </span> Now, I will use matplotlib library to vidualize the data.
"""
PetalLengthCm_0 = df[df['Species']==0]['PetalLengthCm']
PetalLengthCm_1 = df[df['Species']==1]['PetalLengthCm']
PetalLengthCm_2 = df[df['Species']==2]['PetalLengthCm']

PetalWidthCm_0 = df[df['Species']==0]['PetalWidthCm']
PetalWidthCm_1 = df[df['Species']==1]['PetalWidthCm']
PetalWidthCm_2 = df[df['Species']==2]['PetalWidthCm']
import matplotlib.pyplot as plt
plt.scatter(PetalLengthCm_0, PetalWidthCm_0, label='Iris-setosa')
plt.scatter(PetalLengthCm_1, PetalWidthCm_1, label='Iris-versicolor')
plt.scatter(PetalLengthCm_2, PetalWidthCm_2, label='Iris-virginica')
plt.legend()

plt.show()
"""
From the above figure, we can see that the data is almost linearly separable. We know there is not perfect linearly separation between Iris-Versicolor and Iris-Virginica. So, we will not get 100% accuracy. But this is minor thing. Let's check how many amount of accuracy we will get?
"""
"""
I will store input data and output data in two different variables: x and y
"""
x = df[['SepalLengthCm','SepalWidthCm','PetalLengthCm','PetalWidthCm']]
y = df['Species']
print(x, y)
"""
<span style="color:red; font-weight:bold;">Training of model : </span> Let's buid and train the model. I will use linear SVM to buid and train the model. For that, I will use sklearn library of python. As we know, fit() method of SVC object will train the model.
"""
from sklearn.svm import SVC
model = SVC()
model.fit(x, y)
"""
Now, check our model is working or not? I will use predict() method on the SVC object with input data.
"""
model.predict(x)
"""
<span style="color:red; font-weight:bold;">Accuracy/Score of the model : </span> Let's check the score of the model. I will use score() method on SVC object with input and output data.
"""
model.score(x, y)
"""
Yes, we got 97.33% of accuracy, which is much better.
"""
"""
<span style="color:green; font-weight:bold; font-size: 25px;"> Conclusion: </span> I have buid a model using linear SVM on linearly separable data. I can conclude that if we use linear SVM on the linearly separable data, we will get more accuracy.
<br><br><br><br><br><br><br><br>
<center>Thank you</center>
"""