Data Science Data Cleaning and Preparation Questions and Answers 1 — Questions and Answers
Question 1: A data scientist is preparing a dataset for a K-Nearest Neighbors (KNN) model. The dataset contains features with vastly different scales: 'Age' (ranging from 20-70) and 'Income' (ranging from 30,000-250,000). Which data preparation technique is most crucial to apply in this scenario to ensure model performance is not biased?
- One-Hot Encoding
- Feature Scaling (Correct answer)
- Logarithmic Transformation
- Principal Component Analysis
Correct answer: Feature Scaling
Feature scaling is essential for distance-based algorithms like K-Nearest Neighbors (KNN). Since KNN relies on calculating the distance between data points, features with larger scales (like 'Income') can dominate and disproportionately influence the distance metric, leading to biased predictions. Techniques like Normalization (scaling to a range, e.g., 0 to 1) or Standardization (scaling to a mean of 0 and standard deviation of 1) ensure all features contribute equally to the distance calculation.
Question 2: A dataset contains a categorical feature 'Product_Category' with three unique values: 'Electronics', 'Apparel', and 'Groceries'. The machine learning model to be used is a linear regression model. Which encoding technique is most appropriate for this feature, and why?
- Label Encoding, because it is computationally efficient and creates a single feature column.
- Binary Encoding, because it is a memory-efficient compromise between Label and One-Hot encoding.
- One-Hot Encoding, because it prevents the model from assuming a false ordinal relationship between the categories. (Correct answer)
- Hashing Encoding, because it handles a large number of categories without increasing dimensionality significantly.
Correct answer: One-Hot Encoding, because it prevents the model from assuming a false ordinal relationship between the categories.
One-Hot Encoding is the most suitable method for nominal categorical data when using models like linear regression. Label Encoding would assign integer values (e.g., 0, 1, 2), which could cause the linear model to incorrectly assume that the categories have a meaningful order (e.g., 'Groceries' > 'Apparel' > 'Electronics'). One-Hot Encoding avoids this by creating new binary columns for each category, representing them as 0s and 1s without implying any ordinal relationship.
Question 3: Which of the following methods for handling missing numerical data is generally most robust to the presence of outliers in the feature's distribution?
- Mean Imputation
- Mode Imputation
- Median Imputation (Correct answer)
- Dropping the rows with missing values
Correct answer: Median Imputation
Median Imputation is more robust to outliers than Mean Imputation. The mean is sensitive to extreme values (outliers) and can be skewed, leading to a less representative imputation value. The median, being the middle value of a sorted dataset, is not significantly affected by outliers. While dropping rows is an option, it can lead to significant data loss. Mode imputation is typically used for categorical data.
Question 4: A data analyst is cleaning a dataset and identifies several data points that are three standard deviations away from the mean for a particular feature that is approximately normally distributed. What is this method of identifying potential issues called?
- Interquartile Range (IQR) Method
- Z-Score Method (Correct answer)
- DBSCAN Clustering
- Isolation Forest
Correct answer: Z-Score Method
The Z-Score method identifies outliers by calculating how many standard deviations a data point is from the mean. A common threshold is to consider points with a Z-score greater than 3 or less than -3 as outliers, especially when the data follows a normal distribution. The IQR method uses quartiles, while DBSCAN and Isolation Forest are more advanced, density-based and tree-based machine learning methods, respectively.
Question 5: A data scientist is working with a dataset where a numerical feature has a strong positive skew. To prepare this data for a model that performs better with normally distributed features, which transformation is most appropriate?
- Standardization (Z-score scaling)
- Min-Max Normalization
- One-Hot Encoding
- Logarithmic Transformation (Correct answer)
Correct answer: Logarithmic Transformation
Logarithmic transformation is a common and effective method for handling right-skewed (positively skewed) data. It compresses the range of large values and expands the range of small values, which can help make the distribution more symmetric and closer to a normal distribution. Standardization and Normalization change the scale of the data but do not alter the basic shape of its distribution. One-Hot Encoding is for categorical variables.
Question 6: When cleaning a customer database, a data analyst discovers that the 'State' column contains inconsistencies such as 'CA', 'Calif.', and 'California'. What is the most appropriate data cleaning step to address this issue?
- Impute missing values using the mode.
- Remove the 'State' column from the dataset.
- Standardize the categorical values to a single format. (Correct answer)
- Apply feature scaling to the 'State' column.
Correct answer: Standardize the categorical values to a single format.
The issue described is one of inconsistent formatting for a categorical feature. The correct approach is to standardize these values into a single, consistent format (e.g., converting all variations to 'CA'). This ensures that records are grouped correctly during analysis and that the feature is treated as a single category by machine learning models. Imputation is for missing data, removing the column would cause information loss, and feature scaling applies to numerical data.
A data scientist is preparing a dataset for a K-Nearest Neighbors (KNN) model.
The dataset contains features with vastly different scales: 'Age' (ranging from 20-70) and 'Income' (ranging from 30,000-250,000).
Which data preparation technique is most crucial to apply in this scenario to ensure model performance is not biased?