Common Data Science Interview Q&A

SALOME SONYA LOMSADZE
19 min readMar 12, 2023
Photo by Petr Sevcovic on Unsplash
  1. What is standard deviation, and how is it used in statistics?

Standard deviation is a measure of the variability or dispersion of a dataset. It tells us how much the individual data points deviate from the mean or average value of the dataset. A low standard deviation indicates that the data points are clustered around the mean, while a high standard deviation indicates that the data points are spread out from the mean.

In statistics, the standard deviation is commonly used as a measure of the uncertainty or variability in a sample or population. It is often used in conjunction with the mean to describe the shape and spread of a distribution. It is also used in hypothesis testing, where it is used to calculate the z-score or t-score of a sample or population, which is then used to test whether the sample or population is significantly different from a known value or another sample/population.

2. How standard deviation change when the mean changes?

Suppose we have a dataset of the heights of 10 people, and the mean height is 170 cm with a standard deviation of 5 cm. This means that the heights of the 10 people are spread out around the mean height of 170 cm, with most people falling within a range of plus or minus 5 cm from the mean.

Now, let’s say we add a new person to the dataset who is 190 cm tall. The new mean height of the 11 people is now (10*170 + 190)/11 = 172.7 cm. Notice that the mean height has increased due to the addition of the tall person.

However, the standard deviation has also increased as a result. This is because the range of heights in the dataset has expanded, and the data points are now more spread out from the new mean height of 172.7 cm. If we recalculate the standard deviation using the new mean height, we get:

√[1/11 * (10*(170–172.7)² + (190–172.7)²)] ≈ 9.4 cm

So, by adding the tall person to the dataset, we have increased both the mean height and the standard deviation of the dataset.

3. What is regularization, and why is it important in machine learning?

Regularization is a technique used in machine learning to prevent overfitting and improve the generalization performance of models. Overfitting occurs when a model fits too well to the training data and captures the noise or random variations instead of the underlying patterns. Regularization helps to address this issue by adding a penalty term to the loss function that the model optimizes during training.

There are several types of regularization techniques, including L1 regularization (also known as Lasso), L2 regularization (also known as Ridge), and dropout regularization. L1 regularization encourages the model to select only a subset of the most important features by adding a penalty proportional to the absolute value of the coefficients. L2 regularization, on the other hand, adds a penalty proportional to the square of the coefficients, which encourages the model to spread the weights across all features.

Dropout regularization randomly drops out some neurons during training to prevent them from relying too heavily on a few specific features. This technique forces the network to learn a more robust and generalized representation of the input data.

Regularization is important in machine learning because it helps to prevent overfitting, which is a common problem when training complex models with large datasets. Regularization allows models to generalize better to new, unseen data, improving their overall performance and reliability.

4. What is cross-validation, and why is it useful in machine learning?

Cross-validation is a technique used in machine learning to evaluate the performance of a model on a dataset. The basic idea behind cross-validation is to divide the dataset into multiple subsets or “folds” and use each fold as both a training set and a validation set. The model is trained on the training set, and its performance is evaluated on the validation set. This process is repeated for each fold, and the results are averaged to obtain a final performance estimate.

The most commonly used type of cross-validation is k-fold cross-validation, where the dataset is divided into k equal-sized folds, and each fold is used as the validation set once, while the other k-1 folds are used for training. The process is repeated k times, and the results are averaged to obtain a final performance estimate.

Cross-validation is useful in machine learning for several reasons. First, it allows us to estimate the performance of a model more accurately than simply training and testing on the same dataset, as it provides a more comprehensive evaluation of the model’s ability to generalize to new data. Second, it helps to detect overfitting, which occurs when a model is too complex and captures noise or random variations in the training data. Cross-validation can help us to identify when a model is overfitting and adjust its complexity accordingly.

In addition, cross-validation can help us to compare the performance of different models or hyperparameters and select the best one for a given task. Finally, cross-validation is useful in situations where the dataset is small or imbalanced, as it allows us to make better use of the available data and reduce the risk of biased estimates.

5. How do you evaluate the performance of a machine learning model?

There are several ways to evaluate the performance of a machine learning model, depending on the type of problem and the specific requirements of the task. Here are some of the most commonly used evaluation metrics:

  1. Accuracy: This is the most basic and widely used metric for classification problems. It measures the percentage of correctly classified samples out of the total number of samples.
  2. Precision and Recall: These are two complementary metrics used in binary classification problems. Precision measures the proportion of true positive predictions out of all positive predictions, while recall measures the proportion of true positive predictions out of all actual positive samples.
  3. F1 score: This is the harmonic mean of precision and recall, and it provides a balanced measure of both metrics. It is often used when both precision and recall are important, such as in imbalanced datasets.
  4. Mean Absolute Error (MAE) and Mean Squared Error (MSE): These are common metrics used for regression problems. MAE measures the average absolute difference between the predicted and actual values, while MSE measures the average squared difference between the predicted and actual values.
  5. R-squared (R2): This is another metric used for regression problems, which measures the proportion of variance in the target variable that is explained by the model.

In addition to these metrics, there are other specialized evaluation techniques that can be used for specific tasks, such as the area under the Receiver Operating Characteristic (ROC) curve for binary classification with imbalanced datasets, or the mean average precision (MAP) for information retrieval tasks.

It is important to choose the appropriate evaluation metric(s) based on the specific requirements and goals of the task and to carefully interpret and report the results to ensure that they are meaningful and useful. Furthermore, cross-validation can be used to provide a more accurate and robust estimate of the model’s performance, by evaluating it on multiple test sets.

Note: However, it is important to note that accuracy may not always be the best metric to use, especially in imbalanced datasets where one class is much more prevalent than the other. In such cases, a model that always predicts the majority class may achieve a high accuracy, but may not be useful in practice. In such cases, other metrics such as precision, recall, or F1 score may provide a more meaningful evaluation of the model’s performance.

6. Can you explain the precision metric with example?

Certainly! Precision is a metric used to evaluate the performance of a machine learning model in binary classification problems. It measures the proportion of true positive predictions out of all positive predictions. Here’s an example to illustrate how precision is calculated:

Suppose we have a binary classification problem where we want to predict whether an email is spam or not based on its content. We have a dataset of 1000 emails, where 900 are not spam (i.e., ham) and 100 are spam. We train a model on this data and obtain the following results:

  • Out of 100 emails predicted as spam, 80 are actually spam (true positives), and 20 are not spam (false positives).
  • Out of 900 emails predicted as not spam, 880 are actually not spam (true negatives), and 20 are spam (false negatives).

To calculate the precision of the model, we focus on the positive predictions (i.e., the emails predicted as spam). The precision is the ratio of true positive predictions to all positive predictions:

Precision = true positives / (true positives + false positives) = 80 / (80 + 20) = 0.8

So the precision of the model is 80%, which means that out of all the emails predicted as spam, 80% of them were actually spam.

In other words, precision tells us how many of the emails that were classified as spam by the model were actually spam, and how many were false positives. A high precision means that the model is good at identifying spam emails and has a low rate of false positives.

However, it is important to note that precision may not always be the best metric to use, especially in imbalanced datasets where one class is much more prevalent than the other. In such cases, other metrics such as recall, F1 score, or area under the ROC curve (AUC-ROC) may provide a more meaningful evaluation of the model’s performance.

7. Can you distinguish recall and precision in a simple way?

Yes, I can explain the difference between recall and precision in a simple way.

Recall and precision are two important metrics used in binary classification problems to evaluate the performance of a machine learning model.

Recall, also known as sensitivity, measures the proportion of true positive predictions out of all actual positive samples in the dataset. In other words, recall tells us how many of the actual positive samples in the dataset were correctly identified as positive by the model.

Precision, on the other hand, measures the proportion of true positive predictions out of all predicted positive samples in the dataset. In other words, precision tells us how many of the predicted positive samples in the dataset were actually positive.

To put it simply, recall is focused on finding all the positive samples in the dataset, while precision is focused on finding only the relevant positive samples in the dataset.

To illustrate this, let’s consider a binary classification problem where we want to identify all the patients with a certain disease. In this case:

  • Recall would measure how many of the actual patients with the disease were correctly identified as positive by the model.
  • Precision would measure how many of the predicted positive patients actually have the disease.

So, high recall means that the model is good at finding all the positive samples in the dataset, while high precision means that the model is good at identifying only the relevant positive samples in the dataset.

In summary, recall is about finding all the relevant positive samples, while precision is about finding only the relevant positive samples. Both metrics are important, and the choice of which one to use depends on the specific problem and the trade-offs between false positives and false negatives.

8. Can you explain the F1 score simply?

The F1 score is a metric used in binary classification problems to evaluate the overall performance of a machine learning model. It is a harmonic mean of precision and recall, which means it takes into account both false positives and false negatives.

To calculate the F1 score, we use the following formula:

F1 score = 2 * (precision * recall) / (precision + recall)

where precision and recall are calculated as follows:

precision = true positives / (true positives + false positives)

recall = true positives / (true positives + false negatives)

The F1 score is a single value between 0 and 1, where a score of 1 indicates perfect precision and recall, and a score of 0 indicates the worst possible performance.

In simple terms, the F1 score tells us how well the model balances precision and recall. A high F1 score means that the model has good precision and recall, which means it is good at both finding all the positive samples in the dataset (recall) and identifying only the relevant positive samples (precision).

To illustrate this, let’s consider a binary classification problem where we want to predict whether an email is spam or not. In this case, a high F1 score means that the model is good at identifying all the spam emails in the dataset (recall) while minimizing the false positives (precision).

In summary, the F1 score is a useful metric for evaluating the overall performance of a machine learning model in binary classification problems, taking into account both precision and recall.

9. Can you explain the roc score simply?

ROC (Receiver Operating Characteristic) score is a performance metric commonly used to evaluate binary classification models, which predict one of two possible outcomes (e.g., positive or negative, true or false, etc.).

The ROC curve plots the true positive rate (TPR) against the false positive rate (FPR) at different classification thresholds. The TPR is the proportion of actual positives that are correctly classified as positive, while the FPR is the proportion of actual negatives that are incorrectly classified as positive.

The area under the ROC curve (AUC) is a measure of how well the model is able to distinguish between the two classes. An AUC score of 1 means that the model has perfect discrimination ability, while an AUC score of 0.5 indicates that the model is no better than random guessing.

In summary, the ROC score is a way to evaluate the performance of a binary classification model by analyzing its ability to distinguish between positive and negative classes. The higher the AUC score, the better the model is at correctly classifying the instances.

10. What is overfitting, and how can it be avoided in machine learning?

Overfitting is a common problem in machine learning where a model is too complex and captures noise and random fluctuations in the data, rather than the underlying patterns. In other words, the model is too closely fit to the training data, and as a result, it performs poorly on new, unseen data.

There are several ways to avoid overfitting in machine learning:

  1. Use more data: One way to reduce overfitting is to use more data for training the model. The more data you have, the less likely the model is to fit noise or random fluctuations in the data.
  2. Feature selection: Feature selection is the process of selecting only the most relevant features (i.e., variables) for training the model. By reducing the number of features, you can reduce the complexity of the model and prevent overfitting.
  3. Regularization: Regularization is a technique that adds a penalty term to the loss function of the model to discourage overfitting. There are several types of regularization, including L1 regularization (Lasso), L2 regularization (Ridge), and Elastic Net regularization.
  4. Cross-validation: Cross-validation is a technique that involves splitting the data into multiple subsets and using each subset for both training and testing the model. By testing the model on different subsets, you can get a better estimate of how well the model will perform on new, unseen data.
  5. Early stopping: Early stopping is a technique that involves stopping the training process of the model before it becomes overfit. This is done by monitoring the performance of the model on a validation set and stopping the training process when the performance starts to decrease.

Overall, overfitting can be avoided by using techniques such as feature selection, regularization, cross-validation, and early stopping. These techniques help to reduce the complexity of the model and ensure that it generalizes well to new, unseen data.

11. What is the curse of dimensionality, and how does it affect machine learning?

The curse of dimensionality refers to the phenomenon in which the performance of machine learning algorithms decreases as the number of features (dimensions) in the data increases. In other words, as the number of features in the data grows, the amount of data needed to generalize accurately grows exponentially, which can make machine learning algorithms less effective.

The curse of dimensionality can affect machine learning in several ways:

  1. Increased computation time: As the number of dimensions increases, the number of calculations required to process the data increases exponentially. This can make it difficult to train models on large datasets with high-dimensional feature spaces.
  2. Sparsity of data: As the number of dimensions increases, the amount of data required to cover the feature space increases exponentially. This can lead to sparsity of data, which means that there are fewer data points available to train the model for each possible combination of features.
  3. Overfitting: As the number of dimensions increases, the likelihood of overfitting the model to noise in the data also increases. This can lead to poor generalization performance on new, unseen data.

To address the curse of dimensionality in machine learning, it is often necessary to use feature selection techniques to reduce the number of dimensions in the data. This can help to reduce sparsity, improve computation time, and reduce the risk of overfitting. Additionally, techniques such as principal component analysis (PCA) and linear discriminant analysis (LDA) can be used to reduce the dimensionality of the data while preserving the most relevant information.

12. Explain PCA simply?

PCA is a popular dimensionality reduction technique used in machine learning and data analysis. The goal of PCA is to find the most important features (or combinations of features) in the data and create a smaller set of new features, called principal components, that capture as much of the original variation as possible.

The steps involved in PCA are:

  1. Standardize the data: PCA requires the data to be standardized, meaning that each feature has a mean of zero and a standard deviation of one.
  2. Compute the covariance matrix: The covariance matrix describes the relationship between pairs of features in the data.
  3. Compute the eigenvectors and eigenvalues of the covariance matrix: The eigenvectors represent the directions in which the data varies the most, while the eigenvalues represent the amount of variance explained by each eigenvector.
  4. Select the principal components: The principal components are the eigenvectors that explain the most variance in the data. Typically, the top k eigenvectors with the largest eigenvalues are selected to create the new feature space.
  5. Transform the data: The original data can be transformed into the new feature space by multiplying it by the matrix of selected eigenvectors.

By using PCA, you can reduce the number of features in the data while preserving the most important information. This can help to reduce the dimensionality of the data, improve computation time, and reduce the risk of overfitting in machine learning models.

13. Difference between covariance and correlation matrix?

Covariance and correlation matrices are both used to measure the relationships between features in a dataset, but they differ in their scale and interpretation.

Covariance is a measure of how two variables vary together. A positive covariance indicates that the variables tend to increase or decrease together, while a negative covariance indicates that the variables tend to move in opposite directions. The magnitude of the covariance depends on the scale of the variables, making it difficult to compare the covariances of variables measured on different scales.

Correlation, on the other hand, is a standardized measure of the relationship between two variables. It ranges from -1 to 1, where a correlation of 1 indicates a perfect positive relationship, a correlation of -1 indicates a perfect negative relationship, and a correlation of 0 indicates no relationship. Correlation is independent of the scale of the variables, making it easier to compare the relationships between variables measured on different scales.

To compute a correlation matrix, the data is first standardized by subtracting the mean and dividing it by the standard deviation for each feature. Then, the correlation between each pair of features is computed. The resulting matrix contains the correlation coefficients between each pair of features.

In summary, the main difference between covariance and correlation matrices is that covariance measures the degree to which two variables vary together, while correlation measures the strength and direction of the relationship between two variables, normalized to a common scale.

14. What is clustering, and what are some common techniques used in clustering?

Clustering is a type of unsupervised learning in machine learning, where the goal is to group similar objects together based on the similarity of their features or characteristics. The aim of clustering is to identify natural groups or clusters in the data, without any prior knowledge of their labels or categories.

There are various techniques used in clustering, some of the most common ones include:

  1. K-means clustering: In K-means clustering, the data is partitioned into K clusters, where K is a user-defined parameter. The algorithm starts by randomly selecting K points as initial cluster centroids and assigns each data point to the nearest centroid. The algorithm then iteratively updates the centroids and reassigns the data points until convergence is reached.
  2. Hierarchical clustering: Hierarchical clustering is a type of clustering that creates a hierarchy of clusters by iteratively merging or dividing clusters based on their similarity. It can be either agglomerative (bottom-up) or divisive (top-down).

These are just a few examples of the many clustering techniques available in machine learning. The choice of clustering technique depends on the nature of the data and the problem at hand.

14. What are clustering use cases?

Clustering has many use cases across various industries and domains. Some common applications of clustering include:

  1. Market segmentation: Clustering can be used to group customers based on their purchasing behavior, demographics, or other characteristics, which can help companies to better understand their target audience and tailor their marketing strategies accordingly.
  2. Image segmentation: Clustering can be used to segment images into regions with similar features, which is useful in computer vision applications such as object recognition and tracking.
  3. Anomaly detection: Clustering can be used to identify outliers or anomalies in datasets, which can help to detect fraud or other unusual activity.
  4. Recommendation systems: Clustering can be used to group similar items or products together, which can be used to make personalized recommendations to users based on their preferences.
  5. Genomic data analysis: Clustering can be used to group genes with similar expression patterns, which can help to identify gene networks and pathways involved in disease processes.
  6. Social network analysis: Clustering can be used to identify communities or groups within social networks, which can provide insights into social structures and interactions.

These are just a few examples of the many applications of clustering. In general, clustering is useful in any situation where there is a need to group similar objects or identify patterns in data.

15. What is feature selection, and why is it important in machine learning?

Feature selection is the process of identifying and selecting the most relevant and useful features from a dataset for use in a machine learning model. It involves identifying the most important variables or attributes that contribute to the outcome of a particular problem or task while discarding irrelevant, redundant, or noisy features.

The main objective of feature selection is to improve the performance of machine learning models by reducing the dimensionality of the dataset, decreasing the risk of overfitting, and increasing the model’s interpretability and generalization ability. By selecting the most informative features, the model can focus on the most relevant information, leading to faster and more accurate predictions, better model performance, and improved understanding of the underlying relationships between the variables.

There are several methods for feature selection, including filter methods, wrapper methods, and embedded methods, each with its own advantages and disadvantages. It is important to carefully choose the appropriate method based on the dataset and the specific problem being addressed.

Overall, feature selection is a critical step in the machine learning pipeline, as it helps to improve the accuracy, efficiency, and interpretability of the models, making them more suitable for real-world applications.

16. What are common feature selection techniques?

There are several techniques for feature selection, and the choice of technique depends on the specific problem, the dataset, and the machine learning algorithm used. Here are some common techniques for feature selection:

  1. Filter methods: These methods rely on statistical measures to rank the features based on their relevance to the target variable. Examples include correlation-based feature selection (CFS), mutual information, chi-square test, and variance threshold.
  2. Wrapper methods: These methods use a specific machine learning algorithm to evaluate the importance of the features. Examples include recursive feature elimination (RFE), forward selection, and backward elimination.
  3. Embedded methods: These methods perform feature selection during the model training process. Examples include LASSO (Least Absolute Shrinkage and Selection Operator), ridge regression, and decision tree-based methods such as CART (Classification and Regression Trees), Random Forest, and XGBoost.
  4. Dimensionality reduction techniques: These methods transform the original feature space into a lower-dimensional space while retaining the most important features. Examples include principal component analysis (PCA), singular value decomposition (SVD), and linear discriminant analysis (LDA).
  5. Domain knowledge-based methods: These methods rely on the expertise of domain experts to identify the most relevant features based on their knowledge of the problem domain.

It is important to note that feature selection is not a one-size-fits-all solution, and the choice of technique depends on the specific problem and the nature of the dataset. It is also important to evaluate the impact of feature selection on the model’s performance and interpretability.

17. Feature selection techniques in xgboost, lgbm?

XGBoost (Extreme Gradient Boosting) and LightGBM (Light Gradient Boosting Machine) are popular machine learning algorithms that use gradient boosting to improve model performance. Both algorithms have built-in feature selection capabilities that can be used to identify the most important features of the model. Here are some feature selection techniques that are specific to XGBoost and LightGBM:

  1. Importance scores: XGBoost and LightGBM calculate feature importance scores based on the number of times a feature is used in splitting the data and the reduction in the loss function. Features with higher importance scores are considered more important and can be selected for use in the model.
  2. Early stopping: Both XGBoost and LightGBM have early stopping capabilities that can be used to identify the optimal number of features. The algorithms monitor the model’s performance on a validation set during the training process and stop the training when the model’s performance stops improving.
  3. Shap values: XGBoost has built-in support for computing Shapley values, which can be used to explain the contribution of each feature to the final prediction. This can be used to identify the most important features and remove irrelevant or redundant features.
  4. Regularization: Both XGBoost and LightGBM have built-in regularization techniques such as L1 and L2 regularization that can be used to penalize the model for using too many features. This encourages the model to use only the most important features.

It is important to note that the effectiveness of these techniques depends on the specific problem and the nature of the dataset. It is recommended to experiment with different techniques and evaluate their impact on the model’s performance and interpretability.

18. What is time series analysis, and what are some common techniques used in time series analysis?

Time series analysis is a statistical technique used to analyze and model data that is collected over time. Time series data is a sequence of measurements or observations taken at fixed time intervals. Examples of time series data include stock prices, weather data, traffic flow data, and sensor data.

The goal of time series analysis is to understand the underlying patterns and trends in the data, and to make predictions about future values based on past observations. Common techniques used in time series analysis include:

  1. Trend analysis: This involves identifying the long-term upward or downward movement in the data. Techniques for trend analysis include moving averages, linear regression, and exponential smoothing.
  2. Seasonal analysis: This involves identifying seasonal patterns or periodic fluctuations in the data. Techniques for seasonal analysis include seasonal decomposition, Fourier analysis, and seasonal autoregressive integrated moving average (SARIMA) models.
  3. Stationarity analysis: Stationarity is a property of time series data where the statistical properties of the data remain constant over time. Techniques for stationarity analysis include differencing, autocorrelation and partial autocorrelation analysis, and unit root tests.
  4. Forecasting: This involves predicting future values of the time series based on past observations. Techniques for forecasting include exponential smoothing, ARIMA (autoregressive integrated moving average) models, and machine learning algorithms such as neural networks and support vector regression.
  5. Time series clustering: This involves grouping similar time series data together based on their statistical properties. Techniques for time series clustering include dynamic time warping, k-means clustering, and hierarchical clustering.
  6. Anomaly detection: This involves identifying unusual or abnormal patterns in the time series data. Techniques for anomaly detection include statistical methods such as z-score and box plot analysis and machine learning algorithms such as isolation forest and autoencoder-based methods.

Time series analysis is widely used in many applications such as finance, economics, engineering, and healthcare, among others. The choice of technique depends on the nature of the data and the specific problem being addressed.

--

--

SALOME SONYA LOMSADZE

Sr. Customer Analytics , BI Developer, Experienced in SQL, Python, Qlik, B.Sc in Chemistry at Bogazici University https://github.com/sonyalomsadze