Challenge

Supervised Learning - Classification Week 7 Challenge

1. SVM is Simple technique and provides good accuracy with less computational power

SVM is more effective for dataset with lot of features

SVM is more prone to over fitting of data

SVM is meant for data with lot of input features not for dataset with huge data entry

import pandas as pd
import numpy as np
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split, cross_val_score

df = pd.read_csv('faults.csv')

#Convert pandas dataFame to np array
X1 = df.values
features = X1[:,0:27]
#Convert np array into dataFrame
x_input = pd.DataFrame(features)
y_output = df[["Pastry","Z_Scratch","K_Scatch","Stains","Dirtiness","Bumps","Other_Faults"]]

#Convert Multi-dimensional output into single coloumn
y = []
for i in range(y_output.shape[0]):
    if y_output["Pastry"].values[i] == 1:
        y.append(0)
    elif y_output["Z_Scratch"].values[i] == 1:
        y.append(1)
    elif y_output["K_Scatch"].values[i] == 1:
        y.append(2)
    elif y_output["Stains"].values[i] == 1:
        y.append(3)
    elif y_output["Dirtiness"].values[i] == 1:
        y.append(4)
    elif y_output["Bumps"].values[i] == 1:
        y.append(5)
    else:
        y.append(6)
        
y_op_1d=np.array(y)
y_op_1d.shape

#Split training and testing data
X_train, X_test, y_train, y_test = train_test_split(x_input,y_op_1d,train_size=0.3)
svm = SVC()
svm.fit(X_train, y_train)
svm.score(X_train, y_train)

#Accuracy for different Cross Validation folds
cross_val_score(SVC(), x_input,y_op_1d, cv=5)
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.