Machine Learning Practice Test — Questions and Answers
Question 1: We set the gradient to zero to obtain the minimum or maximum of a function because:
- Depends on the type of problem
- The value of the gradient at extrema of a function is always zero (Correct answer)
- A and B
- None of these
Correct answer: The value of the gradient at extrema of a function is always zero
Explanation: <br> The gradient of a multivariable function at a maximum point will be the zero vector of the function, which is the single greatest value that the function can achieve.
Question 2: Which of the following machine learning algorithms is based on the principle of bagging and is extensively used and effective?
- Classification
- Random Forest (Correct answer)
- Decision Tree
- Regression
Correct answer: Random Forest
Explanation: <br> The Radom Forest algorithm builds an ensemble of Decision Trees, mostly trained with the bagging method.
Question 3: Which of the following is a good characteristic of a test dataset?
- Is representative of the dataset as a whole
- Large enough to yield meaningful results
- A and B (Correct answer)
Correct answer: A and B
Explanations: <br> A good test dataset has a good amount of sample population and equal ratios of class representation.
Question 4: The following are the most regularly used metrics and tools for evaluating a classification model:
- Area under the ROC curve
- Confusion matrix
- Cost-sensitive accuracy
- All of the above (Correct answer)
Correct answer: All of the above
Explanations: <br> The model performance assessment for classification algorithms encorporates all of the above techniques.
Question 5: What is the purpose of cross-validation?
- To judge how the trained model performs outside the sample on test data
- To assess the predictive performance of the models
- Both A and B (Correct answer)
Correct answer: Both A and B
Explanations: <br> Cross-validation is a model validation technique for assessing how the results of a statistical analysis will generalize to an independent data set.
Question 6: How do you deal with data in a dataset that is missing or corrupted?
- Replace missing values with mean/median/mode
- Assign a unique category to missing values
- Drop missing rows or columns
- All of the above (Correct answer)
Correct answer: All of the above
Explanations: All of the above techniques are different ways of imputing the missing values.
Question 7: A disadvantage of decision trees is which of the following?
- Decision trees are prone to be overfit (Correct answer)
- Factor analysis
- Decision trees are robust to outliers
Correct answer: Decision trees are prone to be overfit
Explanations: <br> Allowing a decision tree to split to a granular degree makes decision trees prone to learning every point extremely well to the point of perfect classification that is overfitting.
Question 8: Which of the following is the correct technique to preprocess data before performing regression or classification?
- PCA -> normalize PCA output -> training
- Normalize the data -> PCA -> normalize PCA output -> training
- Normalize the data -> PCA -> training (Correct answer)
Correct answer: Normalize the data -> PCA -> training
Explanations: <br> You need to always normalize the data first. If not, PCA or other techniques that are used to reduce dimensions will give different results.
Question 9: Why is it necessary to use second-order differencing in a time series?
- To find the maxima or minima at the local point
- To remove stationarity
- Both A and B (Correct answer)
- None of these
Correct answer: Both A and B
Explanations: <br> If the second-order difference is positive, the time series will curve upward and if it is negative, the time series will curve downward at that time.
Question 10: In Sklearn, what is pca.components_?
- Matrix of principal components
- Result of the multiplication matrix
- Set of all eigen vectors for the projection space (Correct answer)
- None of the above
Correct answer: Set of all eigen vectors for the projection space
Explanations: <br> pca.components_ is the set of all eigen vectors for the projection space.
Question 11: Which of the following is a feature extraction example?
- Removing stopwords in a sentence
- Constructing bag of words vector from an email
- Applying PCA projects to a large high-dimensional data
- All of the above (Correct answer)
Correct answer: All of the above
Explanations: <br> All of the above techniques transform raw data into features which can be used as inputs to machine learning algorithms.
Question 12: Which of the following regularization statements is incorrect?
- Using a very large value of lambda cannot hurt the performance of your hypothesis.
- Using too large a value of lambda can cause your hypothesis to underfit the data.
- Using too large a value of lambda can cause your hypothesis to overfit the data.
- None of the above (Correct answer)
Correct answer: None of the above
Explanations: <br> A large value results in a large regularization penalty and therefore, a strong preference for simpler models, which can underfit the data.
Question 13: Which of the following statements about Naive Bayes is correct?
- Assumes that all the features in a dataset are independent
- Assumes that all the features in a dataset are equally important
- A and B (Correct answer)
- None of the above
Correct answer: A and B
Explanations: <br> Naive Bayes assumes that all the features in a data set are equally important and independent.
Question 14: Which of the following scenarios will K-means clustering fail to produce satisfactory results? 1) Outliers in the data 2) Data points of various densities 3) Nonconvex data points
- 2 and 3
- 1 and 2
- 1 and 3
- 1, 2, and 3 (Correct answer)
Correct answer: 1, 2, and 3
Explanations: <br> K-means clustering algorithm fails to give good results when the data contains outliers, the density spread of data points across the data space is different, and the data points follow nonconvex shapes.
Question 15: In-text mining, which of the following approaches can be used for normalization?
- Stop Word Removal
- Stemming
- Lemmatization
- Both B and C (Correct answer)
Correct answer: Both B and C
Explanations: <br> Lemmatization and stemming are the techniques of keyword normalization.
Question 16: How can a clustering algorithm avoid becoming caught in a bad local optima?
- Use multiple radom initializations (Correct answer)
- Set the same seed value for each run
- Both A and B
Correct answer: Use multiple radom initializations
Clustering algorithms like K-means are iterative and sensitive to their initial centroid placement. A poor initialization can lead to convergence on a suboptimal local optimum. By running the algorithm multiple times with different random initializations and selecting the best result (e.g., lowest inertia), the chances of finding a better, more global optimum are significantly increased.
Question 17: After 15 iterations of gradient descent with a=0.3, you compute J(theta). You notice that J(Theta) rapidly falls before leveling out. Which of the following conclusions do you think is most likely based on this information?
- a=0.3 is an effective choice of learning rate (Correct answer)
- Rather than using the current value of a, use a larger value of a (say a=1.0)
- Rather than using the current value of a, use a smaller value of a (say a=0.1)
Correct answer: a=0.3 is an effective choice of learning rate
When the cost function J(Theta) rapidly decreases and then levels out, it indicates that the gradient descent algorithm is converging efficiently. This behavior suggests that the chosen learning rate (alpha = 0.3) is appropriate, allowing the model to quickly approach the minimum without overshooting or getting stuck. If the learning rate were too large, J(Theta) might diverge or oscillate; if too small, it would decrease very slowly.
Question 18: Which of the following is an appropriate method for determining "k" main components?
- Choose k to be 99% of m (k = 0.99*m, rounded to the nearest integer).
- Choose k to be the smallest value so that at least 99% of the varinace is retained. (Correct answer)
- Use the elbow method.
- Choose k to be the largest value so that 99% of the variance is retained.
Correct answer: Choose k to be the smallest value so that at least 99% of the varinace is retained.
In Principal Component Analysis (PCA), the goal is to reduce dimensionality while retaining as much information (variance) as possible. A common heuristic is to select the smallest number of principal components (k) that collectively explain a high percentage (e.g., 95% or 99%) of the total variance in the original data. This ensures that most of the data's variability is preserved, minimizing information loss while achieving significant dimensionality reduction.
Question 19: What is the purpose of a sentence parser?
- It is used to parse sentences to derive their most likely syntax tree structures. (Correct answer)
- It is used to parse sentences to check if they are utf-8 compliant.
- It is used to check if sentences can be parsed into meaningful tokens.
- It is used to parse sentences to assign POS tags to all tokens.
Correct answer: It is used to parse sentences to derive their most likely syntax tree structures.
A sentence parser in Natural Language Processing (NLP) analyzes the grammatical structure of a sentence. Its primary purpose is to determine the syntactic relationships between words and phrases, typically by generating a parse tree or dependency graph. This structural representation helps in understanding the meaning and relationships within the sentence, which is crucial for many downstream NLP tasks.
Question 20: Using the automated machine learning user interface, you create a machine learning model (UI). You must guarantee that the model complies with Microsoft's transparent AI philosophy. What are your options?
- Enable Explain best model. (Correct answer)
- Set Validation type to Auto.
- Set Max concurrent iterations to 0.
- Set Primary metric to accuracy.
Correct answer: Enable Explain best model.
Microsoft's transparent AI philosophy emphasizes interpretability and understanding how models make decisions. Enabling 'Explain best model' in an automated ML UI provides insights into the model's predictions, such as feature importance and how different features influence the output. This functionality directly supports transparency by making the model's internal workings more understandable to users.
Question 21: Different binary classification models are being evaluated by a Data Scientist. A false positive result is 5 times more expensive than a false negative result (from a commercial standpoint). <br> The following criteria should be used to evaluate the models: <br> 1) Must have a recall rate of at least 80% <br> 2) Must have a false positive rate of 10% or less <br> 3) Must minimize business costs <br> The Data Scientist creates the matching confusion matrix once each binary classification model is created. <br> Which confusion matrix best describes the model that meets the criteria?
- TN = 99, FP = 1 FN = 21, TP = 79
- TN = 91, FP = 9 FN = 22, TP = 78
- TN = 98, FP = 2 FN = 18, TP = 82 (Correct answer)
- TN = 96, FP = 4 FN = 10, TP = 90
Correct answer: TN = 98, FP = 2 FN = 18, TP = 82
For option C (TN=98, FP=2, FN=18, TP=82), the recall is 82/(82+18) = 82%, meeting criterion 1. The False Positive Rate is 2/(2+98) = 2%, meeting criterion 2. The total business cost is (2 FP * 5) + (18 FN * 1) = 10 + 18 = 28. Comparing this to option D (cost 30), option C minimizes business costs while satisfying all criteria.
Question 22: A Machine Learning Engineer uses the Amazon SageMaker Linear Learner algorithm to prepare a data frame for a supervised learning task. The ML Engineer notes that the target label classes are unbalanced, and that several feature columns have missing data. The percentage of missing values is less than 5% for the full data frame. <br> What should the machine learning engineer do to reduce bias caused by missing values?
- Replace each missing value by the mean or median across non-missing values in the same column.
- Replace each missing value by the mean or median across non-missing values in same row.
- For each feature, approximate the missing values using supervised learning based on other features. (Correct answer)
- Delete observations that contain missing values because these represent less than 5% of the data.
Correct answer: For each feature, approximate the missing values using supervised learning based on other features.
While simple imputation methods like mean/median replacement are common, they can introduce bias and reduce variance, especially if the missingness is not completely random. Using supervised learning to impute missing values (e.g., MICE, k-NN imputation) is a more sophisticated approach. This method leverages relationships between other features to make more accurate predictions for the missing data, thereby reducing potential bias and preserving data distribution better than simpler methods.
Question 23: A business wants to develop a fraud detection model. Due to the limited number of fraud incidents, the Data Scientist currently does not have enough information. <br> Which strategy is the MOST LIKELY to catch the MOST genuine fraud cases?
- Class weight adjustment
- Oversampling using SMOTE (Correct answer)
- Undersampling
- Oversampling using bootstrapping
Correct answer: Oversampling using SMOTE
Fraud detection datasets are typically highly imbalanced, with very few fraud cases. To effectively train a model to identify these rare instances, the dataset needs to be balanced. SMOTE (Synthetic Minority Over-sampling Technique) generates synthetic samples for the minority class (fraud cases) based on existing minority class examples, rather than simply duplicating them, which helps the model learn the characteristics of fraud cases more effectively and increases the likelihood of catching genuine fraud.
Question 24: A fraud detection model is built using logistic regression by a Data Scientist. While the algorithm's accuracy is 99 percent, the model fails to detect 90 percent of fraud incidents. <br> What activity will ensure that the model is able to detect more than 10% of fraud cases?
- Using regularization to reduce overfitting
- Using oversampling to balance the dataset
- Using undersampling to balance the dataset
- Decreasing the class probability threshold (Correct answer)
Correct answer: Decreasing the class probability threshold
A high accuracy (99%) combined with a low detection rate for fraud (only 10% detected) indicates a highly imbalanced dataset where the model is biased towards the majority class (non-fraud). Logistic regression outputs probabilities, typically using a 0.5 threshold for classification. Decreasing this threshold makes the model more sensitive to the minority class (fraud), causing it to classify more instances as fraud and thereby increasing the recall (detection rate) for fraud cases.
Question 25: In Amazon S3, a Machine Learning team has numerous huge CSV datasets. On similar-sized datasets, models developed with the Amazon SageMaker Linear Learner algorithm have previously taken hours to train. The training process must be accelerated by the team's leaders. <br> What can a Machine Learning Expert do to help with this issue?
- Use Amazon Machine Learning to train the models.
- Use Amazon SageMaker Pipe mode. (Correct answer)
- Use AWS Glue to transform the CSV dataset to the JSON format.
- Use Amazon Kinesis to stream the data to Amazon SageMaker.
Correct answer: Use Amazon SageMaker Pipe mode.
Amazon SageMaker Pipe mode is designed to accelerate training for large datasets stored in S3. Instead of downloading the entire dataset to the training instance before training begins (File mode), Pipe mode streams data directly from S3 to the training algorithm. This significantly reduces the startup time, disk I/O, and overall training duration, making it ideal for large datasets and time-sensitive training requirements.
We set the gradient to zero to obtain the minimum or maximum of a function because: