Data Science Interview Flashcards

1
Q

What is supervised machine learning?

A

Supervised learning is a type of machine learning in which our algorithms are trained using well-labeled training data, and machines predict the output based on that data. Labeled data indicates that the input data has already been tagged with the appropriate output. Basically, it is the task of learning a function that maps the input set and returns an output. Some of its examples are: Linear Regression, Logistic Regression, KNN, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is regression? Which models can you use to solve a regression problem?

A

Regression is a part of supervised ML. Regression models investigate the relationship between a dependent (target) and independent variable (s) (predictor). Here are some common regression models

Linear Regression establishes a linear relationship between target and predictor (s). It predicts a numeric value and has a shape of a straight line.
Polynomial Regression has a regression equation with the power of independent variable more than 1. It is a curve that fits into the data points.
Ridge Regression helps when predictors are highly correlated (multicollinearity problem). It penalizes the squares of regression coefficients but doesn’t allow the coefficients to reach zeros (uses L2 regularization).
Lasso Regression penalizes the absolute values of regression coefficients and allows some of the coefficients to reach absolute zero (thereby allowing feature selection).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is linear regression? When do we use it?

A

Linear regression is a model that assumes a linear relationship between the input variables (X) and the single output variable (y).
The case of one explanatory variable is called simple linear regression. For more than one explanatory variable, the process is called multiple linear regression.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the main assumptions of linear regression?

A

There are several assumptions of linear regression. If any of them is violated, model predictions and interpretation may be worthless or misleading.

Linear relationship between features and target variable.
Additivity means that the effect of changes in one of the features on the target variable does not depend on values of other features. For example, a model for predicting revenue of a company have of two features - the number of items a sold and the number of items b sold. When company sells more items a the revenue increases and this is independent of the number of items b sold. But, if customers who buy a stop buying b, the additivity assumption is violated.
Features are not correlated (no collinearity) since it can be difficult to separate out the individual effects of collinear features on the target variable.
Errors are independently and identically normally distributed (yi = B0 + B1*x1i + ... + errori):
    No correlation between errors (consecutive errors in the case of time series data).
    Constant variance of errors - homoscedasticity. For example, in case of time series, seasonal patterns can increase errors in seasons with higher activity.
    Errors are normaly distributed, otherwise some features will have more influence on the target variable than to others. If the error distribution is significantly non-normal, confidence intervals may be too wide or too narrow.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What’s the normal distribution? Why do we care about it? 👶

A

The normal distribution is a continuous probability distribution whose probability density function takes the following formula:

formula

where μ is the mean and σ is the standard deviation of the distribution.

The normal distribution derives its importance from the Central Limit Theorem, which states that if we draw a large enough number of samples, their mean will follow a normal distribution regardless of the initial distribution of the sample, i.e the distribution of the mean of the samples is normal. It is important that each sample is independent from the other.

This is powerful because it helps us study processes whose population distribution is unknown to us.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do we check if a variable follows the normal distribution?

A
  1. Plot a histogram out of the sampled data. If you can fit the bell-shaped “normal” curve to the histogram, then the hypothesis that the underlying random variable follows the normal distribution can not be rejected.
    1. Check Skewness and Kurtosis of the sampled data. Skewness = 0 and kurtosis = 3 are typical for a normal distribution, so the farther away they are from these values, the more non-normal the distribution.
    2. Use Kolmogorov-Smirnov or/and Shapiro-Wilk tests for normality. They take into account both Skewness and Kurtosis simultaneously.
    3. Check for Quantile-Quantile plot. It is a scatterplot created by plotting two sets of quantiles against one another. Normal Q-Q plot place the data points in a roughly straight line.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What if we want to build a model for predicting prices? Are prices distributed normally? Do we need to do any pre-processing for prices?

A

Data is not normal. Specially, real-world datasets or uncleaned datasets always have certain skewness. Same goes for the price prediction. Price of houses or any other thing under consideration depends on a number of factors. So, there’s a great chance of presence of some skewed values i.e outliers if we talk in data science terms.

Yes, you may need to do pre-processing. Most probably, you will need to remove the outliers to make your distribution near-to-normal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What methods for solving linear regression do you know? ‍⭐️

A
  1. Matrix Algebra method
  2. Singular Value Decomposition (SVD)
  3. Gradient Descent
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is gradient descent? How does it work? ‍⭐️

A

Gradient descent is an algorithm that uses calculus concept of gradient to try and reach local or global minima. It works by taking the negative of the gradient in a point of a given function, and updating that point repeatedly using the calculated negative gradient, until the algorithm reaches a local or global minimum, which will cause future iterations of the algorithm to return values that are equal or too close to the current point. It is widely used in machine learning applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the normal equation? ‍⭐️

A

Normal equations are equations obtained by setting equal to zero the partial derivatives of the sum of squared errors (least squares); normal equations allow one to estimate the parameters of a multiple linear regression.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is SGD  —  stochastic gradient descent? What’s the difference with the usual gradient descent? ‍⭐️

A

In both gradient descent (GD) and stochastic gradient descent (SGD), you update a set of parameters in an iterative manner to minimize an error function.

While in GD, you have to run through ALL the samples in your training set to do a single update for a parameter in a particular iteration, in SGD, on the other hand, you use ONLY ONE or SUBSET of training sample from your training set to do the update for a parameter in a particular iteration. If you use SUBSET, it is called Minibatch Stochastic gradient Descent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which metrics for evaluating regression models do you know? 👶

A

Mean Squared Error(MSE)
Root Mean Squared Error(RMSE)
Mean Absolute Error(MAE)
R² or Coefficient of Determination
Adjusted R²

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are MSE and RMSE? 👶

A

MSE stands for Mean Square Error while RMSE stands for Root Mean Square Error. They are metrics with which we can evaluate models.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the bias-variance trade-off? 👶

A

Bias is the error introduced by approximating the true underlying function, which can be quite complex, by a simpler model. Variance is a model sensitivity to changes in the training dataset.

Bias-variance trade-off is a relationship between the expected test error and the variance and the bias - both contribute to the level of the test error and ideally should be as small as possible:

ExpectedTestError = Variance + Bias² + IrreducibleError

But as a model complexity increases, the bias decreases and the variance increases which leads to overfitting. And vice versa, model simplification helps to decrease the variance but it increases the bias which leads to underfitting.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is overfitting? 👶

A

When your model perform very well on your training set but can’t generalize the test set, because it adjusted a lot to the training set.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to validate your models? 👶

A

One of the most common approaches is splitting data into train, validation and test parts. Models are trained on train data, hyperparameters (for example early stopping) are selected based on the validation data, the final measurement is done on test dataset. Another approach is cross-validation: split dataset into K folds and each time train models on training folds and measure the performance on the validation folds. Also you could combine these approaches: make a test/holdout dataset and do cross-validation on the rest of the data. The final quality is measured on test dataset.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Why do we need to split our data into three parts: train, validation, and test? 👶

A

The training set is used to fit the model, i.e. to train the model with the data. The validation set is then used to provide an unbiased evaluation of a model while fine-tuning hyperparameters. This improves the generalization of the model. Finally, a test data set which the model has never “seen” before should be used for the final evaluation of the model. This allows for an unbiased evaluation of the model. The evaluation should never be performed on the same data that is used for training. Otherwise the model performance would not be representative.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Can you explain how cross-validation works? 👶

A

Cross-validation is the process to separate your total training set into two subsets: training and validation set, and evaluate your model to choose the hyperparameters. But you do this process iteratively, selecting differents training and validation set, in order to reduce the bias that you would have by selecting only one validation set.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is K-fold cross-validation? 👶

A

K fold cross validation is a method of cross validation where we select a hyperparameter k. The dataset is now divided into k parts. Now, we take the 1st part as validation set and remaining k-1 as training set. Then we take the 2nd part as validation set and remaining k-1 parts as training set. Like this, each part is used as validation set once and the remaining k-1 parts are taken together and used as training set. It should not be used in a time series data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How do we choose K in K-fold cross-validation? What’s your favorite K? 👶

A

There are two things to consider while deciding K: the number of models we get and the size of validation set. We do not want the number of models to be too less, like 2 or 3. At least 4 models give a less biased decision on the metrics. On the other hand, we would want the dataset to be at least 20-25% of the entire data. So that at least a ratio of 3:1 between training and validation set is maintained.
I tend to use 4 for small datasets and 5 for large ones as K.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is classification? Which models would you use to solve a classification problem? 👶

A

Classification problems are problems in which our prediction space is discrete, i.e. there is a finite number of values the output variable can be. Some models which can be used to solve classification problems are: logistic regression, decision tree, random forests, multi-layer perceptron, one-vs-all, amongst others.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is logistic regression? When do we need to use it? 👶

A

Logistic regression is a Machine Learning algorithm that is used for binary classification. You should use logistic regression when your Y variable takes only two values, e.g. True and False, “spam” and “not spam”, “churn” and “not churn” and so on. The variable is said to be a “binary” or “dichotomous”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Is logistic regression a linear model? Why? 👶

A

Yes, Logistic Regression is considered a generalized linear model because the outcome always depends on the sum of the inputs and parameters. Or in other words, the output cannot depend on the product (or quotient, etc.) of its parameters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is sigmoid? What does it do? 👶

A

A sigmoid function is a type of activation function, and more specifically defined as a squashing function. Squashing functions limit the output to a range between 0 and 1, making these functions useful in the prediction of probabilities.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

How do we evaluate classification models? 👶

A

Accuracy
Precision
Recall
F1 Score
Logistic loss (also known as Cross-entropy loss)
Jaccard similarity coefficient score

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What is accuracy? 👶

A

Accuracy is a metric for evaluating classification models. It is calculated by dividing the number of correct predictions by the number of total predictions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Is accuracy always a good metric? 👶

A

Accuracy is not a good performance metric when there is imbalance in the dataset. For example, in binary classification with 95% of A class and 5% of B class, a constant prediction of A class would have an accuracy of 95%. In case of imbalance dataset, we need to choose Precision, recall, or F1 Score depending on the problem we are trying to solve.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is the confusion table? What are the cells in this table? 👶

A

Confusion table (or confusion matrix) shows how many True positives (TP), True Negative (TN), False Positive (FP) and False Negative (FN) model has made.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What are precision, recall, and F1-score? 👶

A

Precision and recall are classification evaluation metrics:
P = TP / (TP + FP) and R = TP / (TP + FN).
Where TP is true positives, FP is false positives and FN is false negatives
In both cases the score of 1 is the best: we get no false positives or false negatives and only true positives.
F1 is a combination of both precision and recall in one score (harmonic mean):
F1 = 2 * PR / (P + R).
Max F score is 1 and min is 0, with 1 being the best.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Precision-recall trade-off ‍⭐️

A

Tradeoff means increasing one parameter would lead to decreasing of other. Precision-recall tradeoff occur due to increasing one of the parameter(precision or recall) while keeping the model same.

In an ideal scenario where there is a perfectly separable data, both precision and recall can get maximum value of 1.0. But in most of the practical situations, there is noise in the dataset and the dataset is not perfectly separable. There might be some points of positive class closer to the negative class and vice versa. In such cases, shifting the decision boundary can either increase the precision or recall but not both. Increasing one parameter leads to decreasing of the other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What is the ROC curve? When to use it? ‍⭐️

A

ROC stands for Receiver Operating Characteristics. The diagrammatic representation that shows the contrast between true positive rate vs false positive rate. It is used when we need to predict the probability of the binary outcome.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What is AUC (AU ROC)? When to use it? ‍⭐️

A

AUC stands for Area Under the ROC Curve. ROC is a probability curve and AUC represents degree or measure of separability. It’s used when we need to value how much model is capable of distinguishing between classes. The value is between 0 and 1, the higher the better.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

How to interpret the AU ROC score? ‍⭐️

A

AUC score is the value of Area Under the ROC Curve.

An excellent model has AUC near to the 1 which means it has good measure of separability. A poor model has AUC near to the 0 which means it has worst measure of separability. When AUC score is 0.5, it means model has no class separation capacity whatsoever.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What is the PR (precision-recall) curve? ‍⭐️

A

A precision-recall curve (or PR Curve) is a plot of the precision (y-axis) and the recall (x-axis) for different probability thresholds. Precision-recall curves (PR curves) are recommended for highly skewed domains where ROC curves may provide an excessively optimistic view of the performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What is the area under the PR curve? Is it a useful metric? ‍⭐️I

A

A high area under the curve represents both high recall and high precision, where high precision relates to a low false positive rate, and high recall relates to a low false negative rate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

In which cases AU PR is better than AU ROC? ‍⭐️

A

What is different however is that AU ROC looks at a true positive rate TPR and false positive rate FPR while AU PR looks at positive predictive value PPV and true positive rate TPR.

Typically, if true negatives are not meaningful to the problem or you care more about the positive class, AU PR is typically going to be more useful; otherwise, If you care equally about the positive and negative class or your dataset is quite balanced, then going with AU ROC is a good idea.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

What do we do with categorical variables? ‍⭐️

A

Categorical variables must be encoded before they can be used as features to train a machine learning model. There are various encoding techniques, including:

One-hot encoding
Label encoding
Ordinal encoding
Target encoding
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

Why do we need one-hot encoding? ‍⭐️

A

If we simply encode categorical variables with a Label encoder, they become ordinal which can lead to undesirable consequences. In this case, linear models will treat category with id 4 as twice better than a category with id 2. One-hot encoding allows us to represent a categorical variable in a numerical vector space which ensures that vectors of each category have equal distances between each other. This approach is not suited for all situations, because by using it with categorical variables of high cardinality (e.g. customer id) we will encounter problems that come into play because of the curse of dimensionality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

What is “curse of dimensionality”? ‍⭐️

A

The curse of dimensionality is an issue that arises when working with high-dimensional data. It is often said that “the curse of dimensionality” is one of the main problems with machine learning. The curse of dimensionality refers to the fact that, as the number of dimensions (features) in a data set increases, the number of data points required to accurately learn the relationships between those features increases exponentially.

A simple example where we have a data set with two features, x1 and x2. If we want to learn the relationship between these two features, we need to have enough data points so that we can accurately estimate the parameters of that relationship. However, if we add a third feature, x3, then the number of data points required to accurately learn the relationships between all three features increases exponentially. This is because there are now more parameters to estimate, and the number of data points needed to accurately estimate those parameters increases exponentially with the number of parameters.

Simply put, the curse of dimensionality basically means that the error increases with the increase in the number of features.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

What happens to our linear regression model if we have three columns in our data: x, y, z  —  and z is a sum of x and y? ‍⭐️

A

We would not be able to perform the resgression. Because z is linearly dependent on x and y so when performing the regression XTX would be a singular (not invertible) matrix.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

What is regularization? Why do we need it? 👶

A

Regularization is used to reduce overfitting in machine learning models. It helps the models to generalize well and make them robust to outliers and noise in the data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

Which regularization techniques do you know? ‍⭐️

A

There are mainly two types of regularization,

L1 Regularization (Lasso regularization) - Adds the sum of absolute values of the coefficients to the cost function.
L2 Regularization (Ridge regularization) - Adds the sum of squares of coefficients to the cost function.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

What kind of regularization techniques are applicable to linear models? ‍⭐️

A

AIC/BIC, Ridge regression, Lasso, Elastic Net, Basis pursuit denoising, Rudin–Osher–Fatemi model (TV), Potts model, RLAD, Dantzig Selector,SLOPE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

How does L2 regularization look like in a linear model? ‍⭐️

A

L2 regularization adds a penalty term to our cost function which is equal to the sum of squares of models coefficients multiplied by a lambda hyperparameter. This technique makes sure that the coefficients are close to zero and is widely used in cases when we have a lot of features that might correlate with each other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

How do we select the right regularization parameters? 👶

A

Regularization parameters can be chosen using a grid search, for example https://scikit-learn.org/stable/modules/linear_model.html has one formula for the implementing for regularization, alpha in the formula mentioned can be found by doing a RandomSearch or a GridSearch on a set of values and selecting the alpha which gives the least cross validation or validation error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

What’s the effect of L2 regularization on the weights of a linear model? ‍⭐️

A

L2 regularization penalizes larger weights more severely (due to the squared penalty term), which encourages weight values to decay toward zero.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

How L1 regularization looks like in a linear model? ‍⭐️

A

L1 regularization adds a penalty term to our cost function which is equal to the sum of modules of models coefficients multiplied by a lambda hyperparamete

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

What’s the difference between L2 and L1 regularization? ‍⭐️

A

Penalty terms: L1 regularization uses the sum of the absolute values of the weights, while L2 regularization uses the sum of the weights squared.
Feature selection: L1 performs feature selection by reducing the coefficients of some predictors to 0, while L2 does not.
Computational efficiency: L2 has an analytical solution, while L1 does not.
Multicollinearity: L2 addresses multicollinearity by constraining the coefficient norm.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

Can we have both L1 and L2 regularization components in a linear model? ‍⭐️

A

Yes, elastic net regularization combines L1 and L2 regularization.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

What’s the interpretation of the bias term in linear models? ‍⭐️

A

Bias is simply, a difference between predicted value and actual/true value. It can be interpreted as the distance from the average prediction and true value i.e. true value minus mean(predictions). But dont get confused between accuracy and bias.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

How do we interpret weights in linear models? ‍⭐️

A

Without normalizing weights or variables, if you increase the corresponding predictor by one unit, the coefficient represents on average how much the output changes. By the way, this interpretation still works for logistic regression - if you increase the corresponding predictor by one unit, the weight represents the change in the log of the odds.

If the variables are normalized, we can interpret weights in linear models like the importance of this variable in the predicted result.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

If a weight for one variable is higher than for another  —  can we say that this variable is more important? ‍⭐️

A

Yes - if your predictor variables are normalized.

Without normalization, the weight represents the change in the output per unit change in the predictor. If you have a predictor with a huge range and scale that is used to predict an output with a very small range - for example, using each nation’s GDP to predict maternal mortality rates - your coefficient should be very small. That does not necessarily mean that this predictor variable is not important compared to the others.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

When do we need to perform feature normalization for linear models? When it’s okay not to do it? ‍⭐️

A

Feature normalization is necessary for L1 and L2 regularizations. The idea of both methods is to penalize all the features relatively equally. This can’t be done effectively if every feature is scaled differently.

Linear regression without regularization techniques can be used without feature normalization. Also, regularization can help to make the analytical solution more stable, — it adds the regularization matrix to the feature matrix before inverting it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

What is feature selection? Why do we need it? 👶

A

Feature Selection is a method used to select the relevant features for the model to train on. We need feature selection to remove the irrelevant features which leads the model to under-perform.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

Is feature selection important for linear models? ‍⭐️

A

Yes, It is. It can make model performance better through selecting the most importance features and remove irrelanvant features in order to make a prediction and it can also avoid overfitting, underfitting and bias-variance tradeoff.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
56
Q

Which feature selection techniques do you know? ‍⭐️

A

Here are some of the feature selections:

Principal Component Analysis
Neighborhood Component Analysis
ReliefF Algorithm
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
57
Q

Can we use L1 regularization for feature selection? ‍⭐️

A

Yes, because the nature of L1 regularization will lead to sparse coefficients of features. Feature selection can be done by keeping only features with non-zero coefficients.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
58
Q

Can we use L2 regularization for feature selection? ‍⭐️

A

No, Because L2 regularization doesnot make the weights zero but only makes them very very small. L2 regularization can be used to solve multicollinearity since it stablizes the model.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
59
Q

What are the decision trees? 👶

A

This is a type of supervised learning algorithm that is mostly used for classification problems. Surprisingly, it works for both categorical and continuous dependent variables.

In this algorithm, we split the population into two or more homogeneous sets. This is done based on most significant attributes/ independent variables to make as distinct groups as possible.

A decision tree is a flowchart-like tree structure, where each internal node (non-leaf node) denotes a test on an attribute, each branch represents an outcome of the test, and each leaf node (or terminal node) holds a value for the target variable.

Various techniques : like Gini, Information Gain, Chi-square, entropy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
60
Q

How do we train decision trees? ‍⭐️

A

Start at the root node.
For each variable X, find the set S_1 that minimizes the sum of the node impurities in the two child nodes and choose the split {X,S} that gives the minimum over all X and S.
If a stopping criterion is reached, exit. Otherwise, apply step 2 to each child node in turn.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
61
Q

What are the main parameters of the decision tree model? 👶

A

maximum tree depth
minimum samples per leaf node
impurity criterion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
62
Q

How do we handle categorical variables in decision trees? ‍⭐️

A

Some decision tree algorithms can handle categorical variables out of the box, others cannot. However, we can transform categorical variables, e.g. with a binary or a one-hot encoder.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
63
Q

What are the benefits of a single decision tree compared to more complex models? ‍⭐️

A

easy to implement
fast training
fast inference
good explainability

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
64
Q

How can we know which features are more important for the decision tree model? ‍⭐️

A

Often, we want to find a split such that it minimizes the sum of the node impurities. The impurity criterion is a parameter of decision trees. Popular methods to measure the impurity are the Gini impurity and the entropy describing the information gain.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
65
Q

What is random forest? 👶

A

Random Forest is a machine learning method for regression and classification which is composed of many decision trees. Random Forest belongs to a larger class of ML algorithms called ensemble methods (in other words, it involves the combination of several models to solve a single prediction problem).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
66
Q

Why do we need randomization in random forest? ‍⭐️

A

Random forest in an extention of the bagging algorithm which takes random data samples from the training dataset (with replacement), trains several models and averages predictions. In addition to that, each time a split in a tree is considered, random forest takes a random sample of m features from full set of n features (with replacement) and uses this subset of features as candidates for the split (for example, m = sqrt(n)).

Training decision trees on random data samples from the training dataset reduces variance. Sampling features for each split in a decision tree decorrelates trees.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
67
Q

What are the main parameters of the random forest model? ‍⭐️

A

max_depth: Longest Path between root node and the leaf
min_sample_split: The minimum number of observations needed to split a given node
max_leaf_nodes: Conditions the splitting of the tree and hence, limits the growth of the trees
min_samples_leaf: minimum number of samples in the leaf node
n_estimators: Number of trees
max_sample: Fraction of original dataset given to any individual tree in the given model
max_features: Limits the maximum number of features provided to trees in random forest model

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
68
Q

How do we select the depth of the trees in random forest? ‍⭐️

A

The greater the depth, the greater amount of information is extracted from the tree, however, there is a limit to this, and the algorithm even if defensive against overfitting may learn complex features of noise present in data and as a result, may overfit on noise. Hence, there is no hard thumb rule in deciding the depth, but literature suggests a few tips on tuning the depth of the tree to prevent overfitting:

limit the maximum depth of a tree
limit the number of test nodes
limit the minimum number of objects at a node required to split
do not split a node when, at least, one of the resulting subsample sizes is below a given threshold
stop developing a node if it does not sufficiently improve the fit.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
69
Q

How do we know how many trees we need in random forest? ‍⭐️

A

The number of trees in random forest is worked by n_estimators, and a random forest reduces overfitting by increasing the number of trees. There is no fixed thumb rule to decide the number of trees in a random forest, it is rather fine tuned with the data, typically starting off by taking the square of the number of features (n) present in the data followed by tuning until we get the optimal results.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
70
Q

What happens when we have correlated features in our data? ‍⭐️

A

In random forest, since random forest samples some features to build each tree, the information contained in correlated features is twice as much likely to be picked than any other information contained in other features.

In general, when you are adding correlated features, it means that they linearly contains the same information and thus it will reduce the robustness of your model. Each time you train your model, your model might pick one feature or the other to “do the same job” i.e. explain some variance, reduce entropy, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
71
Q

What is gradient boosting trees? ‍⭐️

A

Gradient boosting is a machine learning technique for regression and classification problems, which produces a prediction model in the form of an ensemble of weak prediction models, typically decision trees.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
72
Q

What’s the difference between random forest and gradient boosting? ‍⭐️

A

Random Forests builds each tree independently while Gradient Boosting builds one tree at a time.
Random Forests combine results at the end of the process (by averaging or “majority rules”) while Gradient Boosting combines results along the way.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
73
Q

Is it possible to parallelize training of a gradient boosting model? How to do it? ‍⭐️

A

Yes, different frameworks provide different options to make training faster, using GPUs to speed up the process by making it highly parallelizable.For example, for XGBoost tree_method = ‘gpu_hist’ option makes training faster by use of GPUs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
74
Q

What are the main parameters in the gradient boosting model? ‍⭐️

A

There are many parameters, but below are a few key defaults.

learning_rate=0.1 (shrinkage).
n_estimators=100 (number of trees).
max_depth=3.
min_samples_split=2.
min_samples_leaf=1.
subsample=1.0.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
75
Q

How do you approach tuning parameters in XGBoost or LightGBM? 🚀

A

Depending upon the dataset, parameter tuning can be done manually or using hyperparameter optimization frameworks such as optuna and hyperopt. In manual parameter tuning, we need to be aware of max-depth, min_samples_leaf and min_samples_split so that our model does not overfit the data but try to predict generalized characteristics of data (basically keeping variance and bias low for our model).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
76
Q

How do you select the number of trees in the gradient boosting model? ‍⭐️

A

Most implementations of gradient boosting are configured by default with a relatively small number of trees, such as hundreds or thousands. Using scikit-learn we can perform a grid search of the n_estimators model parameter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
77
Q

Which hyper-parameter tuning strategies (in general) do you know? ‍⭐️

A

There are several strategies for hyper-tuning but I would argue that the three most popular nowadays are the following:

Grid Search is an exhaustive approach such that for each hyper-parameter, the user needs to manually give a list of values for the algorithm to try. After these values are selected, grid search then evaluates the algorithm using each and every combination of hyper-parameters and returns the combination that gives the optimal result (i.e. lowest MAE). Because grid search evaluates the given algorithm using all combinations, it's easy to see that this can be quite computationally expensive and can lead to sub-optimal results specifically since the user needs to specify specific values for these hyper-parameters, which is prone for error and requires domain knowledge.

Random Search is similar to grid search but differs in the sense that rather than specifying which values to try for each hyper-parameter, an upper and lower bound of values for each hyper-parameter is given instead. With uniform probability, random values within these bounds are then chosen and similarly, the best combination is returned to the user. Although this seems less intuitive, no domain knowledge is necessary and theoretically much more of the parameter space can be explored.

In a completely different framework, Bayesian Optimization is thought of as a more statistical way of optimization and is commonly used when using neural networks, specifically since one evaluation of a neural network can be computationally costly. In numerous research papers, this method heavily outperforms Grid Search and Random Search and is currently used on the Google Cloud Platform as well as AWS. Because an in-depth explanation requires a heavy background in bayesian statistics and gaussian processes (and maybe even some game theory), a "simple" explanation is that a much simpler/faster acquisition function intelligently chooses (using a surrogate function such as probability of improvement or GP-UCB) which hyper-parameter values to try on the computationally expensive, original algorithm. Using the result of the initial combination of values on the expensive/original function, the acquisition function takes the result of the expensive/original algorithm into account and uses it as its prior knowledge to again come up with another set of hyper-parameters to choose during the next iteration. This process continues either for a specified number of iterations or for a specified amount of time and similarly the combination of hyper-parameters that performs the best on the expensive/original algorithm is chosen.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
78
Q

What kind of problems neural nets can solve? 👶

A

Neural nets are good at solving non-linear problems. Some good examples are problems that are relatively easy for humans (because of experience, intuition, understanding, etc), but difficult for traditional regression models: speech recognition, handwriting recognition, image identification, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
79
Q

How does a usual fully-connected feed-forward neural network work? ‍⭐️

A

In a usual fully-connected feed-forward network, each neuron receives input from every element of the previous layer and thus the receptive field of a neuron is the entire previous layer. They are usually used to represent feature vectors for input data in classification problems but can be expensive to train because of the number of computations involved.

80
Q

Why do we need activation functions? 👶

A

The main idea of using neural networks is to learn complex nonlinear functions. If we are not using an activation function in between different layers of a neural network, we are just stacking up multiple linear layers one on top of another and this leads to learning a linear function. The Nonlinearity comes only with the activation function, this is the reason we need activation functions.

81
Q

What are the problems with sigmoid as an activation function? ‍⭐️

A

The derivative of the sigmoid function for large positive or negative numbers is almost zero. From this comes the problem of vanishing gradient — during the backpropagation our net will not learn (or will learn drastically slow). One possible way to solve this problem is to use ReLU activation function.

82
Q

What is ReLU? How is it better than sigmoid or tanh? ‍⭐️

A

ReLU is an abbreviation for Rectified Linear Unit. It is an activation function which has the value 0 for all negative values and the value f(x) = x for all positive values. The ReLU has a simple activation function which makes it fast to compute and while the sigmoid and tanh activation functions saturate at higher values, the ReLU has a potentially infinite activation, which addresses the problem of vanishing gradients.

83
Q

How we can initialize the weights of a neural network? ‍⭐️

A

Proper initialization of weight matrix in neural network is very necessary. Simply we can say there are two ways for initializtions.

Initializing weights with zeroes. Setting weights to zero makes your network no better than a linear model. It is important to note that setting biases to 0 will not create any troubles as non zero weights take care of breaking the symmetry and even if bias is 0, the values in every neuron are still different.
Initializing weights randomly. Assigning random values to weights is better than just 0 assignment.

a) If weights are initialized with very high values the term np.dot(W,X)+b becomes significantly higher and if an activation function like sigmoid() is applied, the function maps its value near to 1 where the slope of gradient changes slowly and learning takes a lot of time.
b) If weights are initialized with low values it gets mapped to 0, where the case is the same as above. This problem is often referred to as the vanishing gradient.
84
Q

What if we set all the weights of a neural network to 0? ‍⭐️

A

If all the weights of a neural network are set to zero, the output of each connection is same (W*x = 0). This means the gradients which are backpropagated to each connection in a layer is same. This means all the connections/weights learn the same thing, and the model never converges.

85
Q

What regularization techniques for neural nets do you know? ‍⭐️

A

L1 Regularization - Defined as the sum of absolute values of the individual parameters. The L1 penalty causes a subset of the weights to become zero, suggesting that the corresponding features may safely be discarded.
L2 Regularization - Defined as the sum of square of individual parameters. Often supported by regularization hyperparameter alpha. It results in weight decay.
Data Augmentation - This requires some fake data to be created as a part of training set.
Drop Out : This is most effective regularization technique for newral nets. Few randome nodes in each layer is deactivated in forward pass. This allows the algorithm to train on different set of nodes in each iterations.

86
Q

What is dropout? Why is it useful? How does it work? ‍⭐️

A

Dropout is a technique that at each training step turns off each neuron with a certain probability of p. This way at each iteration we train only 1-p of neurons, which forces the network not to rely only on the subset of neurons for feature representation. This leads to regularizing effects that are controlled by the hyperparameter p.

87
Q

What is backpropagation? How does it work? Why do we need it? ‍⭐️

A

The Backpropagation algorithm looks for the minimum value of the error function in weight space using a technique called the delta rule or gradient descent. The weights that minimize the error function is then considered to be a solution to the learning problem.

We need backpropogation because,

Calculate the error – How far is your model output from the actual output.
Minimum Error – Check whether the error is minimized or not.
Update the parameters – If the error is huge then, update the parameters (weights and biases). After that again check the error.
Repeat the process until the error becomes minimum.
Model is ready to make a prediction – Once the error becomes minimum, you can feed some inputs to your model and it will produce the output.
88
Q

Which optimization techniques for training neural nets do you know? ‍⭐️

A

Gradient Descent
Stochastic Gradient Descent
Mini-Batch Gradient Descent(best among gradient descents)
Nesterov Accelerated Gradient
Momentum
Adagrad
AdaDelta
Adam(best one. less time, more efficient)

89
Q

How do we use SGD (stochastic gradient descent) for training a neural net? ‍⭐️

A

SGD approximates the expectation with few randomly selected samples (instead of the full data). In comparison to batch gradient descent, we can efficiently approximate the expectation in large data sets using SGD. For neural networks this reduces the training time a lot even considering that it will converge later as the random sampling adds noise to the gradient descent.

90
Q

What’s the learning rate? 👶

A

The learning rate is an important hyperparameter that controls how quickly the model is adapted to the problem during the training. It can be seen as the “step width” during the parameter updates, i.e. how far the weights are moved into the direction of the minimum of our optimization problem.

91
Q

What happens when the learning rate is too large? Too small? 👶

A

A large learning rate can accelerate the training. However, it is possible that we “shoot” too far and miss the minimum of the function that we want to optimize, which will not result in the best solution. On the other hand, training with a small learning rate takes more time but it is possible to find a more precise minimum. The downside can be that the solution is stuck in a local minimum, and the weights won’t update even if it is not the best possible global solution.

92
Q

How to set the learning rate? ‍⭐️

A

There is no straightforward way of finding an optimum learning rate for a model. It involves a lot of hit and trial. Usually starting with a small values such as 0.01 is a good starting point for setting a learning rate and further tweaking it so that it doesn’t overshoot or converge too slowly.

93
Q

What is Adam? What’s the main difference between Adam and SGD? ‍⭐️

A

Adam (Adaptive Moment Estimation) is a optimization technique for training neural networks. on an average, it is the best optimizer .It works with momentums of first and second order. The intuition behind the Adam is that we don’t want to roll so fast just because we can jump over the minimum, we want to decrease the velocity a little bit for a careful search.

Adam tends to converge faster, while SGD often converges to more optimal solutions. SGD’s high variance disadvantages gets rectified by Adam (as advantage for Adam).

94
Q

When would you use Adam and when SGD? ‍⭐️

A

Adam tends to converge faster, while SGD often converges to more optimal solutions.

95
Q

Do we want to have a constant learning rate or we better change it throughout training? ‍⭐️

A

You can change the learning rate to have a superior learning rate in the first layers and a lower lr in the final layers

96
Q

How do we decide when to stop training a neural net? 👶

A

Simply stop training when the validation error is the minimum.

97
Q

What is model checkpointing? ‍⭐️

A

Saving the weights learned by a model mid training for long running processes is known as model checkpointing so that you can resume your training from a certain checkpoint.

98
Q

How we can use neural nets for computer vision? ‍⭐️

A

Neural nets used in the area of computer vision are generally Convolutional Neural Networks(CNN’s). You can learn about convolutions below. It appears that convolutions are quite powerful when it comes to working with images and videos due to their ability to extract and learn complex features. Thus CNN’s are a go-to method for any problem in computer vision.

99
Q

What’s a convolutional layer? ‍⭐️

A

The idea of the convolutional layer is the assumption that the information needed for making a decision often is spatially close and thus, it only takes the weighted sum over nearby inputs. It also assumes that the networks’ kernels can be reused for all nodes, hence the number of weights can be drastically reduced. To counteract only one feature being learnt per layer, multiple kernels are applied to the input which creates parallel channels in the output. Consecutive layers can also be stacked to allow the network to find more high-level features.

100
Q

Why do we actually need convolutions? Can’t we use fully-connected layers for that? ‍⭐️

A

A fully-connected layer needs one weight per inter-layer connection, which means the number of weights which needs to be computed quickly balloons as the number of layers and nodes per layer is increased.

101
Q

What’s pooling in CNN? Why do we need it? ‍⭐️

A

Pooling is a technique to downsample the feature map. It allows layers which receive relatively undistorted versions of the input to learn low level features such as lines, while layers deeper in the model can learn more abstract features such as texture.

102
Q

How does max pooling work? Are there other pooling techniques? ‍⭐️

A

Max pooling is a technique where the maximum value of a receptive field is passed on in the next feature map. The most commonly used receptive field is 2 x 2 with a stride of 2, which means the feature map is downsampled from N x N to N/2 x N/2. Receptive fields larger than 3 x 3 are rarely employed as too much information is lost.

Other pooling techniques include:

Average pooling, the output is the average value of the receptive field.
Min pooling, the output is the minimum value of the receptive field.
Global pooling, where the receptive field is set to be equal to the input size, this means the output is equal to a scalar and can be used to reduce the dimensionality of the feature map.

103
Q

Are CNNs resistant to rotations? What happens to the predictions of a CNN if an image is rotated? 🚀

A

CNNs are not resistant to rotation by design. However, we can make our models resistant by augmenting our datasets with different rotations of the raw data. The predictions of a CNN will change if an image is rotated and we did not augment our dataset accordingly. A demonstration of this occurence can be seen in this video, where a CNN changes its predicted class between a duck and a rabbit based on the rotation of the image.

104
Q

What are augmentations? Why do we need them? 👶

A

Augmentations are an artifical way of expanding the existing datasets by performing some transformations, color shifts or many other things on the data. It helps in diversifying the data and even increasing the data when there is scarcity of data for a model to train on.

105
Q

What kind of augmentations do you know? 👶

A

There are many kinds of augmentations which can be used according to the type of data you are working on some of which are geometric and numerical transformation, PCA, cropping, padding, shifting, noise injection etc.

106
Q

How to choose which augmentations to use? ‍⭐️

A

Augmentations really depend on the type of output classes and the features you want your model to learn. For eg. if you have mostly properly illuminated images in your dataset and want your model to predict poorly illuminated images too, you can apply channel shifting on your data and include the resultant images in your dataset for better results.

107
Q

What kind of CNN architectures for classification do you know? 🚀

A

mage Classification

Inception v3
Xception
DenseNet
AlexNet
VGG16
ResNet
SqueezeNet
EfficientNet
MobileNet
The last three are designed so they use smaller number of parameters which is helpful for edge AI.

108
Q

What is transfer learning? How does it work? ‍⭐️

A

Given a source domain D_S and learning task T_S, a target domain D_T and learning task T_T, transfer learning aims to help improve the learning of the target predictive function f_T in D_T using the knowledge in D_S and T_S, where D_S ≠ D_T,or T_S ≠ T_T. In other words, transfer learning enables to reuse knowledge coming from other domains or learning tasks.

In the context of CNNs, we can use networks that were pre-trained on popular datasets such as ImageNet. We then can use the weights of the layers that learn to represent features and combine them with a new set of layers that learns to map the feature representations to the given classes. Two popular strategies are either to freeze the layers that learn the feature representations completely, or to give them a smaller learning rate.

109
Q

What is object detection? Do you know any architectures for that? 🚀

A

Object detection is finding Bounding Boxes around objects in an image. Architectures : YOLO, Faster RCNN, Center Net

110
Q

What is object segmentation? Do you know any architectures for that?

A

Object Segmentation is predicting masks. It does not differentiate objects. Architectures : Mask RCNN, UNet

111
Q

How can we use machine learning for text classification? ‍⭐️

A

Machine learning classification algorithms predict a class based on a numerical feature representation. This means that in order to use machine learning for text classification, we need to extract numerical features from our text data first before we can apply machine learning algorithms. Common approaches to extract numerical features from text data are bag of words, N-grams or word embeddings.

112
Q

What is bag of words? How we can use it for text classification? ‍⭐️

A

Bag of Words is a representation of text that describes the occurrence of words within a document. The order or structure of the words is not considered. For text classification, we look at the histogram of the words within the text and consider each word count as a feature.

113
Q

What are the advantages and disadvantages of bag of words? ‍⭐️

A

Advantages:

Simple to understand and implement.
Disadvantages:

The vocabulary requires careful design, most specifically in order to manage the size, which impacts the sparsity of the document representations.
Sparse representations are harder to model both for computational reasons (space and time complexity) and also for information reasons
Discarding word order ignores the context, and in turn meaning of words in the document. Context and meaning can offer a lot to the model, that if modeled could tell the difference between the same words differently arranged (“this is interesting” vs “is this interesting”), synonyms (“old bike” vs “used bike”).

114
Q

What are N-grams? How can we use them? ‍⭐️

A

The function to tokenize into consecutive sequences of words is called n-grams. It can be used to find out N most co-occurring words (how often word X is followed by word Y) in a given sentence.

115
Q

How large should be N for our bag of words when using N-grams? ‍⭐️

A

Between 3 and 4

116
Q

What is TF-IDF? How is it useful for text classification? ‍⭐️

A

Term Frequency (TF) is a scoring of the frequency of the word in the current document. Inverse Document Frequency(IDF) is a scoring of how rare the word is across documents. It is used in scenario where highly recurring words may not contain as much informational content as the domain specific words. For example, words like “the” that are frequent across all documents therefore need to be less weighted. The TF-IDF score highlights words that are distinct (contain useful information) in a given document.

117
Q

Which model would you use for text classification with bag of words features? ‍⭐️

A

Bag Of Words model
Word2Vec Embeddings
fastText Embeddings
Convolutional Neural Networks (CNN)
Long Short-Term Memory (LSTM)
Bidirectional Encoder Representations from Transformers (BERT)

118
Q

Would you prefer gradient boosting trees model or logistic regression when doing text classification with bag of words? ‍⭐️

A

Usually logistic regression is better because bag of words creates a matrix with large number of columns. For a huge number of columns logistic regression is usually faster than gradient boosting trees.

119
Q

What are word embeddings? Why are they useful? Do you know Word2Vec? ‍⭐️

A

Word Embeddings are vector representations for words. Each word is mapped to one vector, this vector tries to capture some characteristics of the word, allowing similar words to have similar vector representations.
Word Embeddings helps in capturing the inter-word semantics and represents it in real-valued vectors.

Word2Vec is a method to construct such an embedding. It takes a text corpus as input and outputs a set of vectors which represents words in that corpus.

It can be generated using two methods:

Common Bag of Words (CBOW)
Skip-Gram

120
Q

Do you know any other ways to get word embeddings? 🚀

A

TF-IDF
GloVe
BERT

121
Q

If you have a sentence with multiple words, you may need to combine multiple word embeddings into one. How would you do it? ‍⭐️

A

Approaches ranked from simple to more complex:

Take an average over all words
Take a weighted average over all words. Weighting can be done by inverse document frequency (idf part of tf-idf).
Use ML model like LSTM or Transformer.

122
Q

Would you prefer gradient boosting trees model or logistic regression when doing text classification with embeddings? ‍⭐️

A

Logistic regression as it is pretty straightforward and trees are not suited for very high dimensions

123
Q

How can you use neural nets for text classification? 🚀

A

You represent your text into embeddings and then use Dense layers (words are considered independently)

124
Q

How can we use CNN for text classification? 🚀

A

Once you have your text represented into embeddings. You can use conv2d layers to take into account the close context near the word

125
Q

What is unsupervised learning? 👶

A

Unsupervised learning aims to detect paterns in data where no labels are given.

126
Q

What is clustering? When do we need it? 👶

A

Clustering algorithms group objects such that similar feature points are put into the same groups (clusters) and dissimilar feature points are put into different clusters.

127
Q

Do you know how K-means works? ‍⭐️

A

Partition points into k subsets.
Compute the seed points as the new centroids of the clusters of the current partitioning.
Assign each point to the cluster with the nearest seed point.
Go back to step 2 or stop when the assignment does not change.

128
Q

How to select K for K-means? ‍⭐️

A

Domain knowledge, i.e. an expert knows the value of k
Elbow method: compute the clusters for different values of k, for each k, calculate the total within-cluster sum of square, plot the sum according to the number of clusters and use the band as the number of clusters.
Average silhouette method: compute the clusters for different values of k, for each k, calculate the average silhouette of observations, plot the silhouette according to the number of clusters and select the maximum as the number of clusters.

129
Q

What are the other clustering algorithms do you know? ‍⭐️

A

k-medoids: Takes the most central point instead of the mean value as the center of the cluster. This makes it more robust to noise.
Agglomerative Hierarchical Clustering (AHC): hierarchical clusters combining the nearest clusters starting with each point as its own cluster.
DIvisive ANAlysis Clustering (DIANA): hierarchical clustering starting with one cluster containing all points and splitting the clusters until each point describes its own cluster.
Density-Based Spatial Clustering of Applications with Noise (DBSCAN): Cluster defined as maximum set of density-connected points.

130
Q

Do you know how DBScan works? ‍⭐️

A

Two input parameters epsilon (neighborhood radius) and minPts (minimum number of points in an epsilon-neighborhood)
Cluster defined as maximum set of density-connected points.
Points p_j and p_i are density-connected w.r.t. epsilon and minPts if there is a point o such that both, i and j are density-reachable from o w.r.t. epsilon and minPts.
p_j is density-reachable from p_i w.r.t. epsilon, minPts if there is a chain of points p_i -> p_i+1 -> p_i+x = p_j such that p_i+x is directly density-reachable from p_i+x-1.
p_j is a directly density-reachable point of the neighborhood of p_i if dist(p_i,p_j) <= epsilon.

131
Q

When would you choose K-means and when DBScan? ‍⭐️

A

DBScan is more robust to noise.
DBScan is better when the amount of clusters is difficult to guess.
K-means has a lower complexity, i.e. it will be much faster, especially with a larger amount of points.

132
Q

What is the curse of dimensionality? Why do we care about it? ‍⭐️

A

Data in only one dimension is relatively tightly packed. Adding a dimension stretches the points across that dimension, pushing them further apart. Additional dimensions spread the data even further making high dimensional data extremely sparse. We care about it, because it is difficult to use machine learning in sparse spaces.

133
Q

Do you know any dimensionality reduction techniques? ‍⭐️

A

Singular Value Decomposition (SVD)
Principal Component Analysis (PCA)
Linear Discriminant Analysis (LDA)
T-distributed Stochastic Neighbor Embedding (t-SNE)
Autoencoders
Fourier and Wavelet Transforms

134
Q

What’s singular value decomposition? How is it typically used for machine learning? ‍⭐️

A

Singular Value Decomposition (SVD) is a general matrix decomposition method that factors a matrix X into three matrices L (left singular values), Σ (diagonal matrix) and R^T (right singular values).
For machine learning, Principal Component Analysis (PCA) is typically used. It is a special type of SVD where the singular values correspond to the eigenvectors and the values of the diagonal matrix are the squares of the eigenvalues. We use these features as they are statistically descriptive.
Having calculated the eigenvectors and eigenvalues, we can use the Kaiser-Guttman criterion, a scree plot or the proportion of explained variance to determine the principal components (i.e. the final dimensionality) that are useful for dimensionality reduction.

135
Q

What are good unsupervised baselines for text information retrieval? ‍⭐️

A

Tfidf

136
Q

How would you evaluate your ranking algorithms? Which offline metrics would you use? ‍⭐️

A

MAP, precision, recall, p@10, AUC ROC

137
Q

What is precision and recall at k? ‍⭐️

A

Precision at k and recall at k are evaluation metrics for ranking algorithms. Precision at k shows the share of relevant items in the first k results of the ranking algorithm. And Recall at k indicates the share of relevant items returned in top k results out of all correct answers for a given query.

Example: For a search query “Car” there are 3 relevant products in your shop. Your search algorithm returns 2 of those relevant products in the first 5 search results. Precision at 5 = # num of relevant products in search result / k = 2/5 = 40% Recall at 5 = # num of relevant products in search result / # num of all relevant products = 2/3 = 66.6%

138
Q

What is mean average precision at k? ‍⭐️

A

APK is a measure of the average relevance scores of a set of the top-K documents presented in response to a query
In the APK metric, the order of the result set matters, in that the APK score would be higher if the result documents are both relevant and the relevant documents are presented higher in the results. It is, thus, a good metric for recommender systems

139
Q

What is a recommender system? 👶

A

Recommender systems are software tools and techniques that provide suggestions for items that are most likely of interest to a particular user.

140
Q

What are good baselines when building a recommender system? ‍⭐️

A

A good recommer system should give relevant and personalized information.
It should not recommend items the user knows well or finds easily.
It should make diverse suggestions.
A user should explore new items.

141
Q

What is collaborative filtering? ‍⭐️

A

Collaborative filtering is the most prominent approach to generate recommendations.
It uses the wisdom of the crowd, i.e. it gives recommendations based on the experience of others.
A recommendation is calculated as the average of other experiences.
Say we want to give a score that indicates how much user u will like an item i. Then we can calculate it with the experience of N other users U as r_ui = 1/N * sum(v in U) r_vi.
In order to rate similar experiences with a higher weight, we can introduce a similarity between users that we use as a multiplier for each rating.
Also, as users have an individual profile, one user may have an average rating much larger than another user, so we use normalization techniques (e.g. centering or Z-score normalization) to remove the users’ biases.
Collaborative filtering does only need a rating matrix as input and improves over time. However, it does not work well on sparse data, does not work for cold starts (see below) and usually tends to overfit.

142
Q

How we can incorporate implicit feedback (clicks, etc) into our recommender systems? ‍⭐️

A

In comparison to explicit feedback, implicit feedback datasets lack negative examples. For example, explicit feedback can be a positive or a negative rating, but implicit feedback may be the number of purchases or clicks. One popular approach to solve this problem is named weighted alternating least squares (wALS) [Hu, Y., Koren, Y., & Volinsky, C. (2008, December). Collaborative filtering for implicit feedback datasets. In Data Mining, 2008. ICDM’08. Eighth IEEE International Conference on (pp. 263-272). IEEE.]. Instead of modeling the rating matrix directly, the numbers (e.g. amount of clicks) describe the strength in observations of user actions. The model tries to find latent factors that can be used to predict the expected preference of a user for an item.

143
Q

What is the cold start problem? ‍⭐️

A

Collaborative filterung incorporates crowd knowledge to give recommendations for certain items. Say we want to recommend how much a user will like an item, we then will calculate the score using the recommendations of other users for this certain item. We can distinguish between two different ways of a cold start problem now. First, if there is a new item that has not been rated yet, we cannot give any recommendation. Also, when there is a new user, we cannot calculate a similarity to any other user.

144
Q

Possible approaches to solving the cold start problem? ‍⭐️🚀

A

Content-based filtering incorporates features about items to calculate a similarity between them. In this way, we can recommend items that have a high similarity to items that a user liked already. In this way, we are not dependant on the ratings of other users for a given item anymore and solve the cold start problem for new items.
Demographic filtering incorporates user profiles to calculate a similarity between them and solves the cold start problem for new users.

145
Q

What is a time series? 👶

A

A time series is a set of observations ordered in time usually collected at regular intervals.

146
Q

How is time series different from the usual regression problem? 👶

A

The principle behind causal forecasting is that the value that has to be predicted is dependant on the input features (causal factors). In time series forecasting, the to be predicted value is expected to follow a certain pattern over time.

147
Q

Which models do you know for solving time series problems? ‍⭐️

A

Simple Exponential Smoothing: approximate the time series with an exponentional function
Trend-Corrected Exponential Smoothing (Holt‘s Method): exponential smoothing that also models the trend
Trend- and Seasonality-Corrected Exponential Smoothing (Holt-Winter‘s Method): exponential smoothing that also models trend and seasonality
Time Series Decomposition: decomposed a time series into the four components trend, seasonal variation, cycling varation and irregular component
Autoregressive models: similar to multiple linear regression, except that the dependent variable y_t depends on its own previous values rather than other independent variables.
Deep learning approaches (RNN, LSTM, etc.)

148
Q

If there’s a trend in our series, how we can remove it? And why would we want to do it? ‍⭐️

A

We can explicitly model the trend (and/or seasonality) with approaches such as Holt’s Method or Holt-Winter’s Method. We want to explicitly model the trend to reach the stationarity property for the data. Many time series approaches require stationarity. Without stationarity,the interpretation of the results of these analyses is problematic [Manuca, Radu & Savit, Robert. (1996). Stationarity and nonstationarity in time series analysis. Physica D: Nonlinear Phenomena. 99. 134-161. 10.1016/S0167-2789(96)00139-X. ].

149
Q

You have a series with only one variable “y” measured at time t. How do predict “y” at time t+1? Which approaches would you use? ‍⭐️

A

We want to look at the correlation between different observations of y. This measure of correlation is called autocorrelation. Autoregressive models are multiple regression models where the time-lag series of the original time series are treated like multiple independent variables.

150
Q

You have a series with a variable “y” and a set of features. How do you predict “y” at t+1? Which approaches would you use? ‍⭐️

A

Given the assumption that the set of features gives a meaningful causation to y, a causal forecasting approach such as linear regression or multiple nonlinear regression might be useful. In case there is a lot of data and the explanability of the results is not a high priority, we can also consider deep learning approaches.

151
Q

What are the problems with using trees for solving time series problems? ‍⭐️

A

Random Forest models are not able to extrapolate time series data and understand increasing/decreasing trends. It will provide us with average data points if the validation data has values greater than the training data points.

152
Q

What is the Central Limit Theorem and why is it important?

A

if we sample from a
population using a sufficiently large sample size, the mean of the samples (also known as the sample
population) will be normally distributed (assuming true random sampling), the mean tending to the mean
of the population and variance equal to the variance of the population divided by the size of the sampling.
What’s especially important is that this will be true regardless of the distribution of the original
population.

153
Q

What is sampling?

A

Data sampling is a statistical analysis technique used to select, manipulate and analyze a representative
subset of data points to identify patterns and trends in the larger data set being examined

154
Q

What is the difference between type I vs type II error?

A

A type I error occurs when the null hypothesis is true but is rejected. A type II error occurs when the null
hypothesis is false but erroneously fails to be rejected.

155
Q

Which algorithms are low/High biased ?

A

Low bias machine learning algorithms — Decision Trees, k-NN and SVM
High bias machine learning algorithms — Linear Regression, Logistic Regression

156
Q

What is correlation and covariance in statistics?

A

Correlation measures how strongly two variables are
related.
Covariance is a measure that indicates the extent to which two random variables change in cycle

157
Q

What is the difference between Point Estimates and Confidence Interval?

A

Point Estimation gives us a particular value as an estimate of a population parameter
A confidence interval gives us a range of values which is likely to contain the population parameter.

158
Q

What is the goal of A/B Testing?

A

It is a hypothesis testing for a randomized experiment with two variables A and B.

159
Q

What is p-value?

A

When you perform a hypothesis test in statistics, a p-value can help you determine the strength of your
results. p-value is the minimum significance level at which you can reject the null hypothesis. The lower
the p-value, the more likely you reject the null hypothesis.

160
Q

Why is Re-sampling done?

A

The key idea is to resample form the original data — either directly or via a fitted model — to create
replicate datasets
* Bootstrap. Samples are drawn from the dataset with replacement (allowing the same sample to
appear more than once in the sample), where those instances not drawn into the data sample
may be used for the test set.
* k-fold Cross-Validation. A dataset is partitioned into k groups, where each group is given the
opportunity of being used as a held out test set leaving the remaining groups as the training set.
The k-fold cross-validation method specifically lends itself to use in the evaluation of predictive
models that are repeatedly trained on one subset of the data and evaluated on a second held-out
subset of the data.

161
Q

How to combat Overfitting and Underfitting?

A

To combat overfitting:
1. Add noise
2. Feature selection
3. Increase training set
4. L2 (ridge) or L1 (lasso) regularization; L1 drops weights, L2 no
5. Use cross-validation techniques, such as k folds cross-validation
6. Boosting and bagging
7. Dropout technique
8. Perform early stopping
9. Remove inner layers

To combat underfitting:
1. Add features
2. Increase time of training

162
Q

What Are Confounding Variables?

A

a confounder is a variable that influences both the dependent variable and independent
variable.

163
Q

What Are the Types of Biases That Can Occur During Sampling?

A

a. Selection bias
b. Under coverage bias
c. Survivorship bias

164
Q

What is Survivorship Bias?

A

It is the logical error of focusing aspects that support surviving some process and casually overlooking
those that did not work because of their lack of prominence.

165
Q

What is Selection Bias? What is under coverage bias?

A

Selection bias occurs when the sample obtained is not representative of the population intended to be
analyzed. For instance, you select only Asians to perform a study on the world population height.
Under coverage bias occurs when some members of the population are inadequately represented in the
sample.

166
Q

Why we generally use Soft-max (or sigmoid) non-linearity function as last
operation in-network? Why RELU in an inner layer?

A

It is because it takes in a vector of real numbers and returns a probability distribution.
RELU because it avoids the vanishing gradient descent issue.

167
Q

What are Eigenvectors and Eigenvalues?

A

we usually calculate the
eigenvectors for a correlation or covariance matrix. Eigenvectors are the directions along which a
particular linear transformation acts by flipping, compressing or stretching.
Eigenvalue can be referred to as the strength of the transformation in the direction of eigenvector or the
factor by which the compression occurs.

168
Q

Can you cite some examples where a false negative important than a false
positive? And vice versa?

A

Example 1 FN: What if Jury or judge decides to make a criminal go free?
Example 2 FN: Fraud detection.

169
Q

Can you cite some examples where both false positive and false negatives
are equally important?

A

In the Banking industry giving loans is the primary source of making money but at the same time if your
repayment rate is not good you will not make any profit, rather you will risk huge losses.
Banks don’t want to lose good customers and at the same point in time, they don’t want to acquire bad
customers. In this scenario, both the false positives and false negatives become very important to measure

170
Q

Can you explain the difference between a Validation Set and a Test Set?

A

A Training Set:
* to fit the parameters i.e. weights
A Validation set:
* part of the training set
* for parameter selection
* to avoid overfitting
A Test set:
* for testing or evaluating the performance of a trained machine learning model, i.e. evaluating the
predictive power and generalization.

171
Q

What is ‘Naive’ in a Naive Bayes?

A

Naive Bayes methods are a set of supervised learning algorithms based on applying Bayes’ theorem with
the “naive” assumption of conditional independence between every pair of features given the value of
the class variable.

172
Q

What is PCA? When do you use it?

A

Principal component analysis (PCA) is a statistical method used in Machine Learning. It consists in
projecting data in a higher dimensional space into a lower dimensional space by maximizing
the variance of each dimension.

173
Q

What are the most known ensemble algorithms?

A

The most popular trees are: AdaBoost, Random Forest, and eXtreme Gradient Boosting (XGBoost).

174
Q

What is pruning in Decision Tree?

A

Pruning is a technique in machine learning and search algorithms that reduces the size of decision trees
by removing sections of the tree that provide little power to classify instances.

175
Q

What is Collaborative filtering? And a content based?

A

Collaborative filtering is a technique
that can filter out items that a user might like on the basis of reactions by similar users. It works by
searching a large group of people and finding a smaller set of users with tastes similar to a particular user
In content based, we look only at the item level, recommending on similar items sold.

176
Q

What are the various steps involved in an analytics project?

A

The following are the various steps involved in an analytics project:
1. Understand the Business problem
2. Explore the data and become familiar with it
3. Prepare the data for modeling by detecting outliers, treating missing values, transforming
variables, etc.
4. After data preparation, start running the model, analyze the result and tweak the approach. This
is an iterative step until the best possible outcome is achieved.
5. Validate the model using a new data set.
6. Start implementing the model and track the result to analyze the performance of the model over
the period of time.

177
Q

During analysis, how do you treat missing values?

A

The extent of the missing values is identified after identifying the variables with missing values. If any
patterns are identified the analyst has to concentrate on them as it could lead to interesting and
meaningful business insights.
If there are no patterns identified, then the missing values can be substituted with mean or median values
(imputation) or they can simply be ignored. Assigning a default value which can be mean, minimum or
maximum value. Getting into the data is important.
If it is a categorical variable, the default value is assigned. The missing value is assigned a default value. If
you have a distribution of data coming, for normal distribution give the mean value.
If 80% of the values for a variable are missing, then you can answer that you would be dropping the
variable instead of treating the missing values.

178
Q

How will you define the number of clusters in a clustering algorithm?

A

Within Sum of squares is generally used to explain the homogeneity within a cluster. If you plot WSS (as
the sum of the squared distance between each member of the cluster and its centroid) for a range of
number of clusters, you will get the plot shown below.
* The Graph is generally known as Elbow Curve.
* Red circled a point in above graph i.e. Number of Cluster = 3 is the point after which you don’t see
any decrement in WSS.
* This point is known as the bending point and taken as K in K – Means

This is the widely used approach but few data scientists also use Hierarchical clustering first to create
dendrograms and identify the distinct groups from there.

179
Q

What is Ensemble Learning?

A

In statistics and machine learning, ensemble methods use multiple learning algorithms to obtain
better predictive performance than could be obtained from any of the constituent learning algorithms
alone.

180
Q

Describe in brief any type of Ensemble Learning

A

Bagging tries to implement similar learners on small sample populations and then takes a mean of all the
predictions. In generalized bagging, you can use different learners on different population. As you expect
this helps us to reduce the variance error

Boosting is an iterative technique which adjusts the weight of an observation based on the last
classification. If an observation was classified incorrectly, it tries to increase the weight of this observation
and vice versa. Boosting in general decreases the bias error and builds strong predictive models. However,
they may over fit on the training data.

181
Q

Pros/Cons of Bagging

A

Pros
Ø Bagging method helps when we face variance or overfitting in the model. It provides an
environment to deal with variance by using N learners of same size on same algorithm.
Ø During the sampling of train data, there are many observations which overlaps. So, the
combination of these learners helps in overcoming the high variance.
Ø Bagging uses Bootstrap sampling method (Bootstrapping is any test or metric that uses
random sampling with replacement and falls under the broader class of resampling methods.)
Cons
Ø Bagging is not helpful in case of bias or underfitting in the data.
Ø Bagging ignores the value with the highest and the lowest result which may have a wide difference
and provides an average result.

182
Q

Pros/Cons of Boosting

A

Pros
Ø Boosting technique takes care of the weightage of the higher accuracy sample and lower accuracy
sample and then gives the combined results.
Ø Net error is evaluated in each learning steps. It works good with interactions.
Ø Boosting technique helps when we are dealing with bias or underfitting in the data set.
Ø Multiple boosting techniques are available. For example: AdaBoost, LPBoost, XGBoost,
GradientBoost, BrownBoost
Cons
Ø Boosting technique often ignores overfitting or variance issues in the data set.
Ø It increases the complexity of the classification.
Ø Time and computation can be a bit expensive.

183
Q

What cross-validation technique would you use on a time series data set?

A

Instead of using k-fold cross-validation, you should be aware of the fact that a time series is not randomly
distributed data — It is inherently ordered by chronological order.
In case of time series data, you should use techniques like forward=chaining — Where you will be model
on past data then look at forward-facing data.

184
Q

What is a Box-Cox Transformation?

A

A Box-Cox transformation is a statistical technique to transform non-normal
dependent variables into a normal shape.

185
Q

How Regularly Must an Algorithm be Updated?

A

You will want to update an algorithm when:
* You want the model to evolve as data streams through infrastructure
* The underlying data source is changing
* There is a case of non-stationarity (mean, variance change over the time)
* The algorithm underperforms/results lack accuracy

186
Q

How Are Weights Initialized in a Network?

A

There are two methods here: we can either initialize the weights to zero or assign them randomly.

187
Q

What Is the Cost Function?

A

Also referred to as “loss” or “error,” cost function is a measure to evaluate how good your model’s
performance is. It’s used to compute the error of the output layer during backpropagation. We push that
error backwards through the neural network and use that during the different training functions.

188
Q

What Will Happen If the Learning Rate Is Set inaccurately

A

When your learning rate is too low, training of the model will progress very slowly as we are making
minimal updates to the weights. It will take many updates before reaching the minimum point.
If the learning rate is set too high, this causes undesirable divergent behavior to the loss function due to
drastic updates in weights. It may fail to converge

189
Q

What Is The Difference Between Epoch, Batch, and Iteration in Deep
Learning?

A

Epoch – Represents one iteration over the entire dataset (everything put into the training model).
* Batch – Refers to when we cannot pass the entire dataset into the neural network at once, so we
divide the dataset into several batches.
* Iteration – if we have 10,000 images as data and a batch size of 200. then an epoch should run 50
iterations (10,000 divided by 50).

190
Q

What Are the Different Layers on CNN?

A

There are four layers in CNN:
1. Convolutional Layer – the layer that performs a convolutional operation, creating several smaller
picture windows to go over the data.
2. Activation Layer (ReLU Layer) – it brings non-linearity to the network and converts all the negative
pixels to zero. The output is a rectified feature map. It follows each convolutional layer.
3. Pooling Layer – pooling is a down-sampling operation that reduces the dimensionality of the
feature map. Stride = how much you slide, and you get the max of the non matrix
4. Fully Connected Layer – this layer recognizes and classifies the objects in the image.

191
Q

What are Recurrent Neural Networks (RNNs)?

A

RNNs are a type of artificial neural networks designed to recognize the pattern from the sequence of data
such as Time series, stock market and government agencies etc.

192
Q

Encoder Decoder Sequence to Sequence RNNs

A

Encoder Decoder or Sequence to Sequence RNNs are used a lot in translation services. The basic idea is
that there are two RNNs, one an encoder that keeps updating its hidden state and produces a final single
“Context” output. This is then fed to the decoder, which translates this context to a sequence of outputs.

193
Q

How Does an LSTM Network Work?

A

Long-Short-Term Memory (LSTM) is a special kind of recurrent neural network capable of learning longterm
dependencies, remembering information for long periods as its default behavior. There are three
steps in an LSTM network:
* Step 1: The network decides what to forget and what to remember.
* Step 2: It selectively updates cell state values.
* Step 3: The network decides what part of the current state makes it to the output.

194
Q

Explain Gradient Descent.

A

The goal of the gradient descent is to minimize a given function which, in our case, is the loss function of
the neural network. To achieve this goal, it performs two steps iteratively.
1. Compute the slope (gradient) that is the first-order derivative of the function at the current point
2. Move-in the opposite direction of the slope increase from the current point by the computed
amount

195
Q

What is exploding gradients?

A

The explosion occurs through exponential growth by repeatedly multiplying gradients through the
network layers that have values larger than 1.0.

Solution: 3. Use Gradient Clipping: Exploding gradients can still occur in very deep Multilayer Perceptron
networks with a large batch size and LSTMs with very long input sequence lengths. If exploding
gradients are still occurring, you can check for and limit the size of gradients during the training
of your network. This is called gradient clipping. Specifically, the values of the error gradient are
checked against a threshold value and clipped or set to that threshold value if the error gradient
exceeds the threshold.

196
Q

What Is Dropout and Batch Normalization?

A

Dropout is a technique of dropping out hidden and visible nodes of a network randomly to prevent
overfitting of data (typically dropping 20 per cent of the nodes). It doubles the number of iterations
needed to converge the network. It used to avoid overfitting, as it increases the capacity of generalization.
Batch normalization is the technique to improve the performance and stability of neural networks by
normalizing the inputs in every layer so that they have mean output activation of zero and standard
deviation of one.