support vector regression

Akhilesh Joshi
Akhilesh JoshiGraduate Student
SVR REGRESSION
NOTE
SVR does not include the feature scaling as some of the linear
regression models from sklearn
So do perform feature scaling separately
For SVR use regression template
PYTHON
IMPORT LIBRARIES
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
READ DATASET
dataset = pd.read_csv("D:machine learning AZMachine Learning A-
Z Template FolderPart 2 - RegressionSection 7 - Support Vector
Regression (SVR)SVRPosition_Salaries.csv")
X = dataset.iloc[:,1:2].values
y = dataset.iloc[:,2:3].values
FEATURE SCALING
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
sc_y = StandardScaler()
X = sc_X.fit_transform(X)
y = sc_y.fit_transform(y)
SUPPORT VECTOR REGRESSION
(SVR)
from sklearn.svm import SVR
regressor = SVR(kernel='rbf')
model = regressor.fit(X,y)
PREDICTIONS
Now we have to predict for 6.5.
But the values that we have are standardized hence we have to convert 6.5 into
standardized value.
- sc_X.transform(np.array([[6.5]])) : here sc_X is used for same scaling
To get back our old value : sc_X.inverse_transform(transformedX)
Therefore , predictions are
transformedX = sc_X.transform(np.array([[6.5]]))
y_pred = regressor.predict(transformedX)
Now we have to fetch the original value of y : y_pred = sc_y.inverse_transform(y_pred)
PLOTTING
plt.scatter(X, y, color = 'red')
plt.plot(X, regressor.predict(X), color = 'blue')
plt.title('Truth or Bluff (SVR)')
plt.xlabel('Position level')
plt.ylabel('Salary')
plt.show()
REFINED PLOT
X_grid = np.arange(min(X), max(X), 0.01) # choice of 0.01 instead of
0.1 step because the data is feature scaled
X_grid = X_grid.reshape((len(X_grid), 1))
plt.scatter(X, y, color = 'red')
plt.plot(X_grid, regressor.predict(X_grid), color = 'blue')
plt.title('Truth or Bluff (SVR)')
plt.xlabel('Position level')
plt.ylabel('Salary')
plt.show()
R
IMPORTING THE DATASET
dataset = read.csv('Position_Salaries.csv')
dataset = dataset[2:3]
PACKAGES
install.packages('e1071')
library(e1071)
FITTING SVR TO THE DATASET
regressor = svm(formula = Salary ~ .,
data = dataset,
type = 'eps-regression',
kernel = 'radial')
PREDICTING A NEW RESULT
y_pred = predict(regressor, data.frame(Level = 6.5))
PLOT
# install.packages('ggplot2')
library(ggplot2)
ggplot() +
geom_point(aes(x = dataset$Level, y = dataset$Salary),
colour = 'red') +
geom_line(aes(x = dataset$Level, y = predict(regressor, newdata =
dataset)),
colour = 'blue') +
ggtitle('Truth or Bluff (SVR)') +
xlab('Level') +
ylab('Salary')
SMOOTH PLOT
# install.packages('ggplot2')
library(ggplot2)
x_grid = seq(min(dataset$Level), max(dataset$Level), 0.1)
ggplot() +
geom_point(aes(x = dataset$Level, y = dataset$Salary),
colour = 'red') +
geom_line(aes(x = x_grid, y = predict(regressor, newdata = data.frame(Level = x_grid))),
colour = 'blue') +
ggtitle('Truth or Bluff (SVR)') +
xlab('Level') +
ylab('Salary')
1 von 17

Recomendados

Clustering von
ClusteringClustering
ClusteringNLPseminar
12.8K views47 Folien
Support Vector Machines ( SVM ) von
Support Vector Machines ( SVM ) Support Vector Machines ( SVM )
Support Vector Machines ( SVM ) Mohammad Junaid Khan
35.5K views26 Folien
Support Vector Machine von
Support Vector MachineSupport Vector Machine
Support Vector MachineShao-Chuan Wang
33.7K views24 Folien
Machine learning with scikitlearn von
Machine learning with scikitlearnMachine learning with scikitlearn
Machine learning with scikitlearnPratap Dangeti
3.9K views31 Folien
Machine Learning - Splitting Datasets von
Machine Learning - Splitting DatasetsMachine Learning - Splitting Datasets
Machine Learning - Splitting DatasetsAndrew Ferlitsch
4.6K views9 Folien
Naive bayes von
Naive bayesNaive bayes
Naive bayesAshraf Uddin
73.3K views38 Folien

Más contenido relacionado

Was ist angesagt?

Introduction to Machine Learning with SciKit-Learn von
Introduction to Machine Learning with SciKit-LearnIntroduction to Machine Learning with SciKit-Learn
Introduction to Machine Learning with SciKit-LearnBenjamin Bengfort
17.5K views78 Folien
07 regularization von
07 regularization07 regularization
07 regularizationRonald Teo
842 views13 Folien
Perceptron (neural network) von
Perceptron (neural network)Perceptron (neural network)
Perceptron (neural network)EdutechLearners
21.7K views33 Folien
Random forest von
Random forestRandom forest
Random forestMusa Hawamdah
53.3K views23 Folien
Clustering von
ClusteringClustering
ClusteringM Rizwan Aqeel
21.8K views37 Folien
Dimensionality Reduction von
Dimensionality ReductionDimensionality Reduction
Dimensionality Reductionmrizwan969
12.6K views135 Folien

Was ist angesagt?(20)

Introduction to Machine Learning with SciKit-Learn von Benjamin Bengfort
Introduction to Machine Learning with SciKit-LearnIntroduction to Machine Learning with SciKit-Learn
Introduction to Machine Learning with SciKit-Learn
Benjamin Bengfort17.5K views
07 regularization von Ronald Teo
07 regularization07 regularization
07 regularization
Ronald Teo842 views
Dimensionality Reduction von mrizwan969
Dimensionality ReductionDimensionality Reduction
Dimensionality Reduction
mrizwan96912.6K views
Classification using back propagation algorithm von KIRAN R
Classification using back propagation algorithmClassification using back propagation algorithm
Classification using back propagation algorithm
KIRAN R1.9K views
Machine learning basics using trees algorithm (Random forest, Gradient Boosting) von Parth Khare
Machine learning basics using trees algorithm (Random forest, Gradient Boosting)Machine learning basics using trees algorithm (Random forest, Gradient Boosting)
Machine learning basics using trees algorithm (Random forest, Gradient Boosting)
Parth Khare8.8K views
Support Vector Machines von nextlib
Support Vector MachinesSupport Vector Machines
Support Vector Machines
nextlib19.9K views
Linear regression von MartinHogg9
Linear regressionLinear regression
Linear regression
MartinHogg912.1K views
Feature selection von dkpawar
Feature selectionFeature selection
Feature selection
dkpawar914 views
Introduction to XGBoost von Joonyoung Yi
Introduction to XGBoostIntroduction to XGBoost
Introduction to XGBoost
Joonyoung Yi5.1K views
Ensemble learning von Haris Jamil
Ensemble learningEnsemble learning
Ensemble learning
Haris Jamil8.6K views
Dimensionality Reduction von Knoldus Inc.
Dimensionality ReductionDimensionality Reduction
Dimensionality Reduction
Knoldus Inc.1.5K views
Machine Learning with Decision trees von Knoldus Inc.
Machine Learning with Decision treesMachine Learning with Decision trees
Machine Learning with Decision trees
Knoldus Inc.23K views
K nearest neighbor von Ujjawal
K nearest neighborK nearest neighbor
K nearest neighbor
Ujjawal 12.1K views
1시간만에 GAN(Generative Adversarial Network) 완전 정복하기 von NAVER Engineering
1시간만에 GAN(Generative Adversarial Network) 완전 정복하기1시간만에 GAN(Generative Adversarial Network) 완전 정복하기
1시간만에 GAN(Generative Adversarial Network) 완전 정복하기
NAVER Engineering23.1K views

Similar a support vector regression

knn classification von
knn classificationknn classification
knn classificationAkhilesh Joshi
1.2K views23 Folien
decision tree regression von
decision tree regressiondecision tree regression
decision tree regressionAkhilesh Joshi
1.7K views20 Folien
simple linear regression von
simple linear regressionsimple linear regression
simple linear regressionAkhilesh Joshi
351 views16 Folien
svm classification von
svm classificationsvm classification
svm classificationAkhilesh Joshi
848 views43 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
Linear Regression (Machine Learning) von
Linear Regression (Machine Learning)Linear Regression (Machine Learning)
Linear Regression (Machine Learning)Omkar Rane
122 views12 Folien

Similar a support vector regression(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
Linear Regression (Machine Learning) von Omkar Rane
Linear Regression (Machine Learning)Linear Regression (Machine Learning)
Linear Regression (Machine Learning)
Omkar Rane122 views
polynomial linear regression von Akhilesh Joshi
polynomial linear regressionpolynomial linear regression
polynomial linear regression
Akhilesh Joshi1.1K views
How to use SVM for data classification von Yiwei Chen
How to use SVM for data classificationHow to use SVM for data classification
How to use SVM for data classification
Yiwei Chen738 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
Computer Graphics in Java and Scala - Part 1b von Philip Schwarz
Computer Graphics in Java and Scala - Part 1bComputer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1b
Philip Schwarz261 views
ggtimeseries-->ggplot2 extensions von Dr. Volkan OBAN
ggtimeseries-->ggplot2 extensions ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions
Dr. Volkan OBAN250 views
Assignment 5.2.pdf von dash41
Assignment 5.2.pdfAssignment 5.2.pdf
Assignment 5.2.pdf
dash414 views
MachineLearningApplication.docx von ArnabNath30
MachineLearningApplication.docxMachineLearningApplication.docx
MachineLearningApplication.docx
ArnabNath308 views
The input cata x1-x2-y can be loaded from fie- -x1_x2_y_circle2-csv- W.docx von GordonB0fPaigey
The input cata x1-x2-y can be loaded from fie- -x1_x2_y_circle2-csv- W.docxThe input cata x1-x2-y can be loaded from fie- -x1_x2_y_circle2-csv- W.docx
The input cata x1-x2-y can be loaded from fie- -x1_x2_y_circle2-csv- W.docx
GordonB0fPaigey7 views
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre... von Yao Yao
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
Yao Yao159 views
Assignment 6.1.pdf von dash41
Assignment 6.1.pdfAssignment 6.1.pdf
Assignment 6.1.pdf
dash4114 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
multiple linear regression von
multiple linear regressionmultiple linear regression
multiple linear regressionAkhilesh Joshi
652 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
K fold von
K foldK fold
K foldAkhilesh Joshi
225 views10 Folien
Grid search (parameter tuning) von
Grid search (parameter tuning)Grid search (parameter tuning)
Grid search (parameter tuning)Akhilesh Joshi
523 views13 Folien

Más de Akhilesh Joshi(14)

Último

Cross-network in Google Analytics 4.pdf von
Cross-network in Google Analytics 4.pdfCross-network in Google Analytics 4.pdf
Cross-network in Google Analytics 4.pdfGA4 Tutorials
6 views7 Folien
Vikas 500 BIG DATA TECHNOLOGIES LAB.pdf von
Vikas 500 BIG DATA TECHNOLOGIES LAB.pdfVikas 500 BIG DATA TECHNOLOGIES LAB.pdf
Vikas 500 BIG DATA TECHNOLOGIES LAB.pdfvikas12611618
8 views30 Folien
Introduction to Microsoft Fabric.pdf von
Introduction to Microsoft Fabric.pdfIntroduction to Microsoft Fabric.pdf
Introduction to Microsoft Fabric.pdfishaniuudeshika
24 views16 Folien
UNEP FI CRS Climate Risk Results.pptx von
UNEP FI CRS Climate Risk Results.pptxUNEP FI CRS Climate Risk Results.pptx
UNEP FI CRS Climate Risk Results.pptxpekka28
11 views51 Folien
Understanding Hallucinations in LLMs - 2023 09 29.pptx von
Understanding Hallucinations in LLMs - 2023 09 29.pptxUnderstanding Hallucinations in LLMs - 2023 09 29.pptx
Understanding Hallucinations in LLMs - 2023 09 29.pptxGreg Makowski
13 views18 Folien
MOSORE_BRESCIA von
MOSORE_BRESCIAMOSORE_BRESCIA
MOSORE_BRESCIAFederico Karagulian
5 views8 Folien

Último(20)

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
Vikas 500 BIG DATA TECHNOLOGIES LAB.pdf von vikas12611618
Vikas 500 BIG DATA TECHNOLOGIES LAB.pdfVikas 500 BIG DATA TECHNOLOGIES LAB.pdf
Vikas 500 BIG DATA TECHNOLOGIES LAB.pdf
vikas126116188 views
UNEP FI CRS Climate Risk Results.pptx von pekka28
UNEP FI CRS Climate Risk Results.pptxUNEP FI CRS Climate Risk Results.pptx
UNEP FI CRS Climate Risk Results.pptx
pekka2811 views
Understanding Hallucinations in LLMs - 2023 09 29.pptx von Greg Makowski
Understanding Hallucinations in LLMs - 2023 09 29.pptxUnderstanding Hallucinations in LLMs - 2023 09 29.pptx
Understanding Hallucinations in LLMs - 2023 09 29.pptx
Greg Makowski13 views
JConWorld_ Continuous SQL with Kafka and Flink von Timothy Spann
JConWorld_ Continuous SQL with Kafka and FlinkJConWorld_ Continuous SQL with Kafka and Flink
JConWorld_ Continuous SQL with Kafka and Flink
Timothy Spann100 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
NeethaSherra15 views
RuleBookForTheFairDataEconomy.pptx von noraelstela1
RuleBookForTheFairDataEconomy.pptxRuleBookForTheFairDataEconomy.pptx
RuleBookForTheFairDataEconomy.pptx
noraelstela167 views
Data structure and algorithm. von Abdul salam
Data structure and algorithm. Data structure and algorithm.
Data structure and algorithm.
Abdul salam 18 views
Advanced_Recommendation_Systems_Presentation.pptx von neeharikasingh29
Advanced_Recommendation_Systems_Presentation.pptxAdvanced_Recommendation_Systems_Presentation.pptx
Advanced_Recommendation_Systems_Presentation.pptx
Short Story Assignment by Kelly Nguyen von kellynguyen01
Short Story Assignment by Kelly NguyenShort Story Assignment by Kelly Nguyen
Short Story Assignment by Kelly Nguyen
kellynguyen0118 views
Supercharging your Data with Azure AI Search and Azure OpenAI von Peter Gallagher
Supercharging your Data with Azure AI Search and Azure OpenAISupercharging your Data with Azure AI Search and Azure OpenAI
Supercharging your Data with Azure AI Search and Azure OpenAI
Peter Gallagher37 views
Building Real-Time Travel Alerts von Timothy Spann
Building Real-Time Travel AlertsBuilding Real-Time Travel Alerts
Building Real-Time Travel Alerts
Timothy Spann109 views

support vector regression

  • 2. NOTE SVR does not include the feature scaling as some of the linear regression models from sklearn So do perform feature scaling separately For SVR use regression template
  • 4. IMPORT LIBRARIES import pandas as pd import numpy as np import matplotlib.pyplot as plt
  • 5. READ DATASET dataset = pd.read_csv("D:machine learning AZMachine Learning A- Z Template FolderPart 2 - RegressionSection 7 - Support Vector Regression (SVR)SVRPosition_Salaries.csv") X = dataset.iloc[:,1:2].values y = dataset.iloc[:,2:3].values
  • 6. FEATURE SCALING from sklearn.preprocessing import StandardScaler sc_X = StandardScaler() sc_y = StandardScaler() X = sc_X.fit_transform(X) y = sc_y.fit_transform(y)
  • 7. SUPPORT VECTOR REGRESSION (SVR) from sklearn.svm import SVR regressor = SVR(kernel='rbf') model = regressor.fit(X,y)
  • 8. PREDICTIONS Now we have to predict for 6.5. But the values that we have are standardized hence we have to convert 6.5 into standardized value. - sc_X.transform(np.array([[6.5]])) : here sc_X is used for same scaling To get back our old value : sc_X.inverse_transform(transformedX) Therefore , predictions are transformedX = sc_X.transform(np.array([[6.5]])) y_pred = regressor.predict(transformedX) Now we have to fetch the original value of y : y_pred = sc_y.inverse_transform(y_pred)
  • 9. PLOTTING plt.scatter(X, y, color = 'red') plt.plot(X, regressor.predict(X), color = 'blue') plt.title('Truth or Bluff (SVR)') plt.xlabel('Position level') plt.ylabel('Salary') plt.show()
  • 10. REFINED PLOT X_grid = np.arange(min(X), max(X), 0.01) # choice of 0.01 instead of 0.1 step because the data is feature scaled X_grid = X_grid.reshape((len(X_grid), 1)) plt.scatter(X, y, color = 'red') plt.plot(X_grid, regressor.predict(X_grid), color = 'blue') plt.title('Truth or Bluff (SVR)') plt.xlabel('Position level') plt.ylabel('Salary') plt.show()
  • 11. R
  • 12. IMPORTING THE DATASET dataset = read.csv('Position_Salaries.csv') dataset = dataset[2:3]
  • 14. FITTING SVR TO THE DATASET regressor = svm(formula = Salary ~ ., data = dataset, type = 'eps-regression', kernel = 'radial')
  • 15. PREDICTING A NEW RESULT y_pred = predict(regressor, data.frame(Level = 6.5))
  • 16. PLOT # install.packages('ggplot2') library(ggplot2) ggplot() + geom_point(aes(x = dataset$Level, y = dataset$Salary), colour = 'red') + geom_line(aes(x = dataset$Level, y = predict(regressor, newdata = dataset)), colour = 'blue') + ggtitle('Truth or Bluff (SVR)') + xlab('Level') + ylab('Salary')
  • 17. SMOOTH PLOT # install.packages('ggplot2') library(ggplot2) x_grid = seq(min(dataset$Level), max(dataset$Level), 0.1) ggplot() + geom_point(aes(x = dataset$Level, y = dataset$Salary), colour = 'red') + geom_line(aes(x = x_grid, y = predict(regressor, newdata = data.frame(Level = x_grid))), colour = 'blue') + ggtitle('Truth or Bluff (SVR)') + xlab('Level') + ylab('Salary')