Position salary — Support vector regression (SVR)
using the support vector regression (SVR) model we will make a model that will predict what will be the salary of the person at a specific position (with source code)
As in the previous article, I have given you an introduction to support vector regression now I will tell you how to make a basic support vector regression model in this article with some lines of codes.
if you want to know about click on this link -
so let’s start
the first step is we need to download the dataset and then apply the dataset to the model. you can download or copy data from the URL -
Importing the libraries
now we will import pandas, NumPy, and matplotlib as given below if your system has not installed these libraries you can download them by pip command.
Data preparation
now we will read the data by pandas and store it in a variable named data so we don’t need to call it again and again, by the head command we can see the first 5 elements of the data if you wish to see more you can enter the number inside the bracket.
now we will make 2 variables x and y in the x column we will store level and in the variable y we will store the salary by using iloc (here in iloc we have done simple slicing ie we do in lists and strings)and then reshaping y variable
Feature scaling
now we will feature scale our data because the value of levels is too low i.e 1,2,3… compared to salaries i.e 45k, 50k…… so to normalise the range we need to introduce the feature scaling in the model. for now if you don’t understand about feature scaling don’t worry! soon I would be writing an article on feature scaling too.
Making the model
now I will import SVR from sklearn.svm to make the model after importing the model I am creating a variable name regressor and I am giving kernel, a kernel is to find the linear and nonlinear relationship here I am using RBF kernel and calling the model in regression and then after that I would be fitting the values in the SVR model
Predicting
now we will predict the salary of the position 6.5 by the model predicting the values from the model in this case it is different
as you can see I am getting a feature scaled value so to reverse this value I am using inverse transform to get the original value
Plotting
now we will understand how these models look when plotted in the SVR
source code
you can go check the link for full code
Conclusion
in the article I have given you information and codes on how to make a simple support vector regression model with source code I would be making more exciting projects for you so stay connected