Data Science with Python Certification — Questions and Answers
Question 1: What does the confusion matrix entry at position [1][0] represent in binary classification?
- True Negatives
- True Positives
- False Positives
- False Negatives (Correct answer)
Correct answer: False Negatives
In a confusion matrix indexed as [actual][predicted], position [1][0] means actual positive (1) predicted as negative (0) — a false negative.
Question 2: Which Matplotlib method changes the x-axis tick labels?
- ax.set_xticks()
- ax.xtick_labels()
- ax.xlabel()
- ax.set_xticklabels() (Correct answer)
Correct answer: ax.set_xticklabels()
ax.set_xticklabels() sets the text labels for the x-axis tick marks.
Question 3: In Python, the pass statement is utilized for
- Do nothing
- Jump to loop condition check
- Jump out of the loop
- Jump to loop's else block (Correct answer)
Correct answer: Jump to loop's else block
The pass statement is a null operation: it does nothing and is used as a placeholder where syntax requires a statement but no action is wanted. It does not jump to a loop's else block, recheck the condition, or break out — those are the jobs of normal flow, continue, and break. ⚠ The correct answer is 'Do nothing'; the stored key is wrong.
Question 4: What does the PACF (Partial Autocorrelation Function) help determine in ARIMA modeling?
- The MA (q) order
- The seasonal period
- The AR (p) order (Correct answer)
- The differencing (d) order
Correct answer: The AR (p) order
PACF shows the direct correlation between a series and each lag after removing intermediate lag effects, identifying the AR (p) order.
Question 5: What is the interquartile range (IQR) commonly used for in data science?
- Identifying the most frequent value
- Measuring the average of the dataset
- Measuring the spread of the middle 50% of data (Correct answer)
- Computing the correlation coefficient
Correct answer: Measuring the spread of the middle 50% of data
IQR is the difference between Q3 and Q1, capturing the spread of the central 50% of data and is used for outlier detection.
Question 6: What does df.pivot_table() primarily allow you to do in pandas?
- Merge two DataFrames on a key
- Summarize data by grouping and applying aggregation functions across two dimensions (Correct answer)
- Sort a DataFrame by multiple columns
- Transpose all rows and columns
Correct answer: Summarize data by grouping and applying aggregation functions across two dimensions
pivot_table creates a spreadsheet-style pivot table that aggregates data across rows and columns defined by index and column parameters.
Question 7: What does the 'recall' (sensitivity) metric specifically measure in binary classification?
- Fraction of predicted positives that are true positives
- Fraction of all predictions that are correct
- Fraction of actual positives that were correctly identified (Correct answer)
- Fraction of true negatives among all negatives
Correct answer: Fraction of actual positives that were correctly identified
Recall = TP / (TP + FN), measuring how well the model finds all actual positive cases in the dataset.
Question 8: Which test is used to check for stationarity in a time series?
- Augmented Dickey-Fuller test (Correct answer)
- Mann-Whitney U test
- Levene's test
- Shapiro-Wilk test
Correct answer: Augmented Dickey-Fuller test
The Augmented Dickey-Fuller (ADF) test checks for a unit root; a low p-value indicates the series is stationary.
Question 9: What does the .str.contains() method return when applied to a pandas Series?
- A boolean Series indicating pattern matches (Correct answer)
- The count of matches per element
- A list of matching substrings
- A filtered DataFrame with matching rows
Correct answer: A boolean Series indicating pattern matches
.str.contains() returns a boolean Series that is True where the pattern is found.
Question 10: Which NumPy function can be used to split an array into multiple sub-arrays along an axis?
- np.partition
- np.array_split (Correct answer)
- np.divide
- np.separate
Correct answer: np.array_split
`np.array_split` splits an array into N roughly equal sub-arrays, allowing unequal splits unlike `np.split`.
Question 11: What does df['col'].value_counts(normalize=True) return?
- The cumulative frequency of each unique value
- The z-score of each unique value's count
- The absolute count of each unique value
- The relative frequency (proportion) of each unique value (Correct answer)
Correct answer: The relative frequency (proportion) of each unique value
normalize=True divides each count by the total number of observations, returning proportions that sum to 1.
Question 12: What is the primary advantage of nested cross-validation over standard cross-validation for model selection?
- It provides an unbiased estimate of the selected model's true generalization error (Correct answer)
- It is computationally cheaper
- It always selects the simplest model
- It eliminates the need for a test set
Correct answer: It provides an unbiased estimate of the selected model's true generalization error
Nested CV uses an outer loop for performance estimation and an inner loop for hyperparameter tuning, preventing selection bias from leaking into the performance estimate.
Question 13: You are given two 1D NumPy arrays, `a1 = np.array([1, 2, 3])` and `a2 = np.array([4, 5, 6])`. Which function would you use to combine them into a single 2D array where `a1` is the first row and `a2` is the second row?
- np.concatenate((a1, a2), axis=1)
- np.column_stack((a1, a2))
- np.hstack((a1, a2))
- np.vstack((a1, a2)) (Correct answer)
Correct answer: np.vstack((a1, a2))
`np.vstack()` stacks arrays in sequence vertically (row-wise). It takes a tuple of arrays as input and stacks them one on top of the other, creating a new dimension. `hstack` would append them horizontally, and `concatenate` with `axis=1` would raise an error for 1D arrays.
Question 14: Which NumPy operation performs element-wise multiplication of two arrays (NOT matrix multiplication)?
- np.cross(A, B)
- np.dot(A, B)
- A @ B
- A * B (Correct answer)
Correct answer: A * B
The * operator performs element-wise (Hadamard) multiplication; np.dot and @ perform matrix multiplication.
Question 15: What does the Area Under the ROC Curve (AUC) represent for a classification model?
- The trade-off point where precision and recall are perfectly balanced.
- The total number of correct predictions made by the model.
- The probability that the model will rank a randomly chosen positive instance higher than a randomly chosen negative instance. (Correct answer)
- The model's overall accuracy at the default classification threshold of 0.5.
Correct answer: The probability that the model will rank a randomly chosen positive instance higher than a randomly chosen negative instance.
The AUC score provides a single number summarizing the performance of a classifier across all possible classification thresholds. Its probabilistic interpretation is that it measures the likelihood that the model will assign a higher score (probability) to a randomly selected positive example than to a randomly selected negative example. An AUC of 1.0 represents a perfect model, while 0.5 represents a model with no discriminative ability.
Question 16: What does a confusion matrix diagonal represent in a classification problem?
- Feature importances
- Misclassified samples
- Predicted probabilities
- Correctly classified samples (Correct answer)
Correct answer: Correctly classified samples
The main diagonal of a confusion matrix shows counts where the predicted class equals the true class (correct predictions).
Question 17: Which of the following statements best describes a primary advantage of using Seaborn over Matplotlib?
- Seaborn provides more low-level control over every individual plot element.
- Seaborn is a high-level interface that creates visually appealing statistical plots with less code. (Correct answer)
- Seaborn is required for creating basic plots like line charts and bar charts.
- Seaborn offers faster rendering performance for simple visualizations.
Correct answer: Seaborn is a high-level interface that creates visually appealing statistical plots with less code.
Seaborn is built on top of Matplotlib and provides a higher-level API. Its main advantages are its ability to create complex and aesthetically pleasing statistical plots with more concise syntax, its beautiful default styles, and its seamless integration with Pandas DataFrames.
Question 18: Choosing the incorrect command to create and reshape a 60-integer array when the NumPy package has been imported as an object with the name np
- myArray=np.arrange(60).reshape(12,5)
- myarray=np.linspace(0,60,60).reshape(3,20)
- myArray=np.arrange(60).reshape(10,6)
- myArray=np.arrange(60).reshape(8,7) (Correct answer)
Correct answer: myArray=np.arrange(60).reshape(8,7)
Explanation: <br> The command myArray = np.arrange(60).reshape(8,7) is not a valid command for creating and reshaping a 60-integer array using NumPy.
Question 19: When traversing a dictionary in Python, method returns both the key and the value.
- Items (Correct answer)
- Enumerate
- Extend
- In
Correct answer: Items
Explanation: <br> To retrieve both the key and value while traversing a dictionary in Python, you can use the items() method. The items() method returns a view object that contains tuples of key-value pairs from the dictionary.
Question 20: Which measure of central tendency is most robust to outliers?
- Standard deviation
- Median (Correct answer)
- Mean
- Mode
Correct answer: Median
The median (middle value) is resistant to outliers because it depends on rank order, not the actual extreme values.
Question 21: Which evaluation metric is most appropriate for a text classification task where class distribution is highly imbalanced?
- F1-score (macro or weighted) (Correct answer)
- Accuracy
- Mean Squared Error
- Perplexity
Correct answer: F1-score (macro or weighted)
Accuracy is misleading when classes are imbalanced because a model can achieve high accuracy by predicting only the majority class; F1-score balances precision and recall across classes.
Question 22: Which statistic is most resistant to the influence of outliers when describing the center of a distribution?
- Median (Correct answer)
- Variance
- Mean
- Mode
Correct answer: Median
The median is the middle value and is not pulled by extreme outliers, making it a robust measure of central tendency.
Question 23: What is statistical power in hypothesis testing?
- The probability of making a Type I error
- The confidence level of the test
- The probability of correctly rejecting a false null hypothesis (Correct answer)
- The magnitude of the test statistic
Correct answer: The probability of correctly rejecting a false null hypothesis
Statistical power (1 - β) is the probability that a test correctly detects a real effect when one exists.
Question 24: What is the result of df.duplicated() on a DataFrame?
- Counts duplicates per column
- Drops all duplicate rows
- Returns only duplicate rows
- Returns a boolean Series marking duplicate rows (Correct answer)
Correct answer: Returns a boolean Series marking duplicate rows
df.duplicated() returns a boolean Series where True indicates a row is a duplicate of a previous row.
Question 25: Which Seaborn function creates a matrix of scatter plots for every pair of variables in a DataFrame?
- sns.scatterplot()
- sns.jointplot()
- sns.heatmap()
- sns.pairplot() (Correct answer)
Correct answer: sns.pairplot()
sns.pairplot() generates a grid of scatter plots for all pairwise combinations of numeric variables.
Question 26: Which Python library provides pre-trained Word2Vec and FastText models for loading and using word embeddings?
- TextBlob
- NLTK
- spaCy
- Gensim (Correct answer)
Correct answer: Gensim
Gensim specializes in topic modeling and word vector algorithms; its `KeyedVectors` API makes it straightforward to load pre-trained Word2Vec and FastText models.
Question 27: What is the result of `np.nonzero(np.array([0, 3, 0, 7, 0]))`?
- array([3, 7])
- array([1, 3])
- (array([1, 3]),) (Correct answer)
- array([False, True, False, True, False])
Correct answer: (array([1, 3]),)
`np.nonzero` returns a tuple of arrays (one per dimension) containing the indices of non-zero elements; for 1-D input it's a tuple with one array.
Question 28: In Python, what does `*args` in a function signature allow?
- Passing a variable number of positional arguments (Correct answer)
- Passing keyword arguments only
- Unpacking a single tuple argument
- Accepting only numeric arguments
Correct answer: Passing a variable number of positional arguments
`*args` collects any number of positional arguments passed to a function into a tuple.
Question 29: In a Ridge regression model, what is the effect of increasing the regularization parameter alpha?
- Coefficients shrink toward zero, reducing overfitting (Correct answer)
- The model becomes more complex
- Coefficients grow larger to fit data more tightly
- Feature selection is performed by setting some coefficients to exactly zero
Correct answer: Coefficients shrink toward zero, reducing overfitting
Higher alpha imposes stronger L2 penalty, shrinking all coefficients toward zero and reducing model variance.
Question 30: You have two DataFrames, `df1` and `df2`, with a common column 'employee_id'. You want to create a new DataFrame that contains only the rows where 'employee_id' exists in *both* `df1` and `df2`. Which merge operation should you use?
- pd.concat([df1, df2], on='employee_id')
- pd.merge(df1, df2, on='employee_id', how='inner') (Correct answer)
- pd.merge(df1, df2, on='employee_id', how='left')
- pd.merge(df1, df2, on='employee_id', how='outer')
Correct answer: pd.merge(df1, df2, on='employee_id', how='inner')
An 'inner' merge returns only the records that have matching keys in both DataFrames. This is equivalent to the intersection of the keys. An 'outer' merge would include all rows from both, a 'left' merge would include all rows from `df1` and matched rows from `df2`.
Data Science with Python Certification
A comprehensive certification that validates proficiency in Python-based data science skills including data manipulation with Pandas/NumPy, statistical analysis, machine learning, natural language processing, and time series forecasting.
Exam Rules
- You can skip questions and return to them later
- Flag questions for review before submitting
- No feedback shown until you submit the entire exam
- Unanswered questions count as wrong — answer everything
- 10 pretest questions are mixed in and don't affect your score
- Timer auto-submits when time runs out
- Your progress is auto-saved every 30 seconds