3 Weeks Beginners Guide to Ace Data Science Interview: #Day 13
By: Vinay Vikram
Tags: Machine Learning, Interview, Data Science, Interview Questions, Python

3 Weeks Beginners Guide to Ace Data Science Interview: #Day 13

Interview questions based on SVM, Naive Bayes

About the Series Data Science field is an exciting career choice and seeing a lot of hiring across fresh, lateral and experienced job positions. It’s one thing to know the concepts and totally another to crack the rigorous interviews for data science positions. If a candidate is aware of the different questions and the interview process, he is on the right path to an excellent career in the evolving Data Science field. This 3-week beginners guide to Ace Data Science Interview will be a useful asset for individuals who are preparing for the Data Science interviews. Every day for the next 21 days, we will talk about the different areas of the Data Science field and cover them elaborately. So sit back and start reading the article to get a finer understanding of the Data Science field and go prepared for the interviews.

I’ve noticed that there are several types of data science interviews that companies conduct and among all interviews I found one thing common.

All interviews start with questions based on some basic algorithms and as you answer these questions the complexity starts increasing and at one point you found your interviewer asking you so many questions on SVM. So make sure you nailed every small concept of SVM very clearly.

Question Time

Question 1: Is Support Vector Machine (SVM) is a linear classifier?

By default, SVM works as a linear classifier when it maps a linear function of the n-dimensional input data onto a feature space where class separation can occur using an (n-1) dimensional hyperplane. But when it uses a kernel, then it maps a non-linear function of the input data onto the feature space, and then it is said to work in a non-linear model.

Question 2: The effectiveness of an SVM depends upon which of the following parameter:

A) Selection of Kernel

B) Kernel Parameters

C) Soft Margin Parameter C

D) All of the above

Answer : D

The SVM effectiveness depends upon how you choose the basic 3 requirements ( C parameter, Type of kernel, Kernel parameter)mentioned above in such a way that it maximizes your efficiency, reduces error and overfitting.

Interviewer gonna ask so many twisted questions related to the different parameters of SVM.

Question 3: What is the RBF Kernel? Suppose you are using RBF kernel in SVM with high Gamma value. What does this signify? A) The model would consider even far away points from hyperplane for modeling

B) The model would consider only the points close to the hyperplane for modeling

C) The model would not be affected by distance of points from hyperplane for modeling

D) None of the above

Answer: B

RBF Kernel is a real-valued function whose value depends only on the distance between the input and some fixed point, either origin.

The gamma parameter in SVM tuning signifies the influence of points either near or far away from the hyperplane.

For a low gamma, the model will be too constrained and include all points of the training dataset, without really capturing the shape.

For a higher gamma, the model will capture the shape of the dataset well.

Question 4: Which of the probabilistic theorem is used in the backend of the Naive Bayes Algorithm. And why it is called as “Naive”.

Naive Bayes Algorithm is a classification technique based on Bayes’ Theorem.

Called “Naive” as it assumes that the presence of a particular feature in a class is unrelated to the presence of any other feature i.e multicollinearity does not exist among the features. And fulfilling this kind of assumption is too rare for any dataset that’s why it is called “Naive”.

Question 5: As both the algorithms Logistic Regression and Naive Bayes calculates the probability then what is the difference between these two(Most asked).

Both algorithms calculate the probability; logistic regression based on the probabilistic threshold and Naive Bayes is based on the Bayes theorem.

Logistic Regression is a Discriminative Model that learns the boundary between classes.

Naive Bayes is a Generative Model that learn the distribution of data.

Question 6: You are given a dataset now how do you decide whether you gonna use the Naive Bayes algorithm or Logistic Regression.

This is a kind of question through which the interviewer wants to know your approach to any problem. And to answer this question you need to know basic concepts of algos.

Selecting among these two algorithms really depends on your problem, there is no secret sauce for selecting an algorithm. But in Classification, Naive Bayes converges quickly but has typically a higher error than Logistic Regression.

On Small dataset, you might want to try out Naive Bayes, but as your dataset size grows you get better results with Logistic Regression.

Question 7: What is the role of C parameter in SVM?

The C parameter tells the SVM optimization how much you want to avoid misclassifying each training example. For large values of C, the optimization will choose a smaller-margin hyperplane if that hyperplane does a better job of getting all the training points classified correctly. Conversely, a very small value of C will cause the optimizer to look for a larger-margin separating hyperplane, even if that hyperplane misclassifies more points. For very tiny values of C, you should get misclassified examples, often even if your training data is linearly separable.

Question 8: What is the difference between logistic regression and SVM?

Logistic regression assumes that the predictors aren’t sufficient to determine the response variable, but determine a probability that is a logistic function of a linear combination of them. If there’s a lot of noise, logistic regression (usually fit with maximum-likelihood techniques) is a great technique.

On the other hand, there are problems where you have thousands of dimensions and the predictors do nearly-certainly determine the response, but in some hard-to-explicitly-program way. An example would be image recognition. If you have a grayscale image, 100 by 100 pixels, you have 10,000 dimensions already. With various basis transforms (kernel trick) you will be able to get a linear separator of the data.

Non-regularized logistic regression techniques don’t work well (in fact, the fitted coefficients diverge) when there’s a separating hyperplane, because the maximum likelihood is achieved by any separating plane, and there’s no guarantee that you’ll get the best one. What you get is an extremely confident model with poor predictive power near the margin.

SVMs get you the best separating hyperplane, and they’re efficient in high dimensional spaces. They’re similar to regularization in terms of trying to find the lowest-normed vector that separates the data, but with a margin condition that favors choosing a good hyperplane. A hard-margin SVM will find a hyperplane that separates all the data (if one exists) and fail if there is none; soft-margin SVMs (generally preferred) do better when there’s noise in the data.

Additionally, SVMs only consider points near the margin (support vectors). Logistic regression considers all the points in the data set. Which you prefer depends on your problem.

Logistic regression is great in a low number of dimensions and when the predictors don’t suffice to give more than a probabilistic estimate of the response. SVMs do better when there’s a higher number of dimensions, and especially on problems where the predictors certainly (or near-certainty) determine the responses.

Question 9: Explain the working pattern of the Support vector algorithms for continuous data. (With this question the interviewer is simply asking you to explain about How SVR works). Question 10: Generally people call SVM as a “ very robust algorithm to outliers”. Explain how it is?

While learning the maximal separating hyperplane for the given data you only consider the points that are between +margin width and — margin width. These points are aptly called support vectors.

Thanks for reading!