Challenge

Supervised Learning - Classification Week 7 Challenge

1. Pros and cons of SVM

Advantages:

effective in a higher dimension, margin separation, memory effective

Disadvantages:

size of the dataset, the noise of data, no probabilistic explanation

2. Apply SVM to the “Surface defects in stainless steel plates” dataset and evaluate it

import pandas as pd
df=pd.read_csv('faults.csv')
df.head()

#Import Library
from sklearn import svm
import pandas as pd
from sklearn.metrics import accuracy_score
import warnings
warnings.filterwarnings('ignore')

X=df.iloc[:,:-1]
y=df['Other_Faults']
# Import train_test_split function
from sklearn.model_selection import train_test_split

# Split dataset into training set and test set
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,random_state=109) # 70% training and 30% test

#Import svm model
from sklearn import svm

clf = svm.SVC(kernel='rbf', C=1,gamma='auto').fit(X, y)

#Predict the response for test dataset
y_pred = clf.predict(X_test)


#Import scikit-learn metrics module for accuracy calculation
from sklearn import metrics

# Model Accuracy: how often is the classifier correct?
print("Accuracy:",metrics.accuracy_score(y_test, y_pred))

# Model Precision: what percentage of positive tuples are labeled as such?( how valid the results are)
print("Precision:",metrics.precision_score(y_test, y_pred))

# Model Recall: what percentage of complete the results are
print("Recall:",metrics.recall_score(y_test, y_pred))

Accuracy: 1.0
Precision: 1.0
Recall: 1.0
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.