Supervised Learning - Classification Week 7 Challenge
Pros of SVM:
- It works really well with a clear margin of separation
- It is effective in high dimensional spaces.
- It is effective in cases where the number of dimensions is greater than the number of samples.
- It uses a subset of training points in the decision function (called support vectors), so it is also memory efficient
Cons of SVM:
- It doesn’t perform well when we have large data set because the required training time is higher
- It also doesn’t perform very well, when the data set has more noise i.e. target classes are overlapping
- SVM doesn’t directly provide probability estimates, these are calculated using an expensive five-fold cross-validation. It is included in the related SVC method of Python scikit-learn library.
Performing EDA on the Steel plates defects dataset:
# Importing libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Reading the file
df=pd.read_csv("faults.csv")
# Description of the data
df.describe()
df.head()
df.info
# Check for missing value of data
df.isnull().sum()
# relations between the features in the dataset
sns.heatmap(df,annot=True)
# Creating box plot for under standing outliers
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
Attributes_scaled = pd.DataFrame(scaler.fit_transform(Attributes),columns = Attributes.columns)
Attributes_scaled.boxplot(return_type = 'axes',figsize = (20,20),vert = False)
#Creating a target coloum
Target = []
for i in range(Faults.shape[0]):
if df['Pastry'].values[i] == 1:
Target.append('Pastry')
elif df['Z_Scratch'].values[i] == 1:
Target.append('X_Scratch')
elif df['K_Scatch'].values[i] == 1:
Target.append('K_Scatch')
elif df['Stains'].values[i] == 1:
Target.append('Stains')
elif df['Dirtiness'].values[i] == 1:
Target.append('Dirtiness')
elif df['Bumps'].values[i] == 1:
Target.append('Bumps')
else:
Target.append('Other_Faults')
Target = pd.DataFrame(Target)
df['Target'] = Target
# The data set is splitting into two dataset namely training and test dataset in 70%:30% ratio
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(Attributes_scaled,Target,test_size = 0.3,random_state = 4)
#Applying SVM model to training data set
from sklearn import svm
model = svm.SVC(C = 1,kernel = 'rbf',gamma = 'auto')
fit_model = model.fit(X_train,y_train)
# measure the accuracy of our model and try some predictions of the test data
score = fit_model.score(X_test,y_test)
score
y_predict = fit_model.predict(X_test)
y_predict