Technical Interview Questions for Data Science

In Data Science interviews, technical questions are designed to assess your fundamentals of working with data and your understanding of using Data Science concepts in a given problem. If you want to understand what types of questions are asked in a technical interview for a Data Science job, this article is for you. In this article, I’ll take you through a list of technical interview questions for Data Science.

Technical Interview Questions for Data Science

Let’s go through some of the technical interview questions for Data Science that can assess your fundamentals of working with data.

How do you deal with missing data in a dataset?

Dealing with missing data in a dataset is a crucial step in data preprocessing, as missing values can adversely affect the quality and accuracy of analytical models. There are several strategies to handle missing data in a dataset. 

Suppose we have a dataset containing data about customers, including their age, income, and purchase history. Some rows in the dataset have missing values for the income and age attributes. Let’s understand how we can fill in missing values in this case:

  1. Imputation: One common approach is to impute missing values with some statistic, such as the mean or median of the non-missing values in the same column. It helps preserve the overall distribution of the data.
  2. Deletion: In some cases, you may choose to remove rows with missing data. It is a valid strategy when the amount of missing data is relatively small and won’t significantly impact the analysis.
How to choose between mean, median, and mode to fill in missing values?

Choosing between mean, median, and mode to fill in missing values in a dataset is a critical decision in data preprocessing. Here are some considerations to choose mean, median, or mode to fill in missing values:

  • Use the mean when dealing with continuous, numeric data, such as age or income.
  • Use the median when the data is skewed, has outliers, or is not normally distributed.
  • Use the mode for categorical data, such as color preferences or product categories.
Why Logistic Regression is used for classification problems instead of regression analysis?

Logistic regression is commonly used in classification problems because it allows us to model the probability of a binary outcome based on a set of variables. Suppose a credit card company wants to build a model to predict whether a customer is likely to default on their credit card payments. The company has historical data on a sample of customers, including their demographic information, credit history, and purchasing habits. The goal is to create a model that can accurately predict whether a new customer is likely to default on their payments or not.

To solve this problem, the credit card company can use a logistic regression algorithm to build a binary classification model. In this problem, the binary outcome variable would be 1 for default, and 0 for no default. And the variables/features would include the customer’s demographic information and credit history. 

In this problem, the logistic regression model will estimate the probability that a customer is likely to default on their credit card payments based on their demographic information and credit history. The model would then use a decision threshold (eg, 0.5) to classify each customer as likely to default or not likely to default.

What is P-value, and how it is used in hypothesis testing?

The p-value is a way to tell if something you’re looking at in your data is really important or just random luck. It’s like looking for clues to solve a mystery. If you find a clue that is very rare and unlikely to happen by accident, it is more likely to be a real clue that helps solve the mystery. The p-value helps Data Scientists determine if their results are significant or if they happened by chance.

Let’s Understand what is p-value and how it is used for hypothesis testing by taking an example of comparing two medical treatments. Suppose a new medical treatment has been developed for a disease. A pharmaceutical company wants to test whether the new treatment is effective compared to the existing treatment. They randomly select a group of patients with the disease and divide them into two groups:

  • one group receives the new treatment
  • while the other group receives the existing treatment

After a certain time, the company measures the improvement in the health status of patients in both groups. They want to know if the new treatment results in a statistically significant improvement over the existing treatment. To answer this question, they will use a statistical method called hypothesis testing. The null hypothesis is that there is no difference between the two treatments, and any observed difference is due to chance. The alternative hypothesis is that there is a significant difference between the two treatments.

The p-value is a measure of the strength of evidence against the null hypothesis. It represents the probability of obtaining a test statistic that is as extreme or more extreme than the observed test statistic, assuming the null hypothesis is true.

Suppose the calculated p-value is 0.03. It means there is a 3% chance of observing the difference in health improvement between the two groups, assuming no difference between the treatments. Generally, a p-value of less than 0.05 is considered statistically significant, which means there is strong evidence against the null hypothesis and suggests there is a significant difference between the treatments.

Explain the naive assumption in the Naive Bayes algorithm and why it is called “naive”.

Suppose you want to predict whether a person will buy a car based on their age and income. You have data about people who have bought cars in the past, and you know that younger people with higher incomes tend to buy more cars. Now, the “naive” assumption of the Naive Bayes algorithm in this example is that a person’s age and income are entirely independent, meaning they don’t affect each other.

Thus, the Naive Bayes algorithm treats age and income as unrelated, and it does not consider that sometimes older people can also have high incomes or that young people may not have much money. It’s called “naive” because it’s a simplified assumption that may not always be true in real-world business problems.

Despite this simplifying assumption, the Naive Bayes algorithm can still be useful in some situations where the feature independence assumption is reasonable, and it can provide valuable predictions about many real-world business problems.

Explain how Content based filtering and Collaborative filtering are different?

Content-based filtering is like recommending content based on the content of the movies you like. Collaborative filtering is like recommending content based on what other people with similar preferences have liked.

For example, if a user has previously searched for and purchased running shoes, Amazon’s content-based filtering algorithm will analyze attributes of those shoes, such as brand, size, colour, and style, and will recommend similar running shoes based on these attributes.

Amazon’s collaborative filtering algorithm would analyze the purchase history, browsing behaviour and product ratings of other users with similar interests or shopping habits as the target user. Based on this information, the algorithm will recommend products that similar users have liked or bought, even if the target user has never interacted with these products before.

Thus, content-based filtering helps to identify products with similar attributes or content, while collaborative filtering helps to identify products that are popular or liked by users with similar interests.

What is ROC and AUC, and how these help?
AUC and ROC curve

The ROC (Receiver Operating Characteristic) curve is created by plotting the true positive rate (TPR) against the false positive rate (FPR) at various threshold settings.

AUC (Area Under the Curve) is a metric that quantifies the overall performance of a classification model based on the ROC curve. It measures the area under the ROC curve, which ranges from 0 to 1.

The ROC curve and AUC score help us measure how good a machine learning model is at doing its job, like telling us whether an email is a spam or not.

The ROC curve as close to the top left corner of the graph as possible, and the AUC score as close to 1 as possible means the model is doing a good job.

Suppose you are working on a problem where you need to forecast the future traffic of a website for the next quarter using Time Series Forecasting. How will you choose the right algorithm? What factors you will look for to choose the best algorithm?

Selecting the most appropriate algorithm for website traffic prediction will depend on several factors, including the size and complexity of the data set, the frequency of the data, and the forecast horizon.

Additionally, characteristics of the data, such as seasonality, trend, and cyclicality, should be considered when selecting the algorithm. Let’s go through time series forecasting algorithms to understand when to use which algorithm:

  1. ARIMA & SARIMA: ARIMA (Autoregressive Integrated Moving Average) is a commonly used algorithm for time series forecasting, especially for stationary data with no trend or seasonality. On the other hand, SARIMA (Seasonal Autoregressive Integrated Moving Average) is well suited to data with seasonality patterns.
  2. LSTM: LSTM (Long Short-Term Memory) is a type of neural network that can be used for time series forecasting. LSTM is able to handle complex sequential models and can be trained on large data sets. It is especially useful for data with long-term dependencies and nonlinear relationships between variables.
Why evaluating the performance of an unsupervised machine learning model is a challenge compared to supervised machine learning models?
  1. Absence of labels: Unsupervised learning models do not rely on labelled data that contains predefined target values. In contrast, supervised learning models learn from labelled data, where each instance is associated with a known target value. This absence of labelled data in unsupervised learning makes it difficult to assess the accuracy or correctness of the model’s predictions.
  2. Requires Domain Expertise: Evaluation of unsupervised learning models often requires leveraging external knowledge or input from experts. Domain experts can provide insight into expected patterns, relationships, or structures in the data. This external knowledge can help validate and evaluate model performance, but it introduces an additional layer of subjectivity and reliance on domain expertise.
Explain what n_estimators and random_state mean in this line of code: RandomForestClassifier(n_estimators=100, random_state=42).
  1. n_estimators: The n_estimators parameter specifies the number of decision trees to include in the random forest. Increasing the number of estimators can improve model performance, but it also increases computational complexity and training time. The optimal value for n_estimators depends on the dataset and can be determined by experimentation.
  2. random_state: The random_state parameter is used to set the random seed for reproducibility. Random forests involve randomness, such as training data sampling and feature selection, which can lead to different model results each time it is run. By setting a random seed, we ensure that the same results can be reproduced if the code is run multiple times with the same seed value.

So these were some of the technical interview questions for Data science you should know. I hope this list of questions was helpful to understand what type of questions are asked in technical interviews for Data science.


In Data Science interviews, technical questions are designed to assess your fundamentals of working with data and your understanding of using Data Science in a given problem. I hope you liked this article on technical interview questions for Data Science. Feel free to ask valuable questions in the comments section below.

Aman Kharwal
Aman Kharwal

I'm a writer and data scientist on a mission to educate others about the incredible power of data📈.

Articles: 1498

Leave a Reply