Support Vector Machines

You are currently auditing this course.
1 / 20

Support Vector Machines Part-1


Slides

Download the slides


No hints are availble for this assesment

Answer is not availble for this assesment

Please login to comment

53 Comments

This comment has been removed.

I have applieg SVR on my data. It is predicting low range ad medium range very accurately but not predicting peak values (very badly). What could be done for that

  Upvote    Share

Hi,

Did you try cross-validation?

Thanks.

  Upvote    Share

No, but I am going to

Also I want to apply bootstrap algorithm. How can I write code for that

 

  Upvote    Share

Hi,

For bootstrap, you can use the resampling() scikit-learn function. I have provided the link below for your reference:

https://scikit-learn.org/stable/modules/generated/sklearn.utils.resample.html

Thanks.

  Upvote    Share

It worked but has not solved the overfiiting problem. What technique can be used for resolving overfitting in SVR.

 

  Upvote    Share

Hi,

1. Check if the data is non-linear, in which case try using the Gaussian kernel.

2. If training error < validation error then try tuning the following hyperparameters: C or \nu

Thanks.

  Upvote    Share

In SVR rbf score is less than 0.1 with c=1 if I increase it c=1000000 it is coming more than 0.8. Also for linear score is 0.999999 at c=1(seems a case of overfitting)

For polynomial, score is 0.9 with degree 3 at c=1. how can rbf perform so bad

 

  Upvote    Share

Hi,

It really depends on the data. Thus we tune these hyperparameters and pick those which yield better performance.

Thanks.

  Upvote    Share

how can I plot ytest and ypredicted with dates for comparision in python

 

  Upvote    Share

I did not understand the program.

The teacher jumped that line.

np.set_printoptions(precision=2)

Please tell me why it is used for??

  Upvote    Share
Docstring:
Set printing options.

These options determine the way floating point numbers, arrays and
other NumPy objects are displayed.

Parameters
----------
precision : int or None, optional
    Number of digits of precision for floating point output (default 8).
    May be `None` if `floatmode` is not `fixed`, to print as many digits as
    necessary to uniquely specify the value.

 

You can try running the following in order to get documentation: np.set_printoptions?

  Upvote    Share

CHeck this:

  Upvote    Share

I did not understand.

Why the label is 1 and 0 in 2:04:08 ??

 

 

  Upvote    Share

At 2:02:00, see the above video (https://youtu.be/jNKbdFHivT4?t=7348). I have added the screenshot below too.

We are basically talking about moons data set. The label, in that case, is 0 & 1. There are two classes which we have to identify based on two feature X1, X2.

 

  Upvote    Share

The Pipeline function takes as argument a list of tuples, whereas what is being passed as argument in the video is a tuple of tuples. Hence, the error while using the pipeline.

 2  Upvote    Share

Hi,

Thank you for pointing this out.

Thanks.

  Upvote    Share

Can this kind of algorithm apply to clustering too?

From the plot at 24:13 minutes of video, it appears it can be

  Upvote    Share

Hi,

The image that you are referring contains of points that are being classified based on their target variable. This is a form of supervised learning. Clustering on that other hand is an unsupervised learning. Having said that, SVM is being considered for clustering, you can go through the below paper for further information:

http://web.cs.ucla.edu/~qgu/pdf/aistats13b.pdf

Thanks.

  Upvote    Share

Hi,
I tried implementing this solution
https://www.kaggle.com/paul...
but
For Standard Scaling there is no predict function so I am unable to make a pickle file and lntegrate model to flask and see the output . PLEASE HELP ME OUT SIT ITS VERY IMPORTANT.

I used the following code to make a pickle file and predict the output and but is shows error as "THE MODULE STANDARDSCALER HAS NO ATTRIBUTE PREDICT"

import pickle
pickle.dump(scaler , open('b.pkl','wb'))
models = pickle.load(open('b.pkl','rb'))

print(scaler.predict([[23,2345,12]]))

  Upvote    Share

Hi,

The StandardScalar function is used to scale data, to predict using that data you need to use a prediction algorithm. Could you please tell me which problem are you trying to solve here.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

I am solving this problem the solution is also given -
"https://www.kaggle.com/paul..."
but please have a look in the solution and help me what to write in place of scaler here---pickle.dump(scaler , open('b.pkl','wb'))

  Upvote    Share

Hi,

You can find your solution here:
https://stackoverflow.com/q...
Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Thanks

  Upvote    Share

The current video ends at slide 114 (SVM Nonlinear Classification - MOONS dataset): https://cloudxlab.com/asses...

The next video starts at slide 143: https://cloudxlab.com/asses...

The same has happened for other videos before. Could you kindly check? Maybe its only happening for me.

  Upvote    Share

Hi,

If you check the first video, it ends on the slide "Nonlinear SVM Classification: Example", the second video starts with the slide "Linear SVM Classification". If you check the slides on the first video, these are slide# 114, and 116 respectively. Please let us know if you find some other content.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Hi Rajtilak,

The RBF kernel trick part is missing for me between Session 16 and 17.
Nevermind, I found it on youtube: https://www.youtube.com/wat...

Thanks for checking.

  Upvote    Share

Hi Saurabh,

Thanks for your feedback, the videos are updated and the sections are added.

Happy Learning.

  Upvote    Share

I have reset my notebook according to instruction given link
but now i cant find other files in machine learning folder but only classification file..
please tell me how can i get other files i need to work on training model file
reply asap

  Upvote    Share

Hi,

Would request you to clone our GitHub repository and you would find all the files there.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

can you please tell me how can i do that?

  Upvote    Share

Hi,

You can use the following command to clone the GitHub repo:

git clone https://github.com/cloudxla...

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

i am getting this...

  Upvote    Share

Hi,

The command you are using is git clone https://github.com/cloudxla.... However, the correct command is given below:

git clone https://github.com/cloudxla...

There are no .git in the end. You can refer to the following link for further details:
https://help.github.com/en/...
Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

In SVC RBF Is gamma the landmark value??

  Upvote    Share

Hi,

gamma is the kernel coefficient for ‘rbf’, ‘poly’ and ‘sigmoid’. If gamma='scale' (default) is passed then it uses 1 / (n_features * X.var()) as value of gamma, if ‘auto’, uses 1 / n_features.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

so we should pass what default or auto??

  Upvote    Share

Hi,

That depends on the dataset you are working on, or the problem you are trying to solve.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

Yes but what may be the cases for examples?

  Upvote    Share

how could we know when to use svm classifier and when to use logistic regression for a classification problem?
why we did not use any any cross validation in this problem and we did not even find the cross val score where are we testing our model?

  Upvote    Share

Hi,

Depending on the number of training sets (data)/features that you have, you can choose to use either logistic regression or support vector machine.
Lets take these as an example where :

n = number of features,
m = number of training examples

1. If n is large (1–10,000) and m is small (10–1000) : use logistic regression or SVM with a linear kernel.
2. If n is small (1–10 00) and m is intermediate (10–10,000) : use SVM with (Gaussian, polynomial etc) kernel
3. If n is small (1–10 00), m is large (50,000–1,000,000+): first, manually add more features and then use logistic regression or SVM with a linear kernel

Also, you can cross validate as a practice exercise.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

what is the difference between svm classifier and sgd classifier and which one is better?
how do we know when to use which

  Upvote    Share

Hi,

SVM uses the full data and solve a convex optimization problem with respect to these data points, whereas SGD Classifier can treat the data in batches and performs a gradient descent aiming to minimize *expected* loss with respect to the sample distribution. There are no better algorithm, it depends on the data which one you would like to use.

Thanks.

-- Rajtilak Bhattacharjee

  Upvote    Share

I had a quick question, why are we not segregating the dataset into training and test dataset in these examples except when we used the kernel trick?

 1  Upvote    Share

We use kernel trick when the classes in the dataset are not linearly separable, using the kernel trick transforms the input space to higher dimensional space, so the point of doing a train test split on the data is to get an unbiased estimate of the model's performance on unseen data. This is important as owing to the non-linearity some data may be misclassified if the model has built a wrong decision boundary.

But when the dataset is simple and the classes are linearly separable SVC uses a subset of the data (support vectors) on which we are training to create the decision boundaries and the unseen data on which we might make our predictions later on will very much resemble the linearly separable training set and hence may not require the test set for evaluating the model's performance.

Please clarify, whether I am correct.

Thank you

  Upvote    Share

Hi,

Actually the dataset should have been split into train-test sets. This was an example, so we did not show it here. If it is a supervised learning problem, almost all of the time we need to split the dataset into train-test sets so that we can evaluate model.

Thanks.

  Upvote    Share

Here is a question : in the Jupyter notebook for SVM

Why can't I use the other feature x1 as the x-axis :

I did the x0 , x1 transpose :

decision_boundary = -w[1]/w[0] * x1 - b/w[0]
margin = 1/w[0]

I tried , but the diagram didn't seem to be the same;

  Upvote    Share

HI I want to ask ,

what's the color meaning of two different bell curves in the video 2:24:33

which curve should I correspond to? if I choose the landmark

Does different label correspond to different curve with different color?

  Upvote    Share

Hi,

support_vector_machine file and training_models files not able to get from git..can u please help me out..

Thanks,
Sowjanya.

  Upvote    Share

The data is generated/loaded by the notebook code.

  Upvote    Share