Data Science Interview Questions
Data Science Interview Questions
1. What is logistic regression? Or State an example when you have used logistic
regression recently?
Ans :- A subclass of information filtering systems that are meant to predict the
preferences or ratings that a user would give to a product. Recommender systems
are widely used in movies, news, research articles, products, social tags, music,
etc.
Ans :- Cleaning data from multiple sources to transform it into a format that data
analysts or data scientists can work with is a cumbersome process because - as
the number of data sources increases, the time take to clean the data increases
exponentially due to the number of sources and the volume of data generated in
these sources. It might take up to 80% of the time for just cleaning data making it
a critical part of analysis task.
Ans :- Machine learning is the science of getting computers to act without being
explicitly programmed. Machine learning has given us self-driving cars, practical
speech recognition, effective web search, and a vastly improved understanding of
the human genome. It is so widespread that unknowingly we use it many a times
in our daily life.
Ans :- Supervised Machine Learning will be employed for the problem statements
where in output variable (Nominal) of interest can be either classified or
predicted. Examples: KNN, Naive Bayes, SVM, Decision Tree, Random Forest,
Neural Network
Ans :- In this category of Machine Learning, there won’t be any output variable to
be either predicted or classified. Instead the algorithm understands the patterns
in the data. Examples: Segmentation, PCA, SVD, Market Basket Analysis,
Recommender Systems.
Ans:-KNN, Naive Bayes, SVM, Decision Tree, Random Forest, Neural Network
12. When can you say that resultant clusters are good?
Ans:-When the clusters are as much heterogenous as possible and when the
observations within each cluster are as much homogeenous as possible.
13. In which domains can we employ clustering?
Ans:-None of your data science topics are domain specific. They can be employed
in any domain, provided data is available.
Ans:-It would be better if we employ clustering on normalized data as you will get
different results for with and without normalization
17. What is the range of variable when ((x - min(X))/(max(X) - min(X)) normalization
technique is employed?
Ans:-str() command gives dimensions for your data drame. In addition to this it
gives, class of the dataset & class of every variable
Ans:-In Hierarchial Clustering number of clusters will be decided only after looking
at the dendrogram.
Ans:-K value can be selected using sqrt(no. of obs/2), kselection package, scree
plot, k fold cross validation
29. What is the r function to know the number of observations for the levels of a
variable?
30. What is the r function to know the persentae of observations for the levels of a
variable?`
Ans:-lapply returns the ouput as a list whereas sapply returns the ouput as a
vector, matrix or array.
32. Can we represent the output of a classifer having more than two levels using a
confusion matrix?
Ans:-We cannot use confusion matix when we have more than two levels in the
output variable. Instead, we can use crosstable() function from gmodels package
Ans:-It is the probability of two events occuring at the same time. Classical
example is probability of an email being spam wih the word lottery in it.Here the
events are email being spam and email having the word lottery
Ans:-dim() function or nrow() & col() can be used to find row & column count
Ans:-Here we plot each data point in n-dimensional space with the value of each
dimension being the value of a particular coordinate. Then, we perform
classification by finding the hyper-plane that differentiate the classes very well
Ans:-Kernel, Regularization, Gamma and Margin are the tuning paramers of SVM
Ans:-Kernel tricks are nothing but the transformations applied on input variables
which separate non-separable data to separable data. There are 9 different kernel
tricks. Examples are Linear, RBF, Polynomial, etc.
43. Is there a need to convert categorical variables into numeric in SVM? If yes,
explain.
Ans:-Gamma is the kernel coefficient in the kernel tricks RBF, Polynomial, &
Sigmoid. Higher values of Gamma will make the model more complex and overfits
the model.
Ans:-Margin is the separation line to the closest class datapoints. Larger the
margin width, better is the classification done. But before even achieving
maximum margin, objective of te algorithm is to correctly classify datapoints.
Ans:-A path from root node to leaf node represents classification rules
51. Explain different types of nodes in nodes in decision tree and how are they
selected.
Ans:-We have Root Node, Internal Node, Leaf Node in a decision tree. Decision
Tree starts at the Root Node, this is the first node of the decision tree. Data set is
split based on Root Node, again nodes are selected to further split the already
splitted data. This process of splitting the data goes on till we get leaf nodes,
which are nothing but the classification labels. The process of selecting Root
Nodes and Internal Nodes is done using the statistical measure called as Gain
Ans:-We say a data set is pure or homoegenous if all of it's class labels is the same
and impure or hetergenous if the class labels are different. Entropy or Gini Index
or Classification Error can be used to measure impurity of the data set.
Ans:-The process of removal of sub nodes which contribute less power to the
decision tree model is called as Pruning.
Ans:-C50 and tree packages can be used to implement a decision tree algorithm in
R.
59. How does Random Forest adds randomness and build a better model?
Ans:-Instead of searching for the most important feature while splitting a node, it
searches for the best feature among a random subset of features. This results in a
wide diversity that generally results in a better model. Additional randomness can
be added by using random thresholds for each feature rather than searching for
the best possible thresholds (like a normal decision tree does).
Ans:- Random Forest won't overfit the model, it is unexcelled in reliable accuracy,
works very well on large data sets, can handle thousands of input variables
without deletion, outputs significance of input variables, handles outliers and
missing values very well
Ans:- The main limitation of Random Forest is that a large number of trees can
make the algorithm to slow and ineffective for real-time predictions. In most real-
world applications the random forest algorithm is fast enough, but there can
certainly be situations where run-time performance is important and other
approaches would be preferred.
66. What are the different types of activation functions in neural network?
Ans:- A discrete random variable is a random variable that has countable values,
such as a list of non-negative integers.
Ans:- Height of students in class, weight of students in class, time it takes to get to
school, distance traveled between classes are few of the examples of continuous
random variables
Ans:- Expected value (EV), also known as mean value, is the expected outcome of a
given experiment, calculated as the weighted average of all possible values of a
random variable based on their probabilities. EV(n) = x1P1 + X2P2+X3P3+...+XnPn
77. What is the difference between a nominal and an ordinal data type?
Ans:- Interval scales are numeric scales in which we know not only the order, but
also the exact differences between the values, but the problem with the problem
with interval scales is that they don’t have a “true zero". Temperature and Dates
are examples of Interval data type. Whereas Ratio data type tell us about the
order, exact value between units, and they also have an absolute zero. Heights &
Weights of people, length of a object
79. Why Data Types are important?
Ans:- Absolute zero means true absence of a value. We do not have any absolute
zero in Interval data type. One such example is 0 Celsius temperature which does
not mean that the temperature is absent.
81. Which data object in R is used to store and process categorical data?
Ans:- The Factor data objects in R are used to store and process categorical data in
R.
Ans:- Factor variable is a variable which can take only limited set of values. In
other words, the levels of a factor variable will be limited.
Ans:- "%%" gives remainder of the division of first vector with second while "%/%"
gives the quotient of the division of first vector with second.
Ans:- The lazy evaluation of a function means, the argument is evaluated only if it
is used inside the body of the function. If there is no reference to the argument in
the body of the function then it is simply ignored.
Ans:- NA
86. What is the difference between subset() function and sample() function in R?
Ans:- The subset() functions is used to select variables and observations. The
sample() function is used to choose a random sample of size n from a dataset.
Ans:- Every matrix can be called an array but not the reverse. Matrix is always two
dimensional but array can be of any dimension.
88. How do you convert the data in a JSON file to a data frame?
Ans:- This is the package which is loaded by default when R environment is set. It
provides the basic functionalities like input/output, arithmetic calculations etc. in
the R environment.
Ans:- When two vectors of different length are involved in a operation then the
elements of the shorter vector are reused to complete the operation. This is called
element recycling. Example - v1 <- c(4,1,0,6) and V2 <- c(2,4) then v1*v2 gives
(8,4,0,24). The elements 2 and 4 are repeated.
validation
Ans:- In R the data objects can be converted from one form to another. For
example we can create a data frame by merging many lists. This involves a series
of R commands to bring the data into the new format. This is called data
reshaping.
Ans:- A Bar plot of a numerical variable will be cluttered and makes it difficult for
interpretation, whereas it makes sense to employ bar plot on categorical variable
as we can interpret it in an efficient way.
Ans:- Variance is calculated to find how the individual data points are away from
the mean, nothing but dispersion in the data. It is calculated as the averge of the
square of the difference of mean from each data point. So from this calculation,
we know for a fact that units are getting squared. There is way to get rid of
squared units without having the necessity of standard deviation is by taking an
absolute instead of square in the variance calculation. But the problem with taking
absolute is it will lead to misleading results, for example, two variable X1(4,4,-4,-4)
& X2(7,1,-6,-2) you get same variance as 4 if absolute is used and different
variances as 4 & 4.74 when squared is used. For this reason we resort to squaring
the difference of each value from it's mean. At this stage, if we interpret
dispersion of data based on Variance, it shall confusion as the values & units are
squared. Hence, we resort to Standard Deviation.
106. Why the probability associated with a single value of a continuous random
variable is considered to be zero?
Ans:- This Sampling technique uses randomization to make sure that every
element of the population gets an equal chance to be part of the selected sample.
It’s alternatively known as random sampling. Simple Random Sampling, Stratified
Sampling, Systematic Sampling, Cluster Sampling, Multi stage Sampling are the
types of Probability Sampling
Ans:- Every element has an equal chance of getting selected to be the part sample.
It is used when we don’t have any kind of prior information about the target
population. For example: Random selection of 20 students from class of 50
student. Each student has equal chance of getting selected. Here probability of
selection is 1/50
Ans:- This technique divides the elements of the population into small subgroups
(strata) based on the similarity in such a way that the elements within the group
are homogeneous and heterogeneous among the other subgroups formed. And
then the elements are randomly selected from each of these strata. We need to
have prior information about the population to create subgroups.
Ans:- Our entire population is divided into clusters or sections and then the
clusters are randomly selected. All the elements of the cluster are used for
sampling. Clusters are identified using details such as age, sex, location etc. Single
Stage Cluster Sampling or Two Stage Cluster Sampling can be used to perform
Cluster Sampling
Ans:- It does not rely on randomization. This technique is more reliant on the
research era€™s ability to select elements for a sample. Outcome of sampling
might be biased and makes difficult for all the elements of population to be part
of the sample equally. This type of sampling is also known as non-random
sampling. Convenience Sampling, Purposive Sampling, Quota Sampling,
Referral/Snowball Sampling are the types of Non-Probability Sampling
Ans:- Here the samples are selected based on the availability. This method is used
when the availability of sample is rare and also costly. So based on the
convenience samples are selected. For example: Researchers prefer this during
the initial stages of survey research, as it’s quick and easy to deliver results.
Ans:- This is based on the intention or the purpose of study. Only those elements
will be selected from the population which suits the best for the purpose of our
study. For Example: If we want to understand the thought process of the people
who are interested in pursuing master’s degree then the selection criteria would
be “Are you interested for Masters in..?”. All the people who respond with a “No”
will be excluded from our sample.
Ans:- This type of sampling depends of some pre-set standard. It selects the
representative sample from the population. Proportion of characteristics/ trait in
sample should be same as population. Elements are selected until exact
proportions of certain types of data are obtained or sufficient data in different
categories is collected. For example: If our population has 45% females and 55%
males then our sample should reflect the same percentage of males and females.
Ans:- This technique is used in the situations where the population is completely
unknown and rare. Therefore we will take the help from the first element which
we select for the population and ask him to recommend other elements who will
fit the description of the sample needed. So this referral technique goes on,
increasing the size of population like a snowball. For example: It’s used in
situations of highly sensitive topics like HIV Aids. Not all the victims will respond to
the questions asked so researchers can contact people they know or volunteers to
get in touch with the victims and collect information
119. Explain Systematic Sampling Error.
Ans:- When errors are systematic, they bias the sample in one direction. Under
these circumstances, the sample does not truly represent the population of
interest. Systematic error occur s when the sample is not drawn properly. It can
also occur if names are dropped from the sample list because some individuals
were difficult to locate or uncooperative. Individuals dropped from the sample
could be different from those retained. Those remaining could quite possibly
produce a biased sample. Political polls often have special problems that make
prediction difficult.
Ans:- In Statistics, 68–95–99.7 rule is also known as the empirical rule or three
sigma rule. For a Gaussian distribution the the mean (arithmetic average), median
(central value), and mode (most frequent value) coincide. Here, area under the
curve between ± 1s (1 sigma) includes 68% of all values (of the population), while ±
2s (2 sigma) includes 95% and ± 3s (3 sigma) includes 99.7% of all values.
123. In order to come up with a Linear Regression output a minimum of how many
observations are required.
Ans:- Often referred to as Percentiles, Quantiles are the point(values) in your data
below which certain proportion of data falls. For example Median is also a
quantile or 50th percentile below which 50% of the data falls.
126. How is a Normal QQ plot plotted , what is it's use and why is it called as a
Normal QQ plot?
127. What is the use of the reference line in Normal Q-Q plot?
Ans:- Reference Line indicates the normal distribution of the data. If most of the
data points in a Normal Q-Q Plot are falling across the refence line then we say
that the distribution of the underlying data (variable) follows Normal Distribution.
128. What are the R functions to plot QQ Plot and the reference line in a Q-Q Plot
Ans:- qqnorm() is used to plot a Q-Q Plot whereas qqline() is used to plot the
refence line
Ans:- Stadard Deviation and Standard Error are both measures of dispersion or
spreadness. Standard Deviation uses Population data and Standard Error uses
Sample data. Standard Error tells you have far a sample statistic (eg., sample
mean) deviates from the actual Population mean. This deviation is referred as the
Standard Error. Larger the sample size, less will be the deviation (SE) between the
sample mean and the population mean.
Ans:- Central Limit Theorem explains about the distribution of the sample data.
The distribution will be normal, if the population data is normally distributed or if
the propulation data is not normal but the sample size is fairly large.
Ans:- We cannot trust a point esitmate (for example a sample mean) to infer about
Population mean, reason being, if we draw another sample it is more likely that
we will get a different sample mean all together. To overcome this problem, we
come up with an Interval associated with some Confidence. This can be achieved
by including Magin of Error with Point Estimate which gives us the Confidence
Interval
Ans:- Yes, we have standard z values for different probability values. For example,
1.64 for 90%, 1.96 for 95%, & 2.58 for 99% probability values
Ans:- We will not have standard t values for different probability values, reason
being the computation of t value includes degrees of freedom, which is dependent
on the sample size. Hence for the same probability with different degrees of
freedom we get different t values.
137. Why do we have to include Random Sample while interpreting Confidence
Interval?
Ans:- If we were asked to comment about Population Mean (a single value, which
do not change) by using Sample Data (randomly selected from the Population), we
do not calculate Population Mean( i.e., Point Estimate) instead we come up with a
Confidence Interval. Now, if another Sample Data is randomly drawn and CI is
computed then then it is quite obvious that we will get a different CI all together.
Hence, you can say that CI is dependent on the drawn sample. Therefore, it is
always mandatory to interpret CI by including random sample.
Ans:- Degrees of freedom are the number of independent values that a statistical
analysis can estimate. You can also think of it as the number of values that are
free to vary as you estimate parameters They appear in the output of Hypothesis
Tests, Probability Distributions, Regression Analysis. Degrees of freedom is equal
your sample size minus the number of parameters you need to calculate during
an analysis. It is usually a positive whole number.
Ans:- It is the way of testing results of an experiment whether they are valid and
meaningful and have not occured just by chance. If the results have happened just
by chance then the experiment cannot be repeated and is not reusable.
Ans:- Null Hypothesis is nothing but a statement which is usually true. On top of
Null Hypothesis we conduct various Hypothesis Tests to see if Null Hypothesis
holds true or not. Null Hypothesis is denoted by Ho.
Ans:- naive Bayes is so ‘naive’ because it assumes that all of the features in a data
set are equally important and independent. As we know, these assumption are
rarely true in real world scenario.
143. What do you mean by Prior Probability?
Ans:- Prior probability is the proportion of dependent variable in the data set. It is
the closest guess you can make about a class, without any further information.
144. How is True Positive Rate and Recall related? Write the equation.
Ans:- True Positive Rate = Recall. Yes, they are equal having the formula (TP/TP +
FN).
147. Is there a way to capture the correlation between continuous and categorical
variable?
Ans:- A classification trees makes decision based on Gini Index and Node Entropy.
Gini index says, if we select two items from a population at random then they
must be of same class and probability for this is 1 if population is pure. Entropy is
the measure of impurity in the dataset. Entropy is zero when a node is
homogeneous. It is maximum when a both the classes are present in a node at
50% – 50%. Lower entropy is desirable.
Ans:- Cross Entropy essenitally is similar to log loss function used to measure the
probabilities of an actual label. Generally, Log loss term is used in Binary
classifications, whereas Cross Entropy is used for multiple classification.
151. Given Decision Tree & Random Forest, which one do you think might create an
overfitting problem and which one solves the overfitting problem
Ans:- Decision Tree has the tendency of overfitting because for the fact, it tries to
build as much accurate model as possible by selecting the root node & the
internal nodes based on the measure Gain. This Decision Tree will behave very
well on the training data but might not generalize it's predictions on the test data.
To overcome this problem, we have a reliable ensemble algorithm called as
Random Forest which helps in tackling the overfitting problem by creating creating
a lot of decision trees (built using a fewer input variables) and just not a single
one. Finally, the results will be considered based on majority voting or an average
of all the results.
Ans:- Both are purely trial and error methods, we try with different values of K to
find the best value. Another similarity is the distance measure involved. Both the
algorithms have distance measure calculations.
153. For a coefficient value of -0.65123 for an input variable cost.car what has to be
the interpretation of Log(Carpool/Car) in a multinomial regression?
Ans:- First of all, the sign (+ve,-ve) indicates the impact of the input variable on the
output mode. In this case, if there is a unit increase in the input variable i.e.,
cost.car, the Log(Carpool/Car) decreases by 0.65123
154. For Logiistic Regression, is it a good practice to decide on the goodness of the
model based on just accuracy, or is there anything else we can look at.
Ans:- Output of the Logistic Regression is great, you have multiple measures using
which you can comment about the accuracy and reliability of the model. Like,
probabilitites of parameters, Null Deviance, Residual Deviance, stepAIC (to
compare mutliple models), confusion matrix, overall accuracy, Sensitivity (Recall),
Specificity, ROC Curve, Lift Chart are the measures you might want to look at
based on the context of the business objective.
155. How does Multinomial Regression predicts the probabilities of class labels,
given the fact that you have more than 2 class labels?
Ans:- SVM is termed as a black box technique, as internally the algorithm applies
complex transformations on the input variables based on the Kernel trick applied.
Although, the math of these tranformations is not hidden but slightly complex.
Becasue of this complexity, SVM is known as a black box technique.
157. Why are Ensemble techniques more preferred than other classification
models?
Ans:- Firstly the ensemble techniques assure about the reliability of the accuracy.
This however can also be achieved for non-ensemble techniques by employing
various reliability techniques. One such popular technique is k-fold cross
validation. Secondly, it's the way how intelligently the classifications are predicted
in ensemble techniques.
159. What is the need of having Confidence and Lift Ratio, when you have the
Support measure?
Ans:- Support measure helps us in filtering out all the possible combination of
rules which are expnential. Effect of Antecedent or Conseqent being a generalized
product cannot be filtered out just by definig Support. Confidence helps in
filtering out Antecedents being generalized products and Lift Ratio helps in
filtering our Consequents being generalized ones.
160. Are you aware of the algorithm which employs Affinity Analysis ?
Ans:- In User Based Collaborative Filtering, users act as rows and items as
columns. Here we try to find the similarity among the users.
162. What is Item based collaborative filtering?
Ans:- In Item Based Collaborative Filtering, items act as rows and users as
columns. Here we try to find the similarity among the items.
163. How is Item based collaborative filtering different from User based
collaborative filtering?
Ans:- When compared to Users, count of Items will be more. And in Item based
collaborative filtering, we try to find similarity among the items which inturn
makes the process computationally expensive. In addition to this, in User based
collaborative filtering, by trying to find the similarity among the users we try to
connect to the usre's taste. Whereas Item based collaborative filtering is
somewhat similar to Market Basket Analysis where in we generalize the results.
Ans:- It is appropriate to normalize the data when we have the values like
ratings(1-5) as opposed to having values as purchased/not purchased or rated/not
rated.
165. What is the first thing that you need to look at when you are given a dataset?
Ans:- The first check should be made on NA values. Check if there are any NA
values present in the data or not. If present, then impute the NA values rather
than deleting the observations having NAs.
Ans:- Missing data can reduce the power/fit of a model or can lead to a biased
model making incorrect predictions or classifications.
167. What could be the reasons for the presence of NA values in the data?
Ans:- Data Extraction and Data Collection are considered to be the major reasons
for missing values.
168. What are the reasons for the NAs while collecting the data?
Ans:- We divide dataset into two halves. One with no missing values (train data)
and the other one with the missing values (test data). Variable with missing values
is treated as the target variable. Next, we create a model to predict the target
variable based on other attributes of the training data set.
Ans:- There are two drawbacks for this approach. First is that the model estimated
values are usually more well-behaved than the true values. Second is that, if there
is no relationships with attributes in the data set and the attribute with missing
values, then the model will not be precise for estimating missing values.
Ans:- In this method, the missing values of an attribute are imputed using the
given number of attributes that are most similar to the attribute whose values are
missing. The similarity to the attribute is determined using a discrete function.
Ans:- KNN can predict both qualitative and quantitaive attributes Creation of
predictive model for each attribute with missing data is not required Attributes
with multiple missing values can be easily treated Correlation structure of the data
is take into consideration
Ans :-Ensemble methods average out biases, reduce variance, and are less likely to
overfit. General practice in machine learning is: "ensemble and get 2%." This
implies that you can build your models as usual and typically expect a small
performance boost from ensembling.
Ans :-It is a statistical error that causes a bias in the sampling portion of an
experiment. The error causes one sampling group to be selected more often than
other groups included in the experiment. Selection bias may produce an
inaccurate conclusion if the selection bias is not identified.
Ans :-The ROC curve is a graphical representation of the contrast between true
positive rates and the false positive rate at various thresholds. It’s often used as a
proxy for the trade-off between the sensitivity of the model (true positives) vs the
fall-out or the probability it will trigger a false alarm (false positives).
Ans :- Recall is also known as the true positive rate: the amount of positives your
model claims compared to the actual number of positives there are throughout
the data. Precision is also known as the positive predictive value, and it is a
measure of the amount of accurate positives your model claims compared to the
number of positives it actually claims. It can be easier to think of recall and
precision in the context of a case where you’ve predicted that there were 10
apples and 5 oranges in a case of 10 apples. You’d have perfect recall (there are
actually 10 apples, and you predicted there would be 10) but 66.7% precision
because out of the 15 events you predicted, only 10 (the apples) are correct.
182. What’s the trade-off between bias and variance?
Ans :-L2 regularization tends to spread error among all the terms, while L1 is more
binary/sparse, with many variables either being assigned a 1 or 0 in weighting. L1
corresponds to setting a Laplacean prior on the terms, while L2 corresponds to a
Gaussian prior.
184. What’s the difference between Type I and Type II error in hypothesis?
Ans :-Type I error is a false positive, while Type II error is a false negative. Briefly
stated, Type I error means claiming something has happened when it hasn’t, while
Type II error means that you claim nothing is happening when in fact something
is.
Ans :-A generative model will learn categories of data while a discriminative model
will simply learn the distinction between different categories of data.
Discriminative models will generally outperform generative models on
classification tasks.
Ans :-Pruning is what happens in decision trees when branches that have weak
predictive power are removed in order to reduce the complexity of the model and
increase the predictive accuracy of a decision tree model. Pruning can happen
bottom-up and top-down, with approaches such as reduced error pruning and
cost complexity pruning. Reduced error pruning is perhaps the simplest version:
replace each node. If it doesn’t decrease predictive accuracy, keep it pruned. While
simple, this heuristic actually comes pretty close to an approach that would
optimize for maximum accuracy.
187. What are the advantages and disadvantages of decision trees?
188. What is the difference between Gini Impurity and Entropy in a Decision Tree?
Ans :-Gini Impurity and Entropy are the metrics used for deciding how to split a
Decision Tree. Gini measurement is the probability of a random sample being
classified correctly if you randomly pick a label according to the distribution in the
branch.
Entropy is a measurement to calculate the lack of information. You calculate the
Information Gain (difference in entropies) by making a split. This measure helps to
reduce the uncertainty about the output label.
Ans :-An imbalanced dataset is when you have, for example, a classification test
and 90% of the data is in one class. That leads to problems: an accuracy of 90%
can be skewed if you have no predictive power on the other category of data! Few
tactics to handle imbalanced sets 1- Collect more data to even the imbalances in
the dataset. 2- Resample the dataset to correct for imbalances.
192. What is Overfitting? And how do you ensure you’re not overfitting with a
model?
Ans :-Over-fitting occurs when a model studies the training data to such an extent
that it negatively influences the performance of the model on new data. Few
methods to avoid overfitting:
Keep the model simpler: reduce variance by taking into account fewer variables
and parameters, thereby removing some of the noise in the training data.
Collect more data so that the model can be trained with varied samples. Use
cross-validation techniques such as k-folds cross-validation.
Use regularization techniques such as LASSO that penalize certain model
parameters if they’re likely to cause overfitting.
Use ensembling methods, such as Random Forest. It is based on the idea of
bagging, which is used to reduce the variation in the predictions by combining the
result of multiple Decision trees on different samples of the data set.
193. What evaluation approaches would you work to gauge the effectiveness of a
machine learning model?
Ans :-You would first split the dataset into training and test sets, or perhaps use
cross-validation techniques to further segment the dataset into composite sets of
training and test sets within the data. You should then implement a choice
selection of performance metrics such as the F1 score, the accuracy, confusion
matrix alongside error measures in relevance to the problem being solved
Ans :-The Kernel trick involves kernel functions that can enable in higher
dimension. The kernel function maps the lower dimensional data to higher
dimension and nonlinear data will become linear in higher dimension data and
using the kernel trick enables us effectively run algorithms in a high-dimensional
space with lower-dimensional data.
Ans :-Collinearity occurs when two predictor variables (e.g., x1 and x2) in a
multiple regression have some correlation. Multicollinearity occurs when more
than two predictor variables (e.g., x1, x2, and x3) are inter-correlated.
Ans :-A/B is Statistical hypothesis testing for randomized experiment with two
variables A and B. It is used to compare two models that use different predictor
variables in order to check which variable fits best for a given sample of data.
Consider a scenario where you’ve created two models (using different predictor
variables) that can be used to recommend products for an e-commerce platform.
A/B Testing can be used to compare these two models to check which one best
recommends products to a customer.
198. What is Cluster Sampling?
Ans :-NumPy defines arrays along with some basic numerical functions like
indexing, sorting, reshaping, etc. SciPy implements computations such as
numerical integration, optimization and machine learning using NumPy’s
functionality.
200. When these library would you prefer for plotting in Python language: Seaborn,
Matplotlib, Bokeh?
Ans :-Matplotlib: Used for basic plotting like bars, pies, lines, scatter plots, etc
Seaborn: Is built on top of Matplotlib and Pandas to ease data plotting. It is used
for statistical visualizations like creating heatmaps or showing the distribution of
your data Bokeh: Used for interactive visualization. In case your data is too
complex and you haven’t found any “message” in the data, then use Bokeh to
create interactive visualizations that will allow your viewers to explore the data
themselves
Ans :-kmeans algorithm partitions a data set into clusters such that a cluster
formed is homogeneous and the points in each cluster are close to each other.
The algorithm tries to maintain enough separability between these clusters. Due
to unsupervised nature, the clusters have no labels. kNN algorithm is a
classification algorithm which classify an unlabeled observation based on its k (can
be any number ) surrounding neighbors. It is also known as lazy learner because it
involves minimal training of model. Hence, it doesn’t use training data to make
generalization on unseen data set.
205. What is the difference between stochastic gradient descent (SGD) and gradient
descent (GD)?
Ans :-Both algorithms are methods for finding a set of parameters that minimize a
loss function by evaluating parameters against data and then making
adjustments. In standard gradient descent, you'll evaluate all training samples for
each set of parameters. This is akin to taking big, slow steps toward the solution.
In stochastic gradient descent, you'll evaluate only 1 training sample for the set of
parameters before updating them. This is akin to taking small, quick steps toward
the solution.
Ans :-GD theoretically minimizes the error function better than SGD. However,
SGD converges much faster once the dataset becomes large. That means GD is
preferable for small datasets while SGD is preferable for larger ones. In practice,
however, SGD is used for most applications because it minimizes the error
function well enough while being much faster and more memory efficient for large
datasets.