Supervised Learning - Classification Week 7 Challenge
1.
Advantages of support vector machine :
- Support vector machine works comparably well when there is an understandable margin of dissociation between classes.
- It is more productive in high-dimensional spaces.
- It is effective in instances where the number of dimensions is larger than the number of specimens.
- Support vector machine is comparably memory systematic.
Disadvantages of support vector machine :
- The support vector machine algorithm is not acceptable for large data sets.
- It does not execute very well when the data set has more sound i.e. target classes are overlapping.
- In cases where the number of properties for each data point outstrips the number of training data specimens, the support vector machine will underperform.
- As the support vector classifier works by placing data points, above and below the classifying hyperplane there is no probabilistic clarification for the classification.
2.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn import svm
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.metrics import plot_confusion_matrix
#Dataframe df
df = pd.read_csv('faults.csv')
# To print data
print(df)
#to print column names of data
print('n' ,df.columns)
# To check for datatype and presence of null value for the each column
print ('n' ,df.info())
print('n',df.isnull().value.any())
#last seven columns are type of error classification
label_columns=df.columns.value[-7]
#assigning the error classification values to variable targets
targets =(df.iloc[:,7:]++1).idxmax(1)
print('n',label_columns)
print('n',targets)
#dropping the 7 error classification columns and retaining only targets
dataset= df.drop(label__columns,axis=1)
#creating a new column 'target' with all classification values
dataset['target']=target
print('n',dataset.target.value_counts())
fig, ax= plt.subplots(1,2,figsize=(15,6))
#visualising the correlation among each dataset feature
plt.figure(figsize=(10,11))
sns.heatmap(dataset.corr(),annot=false)
#dropping feature with high correlation to other
dataset=dataset.drop('typeofsteel_A400',axis=1)
dataset=dataset.drop('Y_Minimum',axis=1)
print(dataset.shape)
#Assigning feature column value to x
x= dataset.iloc[;,0:24]
#Assigning feature column value to y
y= dataset.iloc[:,24]
# splitting the dataset to training and testing sets
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=0)
#count of each target classification in test set
index =pd.Index(y_test)
print(index.vale_counts())
#SVM Model
model=svm.svc()
model.fit(x_train,y_train)
prediction = model.predict(x_test)
print("nSVM accuracy:",accuracy_score(y_test,predictions))
plot_confusuin_matrix(r,x_test,y_test,label=none, sample_weight=none,normalize=none)
plt.show()