Challenge

Supervised Learning - Classification Week 7 Challenge

1.

PROS

CONS

It is highly accurate

Its speed is low

It can handle many features

It requires more time to process

Works well even in small sets

Separates only 2 classes

2. Applying SVM

from sklearn import datasets, linear_model
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings("ignore")
# Read the dataset
df = pd.read_csv('faults.csv')
df.drop('TypeOfSteel_A400', axis='columns', inplace=True)
df.head()
print(df.info())
print(df.head(5))
# Seperating the values seperatly of the faulty ones from the good ones
X = df.iloc[:, :26].values
y = df.iloc[:, -1].values
#Fault columns
y1 = df.iloc[:, 26].values
y2 = df.iloc[:, 27].values
y3 = df.iloc[:, 28].values
y4 = df.iloc[:, 29].values
y5 = df.iloc[:, 30].values
y6 = df.iloc[:, 31].values
y7 = df.iloc[:, 32].values


# Assigning output for returning for the faulty ones
for n in range(len(y)):
  if y1[n] == 1:
    y[n] = 1
  elif y2[n] == 1:
    y[n] = 2
  elif y3[n] == 1:
    y[n] = 3
  elif y4[n] == 1:
    y[n] = 4
  elif y5[n] == 1:
    y[n] = 5
  elif y6[n] == 1:
    y[n] = 6
  elif y7[n] == 1:
    y[n] = 7
  else :
    y[n] = 0

    print(y)

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state = 4)

from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

from sklearn.svm import SVC
classifier = SVC(kernel = 'rbf', gamma='auto', random_state = 4)
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
print("The score is: ", classifier.score(X_test, y_test))

from sklearn.metrics import confusion_matrix, accuracy_score
cm = confusion_matrix(y_test, y_pred)
print(cm)
accuracy_score(y_test, y_pred)

import seaborn as sn
plt.figure(figsize=(10,7))
sn.heatmap(cm, annot = True)
plt.xlabel('predicted')
plt.ylabel('actual')
plt.show()
print("The score is: ", classifier.score(x_test, y_test))
print('accuracy_score')

Output

The training and test dataset was solved with 75.81% accuracy

This plot shows the distribution of the actual and predicted values in the dataset

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.