Free MS-DS Master of Data science Data Wrangling and Preprocessing Questions and Answers — Questions and Answers
Question 1: A data scientist is preparing a dataset for a machine learning model that is sensitive to the scale of its input features, such as K-Nearest Neighbors. The dataset contains two numerical features: 'Age' (ranging from 20 to 70) and 'Income' (ranging from 30,000 to 150,000). Which of the following preprocessing techniques is most appropriate to apply to these features?
- One-Hot Encoding
- Standardization (Z-score normalization)
- Log Transformation
- Normalization (Min-Max Scaling) (Correct answer)
Correct answer: Normalization (Min-Max Scaling)
Normalization, or Min-Max Scaling, rescales features to a fixed range, typically [0, 1]. [9, 13] This is crucial for distance-based algorithms like K-Nearest Neighbors, where features with larger ranges (like 'Income') could otherwise dominate the distance calculations and unduly influence the model's predictions. [7, 8] Standardization centers the data around a mean of 0 and a standard deviation of 1 but doesn't bound it to a specific range, which can be less ideal for algorithms that are highly sensitive to the magnitude of feature values. One-Hot Encoding is for categorical data, and Log Transformation is for handling skewed distributions.
Question 2: You are working with a customer dataset that includes a 'Subscription Level' feature with the categories: 'Bronze', 'Silver', 'Gold', and 'Platinum'. There is a clear hierarchical order to these categories. Which encoding method would be most suitable and efficient for this feature before using it in a machine learning model?
- One-Hot Encoding
- Label Encoding (Correct answer)
- Binary Encoding
- Hashing Encoder
Correct answer: Label Encoding
Label Encoding is ideal for ordinal categorical data where there is an intrinsic, meaningful order among the categories ('Bronze' < 'Silver' < 'Gold' < 'Platinum'). [2] It assigns a unique integer to each category (e.g., 0, 1, 2, 3), preserving the ordinal relationship while being memory-efficient. [3] One-Hot Encoding would be more appropriate for nominal data (no inherent order) but would create unnecessary extra columns and lose the ordinal information. [20]
Question 3: A dataset containing sensor readings has missing values in a 'Temperature' column. The data is missing completely at random (MCAR), and the overall temperature distribution is not heavily skewed. To handle the missing data, a data scientist decides to use an imputation method. Which of the following is a simple, yet reasonable, imputation strategy in this scenario?
- Replace missing values with a constant like 0
- Delete all rows with missing temperature values
- Replace missing values with the mean of the 'Temperature' column (Correct answer)
- Use K-Nearest Neighbors (KNN) Imputation
Correct answer: Replace missing values with the mean of the 'Temperature' column
For numerical data that is missing completely at random and has a symmetric distribution, mean imputation is a straightforward and common technique. [17, 22] It replaces the missing values with the average of the observed values, which can be a reasonable estimate that doesn't significantly distort the overall distribution. [18] Deleting rows can lead to a significant loss of information, and replacing with a constant can introduce bias. KNN Imputation is a more complex method that, while powerful, might be unnecessarily complex for this simple case.
Question 4: Which of the following data wrangling tasks is primarily aimed at reducing the dimensionality of the dataset while retaining as much of the original variance as possible?
- Outlier Removal using IQR
- Feature Scaling using Standardization
- Principal Component Analysis (PCA) (Correct answer)
- Data Aggregation
Correct answer: Principal Component Analysis (PCA)
Principal Component Analysis (PCA) is a dimensionality reduction technique used to transform a set of correlated features into a smaller set of uncorrelated features called principal components. The goal of PCA is to capture the maximum possible variance from the original features in the first few principal components, thereby reducing the number of features with minimal loss of information. [33] The other options address different preprocessing needs: outlier removal, feature scaling, and data summarization.
Question 5: A data scientist is analyzing a dataset of house prices and notices that the 'LotArea' feature is highly right-skewed. To prepare this feature for a linear regression model, which assumes a more normal distribution of variables, what is the most appropriate transformation to apply?
- One-Hot Encoding
- Log Transformation (Correct answer)
- Standardization
- Binning
Correct answer: Log Transformation
Log transformation is a common and effective method for handling right-skewed data. [21] By taking the logarithm of the values, it compresses the range of the larger values more than the smaller values, which can help make the distribution more symmetric and closer to a normal distribution. This is beneficial for linear models that perform better when variables are normally distributed. Standardization changes the mean and standard deviation but does not correct for skewness. One-hot encoding and binning are not suitable for this purpose.
Question 6: When cleaning a dataset, you discover that the 'Country' column, a categorical feature, has 50 unique values. You need to prepare this feature for a machine learning algorithm. If you use one-hot encoding, what potential problem are you most likely to introduce?
- Loss of ordinal information
- The Curse of Dimensionality (Correct answer)
- Introduction of multicollinearity if not handled correctly
- Underfitting of the model
Correct answer: The Curse of Dimensionality
One-hot encoding creates a new binary column for each unique category. [10, 20] With 50 unique countries, this method would add 50 new features to the dataset. This significant increase in the number of features (dimensions) can lead to the 'Curse of Dimensionality,' where the data becomes sparse, computational costs increase, and the model may have a harder time generalizing, potentially leading to overfitting. [3] While multicollinearity is also a concern (which can be addressed by dropping one column), the most prominent issue with a high number of categories is the drastic increase in dimensionality.
A data scientist is preparing a dataset for a machine learning model that is sensitive to the scale of its input features, such as K-Nearest Neighbors.
The dataset contains two numerical features: 'Age' (ranging from 20 to 70) and 'Income' (ranging from 30,000 to 150,000).
Which of the following preprocessing techniques is most appropriate to apply to these features?