svm classification

Akhilesh Joshi
Akhilesh JoshiGraduate Student
SVM CLASSIFICATION
svm classification
svm classification
svm classification
svm classification
svm classification
svm classification
svm classification
svm classification
svm classification
svm classification
svm classification
svm classification
svm classification
svm classification
svm classification
svm classification
svm classification
svm classification
svm classification
svm classification
svm classification
svm classification
PYTHON
READING DATASET DYNAMICALLY
from tkinter import *
from tkinter.filedialog import askopenfilename
root = Tk()
root.withdraw()
root.update()
file_path = askopenfilename()
root.destroy()
IMPORTING LIBRARIES
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
IMPORTING DATASET
dataset = pd.read_csv('Social_Network_Ads.csv')
X = dataset.iloc[:,2:4]
y= dataset.iloc[:,-1]
SPLITTING THE DATASET INTO THE
TRAINING SET AND TEST SET
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25,
random_state = 0)
FEATURE SCALING
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
FEATURE SELECTION …
Recursive Feature Elimination (RFE) is based on the idea to
repeatedly construct a model and choose either the best or
worst performing feature, setting the feature aside and then
repeating the process with the rest of the features.
This process is applied until all features in the dataset are
exhausted. The goal of RFE is to select features.
FITTING CLASSIFIER TO THE
TRAINING SET
from sklearn.svm import SVC
classifier = SVC(kernel = 'linear', random_state = 0)
Or
classifier = SVC(kernel = 'rbf', random_state = 0)
classifier.fit(X_train, y_train)
CONFUSION MATRIX
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
K FOLD
from sklearn import model_selection
from sklearn.model_selection import cross_val_score
kfold = model_selection.KFold(n_splits=10, random_state=7)
modelCV = SVC(kernel = 'linear', random_state = 0)
scoring = 'accuracy'
results = model_selection.cross_val_score(modelCV, X_train, y_train, cv=kfold,
scoring=scoring)
print("10-fold cross validation average accuracy: %.3f" % (results.mean()))
PREDICTION
y_pred = classifier.predict(X_test)
EVALUATING CLASSIFICATION
REPORT
from sklearn.metrics import classification_report
print(classification_report(y_test, y_pred))
R
READ DATASET
library(readr)
dataset <- read_csv("D:/machine learning AZ/Machine Learning A-Z
Template Folder/Part 3 - Classification/Section 14 - Logistic
Regression/Logistic_Regression/Social_Network_Ads.csv")
dataset = dataset[3:5]
ENCODING THE TARGET FEATURE
AS FACTOR
dataset$Purchased = factor(dataset$Purchased, levels = c(0, 1))
SPLITTING THE DATASET INTO THE
TRAINING SET AND TEST SET
# install.packages('caTools')
library(caTools)
set.seed(123)
split = sample.split(dataset$Purchased, SplitRatio = 0.75)
training_set = subset(dataset, split == TRUE)
test_set = subset(dataset, split == FALSE)
FEATURE SCALING
training_set[-3] = scale(training_set[-3])
test_set[-3] = scale(test_set[-3])
FITTING SVM TO THE TRAINING SET
library(e1071)
classifier = svm(Purchased ~ . ,
data = training_set ,
type = 'C-classification’ ,
kernel = 'linear’)
library(e1071)
classifier = svm(formula = Purchased ~ .,
data = training_set,
type = 'C-classification',
kernel = 'radial')
PREDICTION
y_pred = predict(classifier , newdata = test_set[-3])
CONFUSION MATRIX
cm = table(test_set[, 3], y_pred)
1 von 43

Recomendados

Svm von
SvmSvm
Svmwltongxing
1.6K views86 Folien
The world of loss function von
The world of loss functionThe world of loss function
The world of loss function홍배 김
3.2K views80 Folien
Support Vector Machines for Classification von
Support Vector Machines for ClassificationSupport Vector Machines for Classification
Support Vector Machines for ClassificationPrakash Pimpale
35.8K views41 Folien
Deep Dive into Hyperparameter Tuning von
Deep Dive into Hyperparameter TuningDeep Dive into Hyperparameter Tuning
Deep Dive into Hyperparameter TuningShubhmay Potdar
623 views33 Folien
Support Vector Machines von
Support Vector MachinesSupport Vector Machines
Support Vector MachinesCloudxLab
863 views231 Folien
Machine learning Lecture 1 von
Machine learning Lecture 1Machine learning Lecture 1
Machine learning Lecture 1Srinivasan R
25.2K views77 Folien

Más contenido relacionado

Was ist angesagt?

Linear models for classification von
Linear models for classificationLinear models for classification
Linear models for classificationSung Yub Kim
2.5K views29 Folien
Naive Bayes Presentation von
Naive Bayes PresentationNaive Bayes Presentation
Naive Bayes PresentationMd. Enamul Haque Chowdhury
10.8K views32 Folien
Introduction to Machine Learning Classifiers von
Introduction to Machine Learning ClassifiersIntroduction to Machine Learning Classifiers
Introduction to Machine Learning ClassifiersFunctional Imperative
12.6K views38 Folien
NAIVE BAYES CLASSIFIER von
NAIVE BAYES CLASSIFIERNAIVE BAYES CLASSIFIER
NAIVE BAYES CLASSIFIERKnoldus Inc.
5.9K views36 Folien
Support vector machine von
Support vector machineSupport vector machine
Support vector machinezekeLabs Technologies
2.3K views29 Folien
Decision trees in Machine Learning von
Decision trees in Machine Learning Decision trees in Machine Learning
Decision trees in Machine Learning Mohammad Junaid Khan
6.7K views19 Folien

Was ist angesagt?(20)

Linear models for classification von Sung Yub Kim
Linear models for classificationLinear models for classification
Linear models for classification
Sung Yub Kim2.5K views
NAIVE BAYES CLASSIFIER von Knoldus Inc.
NAIVE BAYES CLASSIFIERNAIVE BAYES CLASSIFIER
NAIVE BAYES CLASSIFIER
Knoldus Inc.5.9K views
Machine-Learning-A-Z-Course-Downloadable-Slides-V1.5.pdf von Maris R
Machine-Learning-A-Z-Course-Downloadable-Slides-V1.5.pdfMachine-Learning-A-Z-Course-Downloadable-Slides-V1.5.pdf
Machine-Learning-A-Z-Course-Downloadable-Slides-V1.5.pdf
Maris R122 views
Feed forward ,back propagation,gradient descent von Muhammad Rasel
Feed forward ,back propagation,gradient descentFeed forward ,back propagation,gradient descent
Feed forward ,back propagation,gradient descent
Muhammad Rasel609 views
Support Vector Machines von nextlib
Support Vector MachinesSupport Vector Machines
Support Vector Machines
nextlib19.9K views
Naive bayes von umeskath
Naive bayesNaive bayes
Naive bayes
umeskath983 views
Support vector machines (svm) von Sharayu Patil
Support vector machines (svm)Support vector machines (svm)
Support vector machines (svm)
Sharayu Patil1.2K views
Machine learning von Amit Rathi
Machine learningMachine learning
Machine learning
Amit Rathi1.9K views
Support Vector Machine (SVM) von Sana Rahim
Support Vector Machine (SVM)Support Vector Machine (SVM)
Support Vector Machine (SVM)
Sana Rahim360 views
Linear regression von MartinHogg9
Linear regressionLinear regression
Linear regression
MartinHogg912.2K views
Deep neural networks von Si Haem
Deep neural networksDeep neural networks
Deep neural networks
Si Haem162.5K views
Support Vector Machine - How Support Vector Machine works | SVM in Machine Le... von Simplilearn
Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...
Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...
Simplilearn10.2K views
Machine Learning in 5 Minutes— Classification von Brian Lange
Machine Learning in 5 Minutes— ClassificationMachine Learning in 5 Minutes— Classification
Machine Learning in 5 Minutes— Classification
Brian Lange4.9K views

Similar a svm classification

knn classification von
knn classificationknn classification
knn classificationAkhilesh Joshi
1.2K views23 Folien
logistic regression with python and R von
logistic regression with python and Rlogistic regression with python and R
logistic regression with python and RAkhilesh Joshi
1.1K views27 Folien
Grid search (parameter tuning) von
Grid search (parameter tuning)Grid search (parameter tuning)
Grid search (parameter tuning)Akhilesh Joshi
524 views13 Folien
K fold von
K foldK fold
K foldAkhilesh Joshi
225 views10 Folien
X_train y_trainX_test y_testX_valid y_validtrainin.docx von
X_train y_trainX_test y_testX_valid y_validtrainin.docxX_train y_trainX_test y_testX_valid y_validtrainin.docx
X_train y_trainX_test y_testX_valid y_validtrainin.docxtroutmanboris
2 views12 Folien
simple linear regression von
simple linear regressionsimple linear regression
simple linear regressionAkhilesh Joshi
355 views16 Folien

Similar a svm classification(20)

logistic regression with python and R von Akhilesh Joshi
logistic regression with python and Rlogistic regression with python and R
logistic regression with python and R
Akhilesh Joshi1.1K views
Grid search (parameter tuning) von Akhilesh Joshi
Grid search (parameter tuning)Grid search (parameter tuning)
Grid search (parameter tuning)
Akhilesh Joshi524 views
X_train y_trainX_test y_testX_valid y_validtrainin.docx von troutmanboris
X_train y_trainX_test y_testX_valid y_validtrainin.docxX_train y_trainX_test y_testX_valid y_validtrainin.docx
X_train y_trainX_test y_testX_valid y_validtrainin.docx
troutmanboris2 views
My code from sklearn-datasets import load_diabetes from sklearn-model.pdf von KOCHHARHOSY
My code  from sklearn-datasets import load_diabetes from sklearn-model.pdfMy code  from sklearn-datasets import load_diabetes from sklearn-model.pdf
My code from sklearn-datasets import load_diabetes from sklearn-model.pdf
KOCHHARHOSY7 views
Converting Scikit-Learn to PMML von Villu Ruusmann
Converting Scikit-Learn to PMMLConverting Scikit-Learn to PMML
Converting Scikit-Learn to PMML
Villu Ruusmann27.8K views
Nyc open-data-2015-andvanced-sklearn-expanded von Vivian S. Zhang
Nyc open-data-2015-andvanced-sklearn-expandedNyc open-data-2015-andvanced-sklearn-expanded
Nyc open-data-2015-andvanced-sklearn-expanded
Vivian S. Zhang2.6K views
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch) von Thomas Fan
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)
Thomas Fan575 views
Machine Learning - Introduction von Empatika
Machine Learning - IntroductionMachine Learning - Introduction
Machine Learning - Introduction
Empatika771 views
import numpy as np import pandas as pd import matplotlib.pyplot as pl.pdf von alankritaecobags
 import numpy as np import pandas as pd import matplotlib.pyplot as pl.pdf import numpy as np import pandas as pd import matplotlib.pyplot as pl.pdf
import numpy as np import pandas as pd import matplotlib.pyplot as pl.pdf
alankritaecobags13 views
Data preprocessing for Machine Learning with R and Python von Akhilesh Joshi
Data preprocessing for Machine Learning with R and PythonData preprocessing for Machine Learning with R and Python
Data preprocessing for Machine Learning with R and Python
Akhilesh Joshi646 views
Hybrid quantum classical neural networks with pytorch and qiskit von Vijayananda Mohire
Hybrid quantum classical neural networks with pytorch and qiskitHybrid quantum classical neural networks with pytorch and qiskit
Hybrid quantum classical neural networks with pytorch and qiskit
Vijayananda Mohire268 views
Assignment 6.2a.pdf von dash41
Assignment 6.2a.pdfAssignment 6.2a.pdf
Assignment 6.2a.pdf
dash4110 views
I am working on this code for my project- but the accuracy is 0-951601.docx von RyanEAcTuckern
I am working on this code for my project- but the accuracy is 0-951601.docxI am working on this code for my project- but the accuracy is 0-951601.docx
I am working on this code for my project- but the accuracy is 0-951601.docx
RyanEAcTuckern8 views
Python Unit Test von David Xie
Python Unit TestPython Unit Test
Python Unit Test
David Xie1.5K views

Más de Akhilesh Joshi

PCA and LDA in machine learning von
PCA and LDA in machine learningPCA and LDA in machine learning
PCA and LDA in machine learningAkhilesh Joshi
4K views188 Folien
random forest regression von
random forest regressionrandom forest regression
random forest regressionAkhilesh Joshi
1.6K views14 Folien
decision tree regression von
decision tree regressiondecision tree regression
decision tree regressionAkhilesh Joshi
1.7K views20 Folien
polynomial linear regression von
polynomial linear regressionpolynomial linear regression
polynomial linear regressionAkhilesh Joshi
1.1K views21 Folien
multiple linear regression von
multiple linear regressionmultiple linear regression
multiple linear regressionAkhilesh Joshi
654 views25 Folien
R square vs adjusted r square von
R square vs adjusted r squareR square vs adjusted r square
R square vs adjusted r squareAkhilesh Joshi
4.5K views9 Folien

Más de Akhilesh Joshi(13)

Último

[DSC Europe 23][AI:CSI] Dragan Pleskonjic - AI Impact on Cybersecurity and P... von
[DSC Europe 23][AI:CSI]  Dragan Pleskonjic - AI Impact on Cybersecurity and P...[DSC Europe 23][AI:CSI]  Dragan Pleskonjic - AI Impact on Cybersecurity and P...
[DSC Europe 23][AI:CSI] Dragan Pleskonjic - AI Impact on Cybersecurity and P...DataScienceConferenc1
8 views36 Folien
Data Journeys Hard Talk workshop final.pptx von
Data Journeys Hard Talk workshop final.pptxData Journeys Hard Talk workshop final.pptx
Data Journeys Hard Talk workshop final.pptxinfo828217
10 views18 Folien
Chapter 3b- Process Communication (1) (1)(1) (1).pptx von
Chapter 3b- Process Communication (1) (1)(1) (1).pptxChapter 3b- Process Communication (1) (1)(1) (1).pptx
Chapter 3b- Process Communication (1) (1)(1) (1).pptxayeshabaig2004
7 views30 Folien
[DSC Europe 23] Ivana Sesic - Use of AI in Public Health.pptx von
[DSC Europe 23] Ivana Sesic - Use of AI in Public Health.pptx[DSC Europe 23] Ivana Sesic - Use of AI in Public Health.pptx
[DSC Europe 23] Ivana Sesic - Use of AI in Public Health.pptxDataScienceConferenc1
5 views15 Folien
CRIJ4385_Death Penalty_F23.pptx von
CRIJ4385_Death Penalty_F23.pptxCRIJ4385_Death Penalty_F23.pptx
CRIJ4385_Death Penalty_F23.pptxyvettemm100
7 views24 Folien
shivam tiwari.pptx von
shivam tiwari.pptxshivam tiwari.pptx
shivam tiwari.pptxAanyaMishra4
5 views14 Folien

Último(20)

[DSC Europe 23][AI:CSI] Dragan Pleskonjic - AI Impact on Cybersecurity and P... von DataScienceConferenc1
[DSC Europe 23][AI:CSI]  Dragan Pleskonjic - AI Impact on Cybersecurity and P...[DSC Europe 23][AI:CSI]  Dragan Pleskonjic - AI Impact on Cybersecurity and P...
[DSC Europe 23][AI:CSI] Dragan Pleskonjic - AI Impact on Cybersecurity and P...
Data Journeys Hard Talk workshop final.pptx von info828217
Data Journeys Hard Talk workshop final.pptxData Journeys Hard Talk workshop final.pptx
Data Journeys Hard Talk workshop final.pptx
info82821710 views
Chapter 3b- Process Communication (1) (1)(1) (1).pptx von ayeshabaig2004
Chapter 3b- Process Communication (1) (1)(1) (1).pptxChapter 3b- Process Communication (1) (1)(1) (1).pptx
Chapter 3b- Process Communication (1) (1)(1) (1).pptx
ayeshabaig20047 views
CRIJ4385_Death Penalty_F23.pptx von yvettemm100
CRIJ4385_Death Penalty_F23.pptxCRIJ4385_Death Penalty_F23.pptx
CRIJ4385_Death Penalty_F23.pptx
yvettemm1007 views
Survey on Factuality in LLM's.pptx von NeethaSherra1
Survey on Factuality in LLM's.pptxSurvey on Factuality in LLM's.pptx
Survey on Factuality in LLM's.pptx
NeethaSherra17 views
Ukraine Infographic_22NOV2023_v2.pdf von AnastosiyaGurin
Ukraine Infographic_22NOV2023_v2.pdfUkraine Infographic_22NOV2023_v2.pdf
Ukraine Infographic_22NOV2023_v2.pdf
AnastosiyaGurin1.4K views
[DSC Europe 23] Stefan Mrsic_Goran Savic - Evolving Technology Excellence.pptx von DataScienceConferenc1
[DSC Europe 23] Stefan Mrsic_Goran Savic - Evolving Technology Excellence.pptx[DSC Europe 23] Stefan Mrsic_Goran Savic - Evolving Technology Excellence.pptx
[DSC Europe 23] Stefan Mrsic_Goran Savic - Evolving Technology Excellence.pptx
Cross-network in Google Analytics 4.pdf von GA4 Tutorials
Cross-network in Google Analytics 4.pdfCross-network in Google Analytics 4.pdf
Cross-network in Google Analytics 4.pdf
GA4 Tutorials6 views
[DSC Europe 23] Danijela Horak - The Innovator’s Dilemma: to Build or Not to ... von DataScienceConferenc1
[DSC Europe 23] Danijela Horak - The Innovator’s Dilemma: to Build or Not to ...[DSC Europe 23] Danijela Horak - The Innovator’s Dilemma: to Build or Not to ...
[DSC Europe 23] Danijela Horak - The Innovator’s Dilemma: to Build or Not to ...
CRM stick or twist.pptx von info828217
CRM stick or twist.pptxCRM stick or twist.pptx
CRM stick or twist.pptx
info82821711 views
[DSC Europe 23][AI:CSI] Aleksa Stojanovic - Applying AI for Threat Detection ... von DataScienceConferenc1
[DSC Europe 23][AI:CSI] Aleksa Stojanovic - Applying AI for Threat Detection ...[DSC Europe 23][AI:CSI] Aleksa Stojanovic - Applying AI for Threat Detection ...
[DSC Europe 23][AI:CSI] Aleksa Stojanovic - Applying AI for Threat Detection ...

svm classification

  • 25. READING DATASET DYNAMICALLY from tkinter import * from tkinter.filedialog import askopenfilename root = Tk() root.withdraw() root.update() file_path = askopenfilename() root.destroy()
  • 26. IMPORTING LIBRARIES import pandas as pd import numpy as np import matplotlib.pyplot as plt
  • 27. IMPORTING DATASET dataset = pd.read_csv('Social_Network_Ads.csv') X = dataset.iloc[:,2:4] y= dataset.iloc[:,-1]
  • 28. SPLITTING THE DATASET INTO THE TRAINING SET AND TEST SET from sklearn.cross_validation import train_test_split X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)
  • 29. FEATURE SCALING from sklearn.preprocessing import StandardScaler sc = StandardScaler() X_train = sc.fit_transform(X_train) X_test = sc.transform(X_test)
  • 30. FEATURE SELECTION … Recursive Feature Elimination (RFE) is based on the idea to repeatedly construct a model and choose either the best or worst performing feature, setting the feature aside and then repeating the process with the rest of the features. This process is applied until all features in the dataset are exhausted. The goal of RFE is to select features.
  • 31. FITTING CLASSIFIER TO THE TRAINING SET from sklearn.svm import SVC classifier = SVC(kernel = 'linear', random_state = 0) Or classifier = SVC(kernel = 'rbf', random_state = 0) classifier.fit(X_train, y_train)
  • 32. CONFUSION MATRIX from sklearn.metrics import confusion_matrix cm = confusion_matrix(y_test, y_pred)
  • 33. K FOLD from sklearn import model_selection from sklearn.model_selection import cross_val_score kfold = model_selection.KFold(n_splits=10, random_state=7) modelCV = SVC(kernel = 'linear', random_state = 0) scoring = 'accuracy' results = model_selection.cross_val_score(modelCV, X_train, y_train, cv=kfold, scoring=scoring) print("10-fold cross validation average accuracy: %.3f" % (results.mean()))
  • 35. EVALUATING CLASSIFICATION REPORT from sklearn.metrics import classification_report print(classification_report(y_test, y_pred))
  • 36. R
  • 37. READ DATASET library(readr) dataset <- read_csv("D:/machine learning AZ/Machine Learning A-Z Template Folder/Part 3 - Classification/Section 14 - Logistic Regression/Logistic_Regression/Social_Network_Ads.csv") dataset = dataset[3:5]
  • 38. ENCODING THE TARGET FEATURE AS FACTOR dataset$Purchased = factor(dataset$Purchased, levels = c(0, 1))
  • 39. SPLITTING THE DATASET INTO THE TRAINING SET AND TEST SET # install.packages('caTools') library(caTools) set.seed(123) split = sample.split(dataset$Purchased, SplitRatio = 0.75) training_set = subset(dataset, split == TRUE) test_set = subset(dataset, split == FALSE)
  • 40. FEATURE SCALING training_set[-3] = scale(training_set[-3]) test_set[-3] = scale(test_set[-3])
  • 41. FITTING SVM TO THE TRAINING SET library(e1071) classifier = svm(Purchased ~ . , data = training_set , type = 'C-classification’ , kernel = 'linear’) library(e1071) classifier = svm(formula = Purchased ~ ., data = training_set, type = 'C-classification', kernel = 'radial')
  • 42. PREDICTION y_pred = predict(classifier , newdata = test_set[-3])
  • 43. CONFUSION MATRIX cm = table(test_set[, 3], y_pred)