← All Data Science Flashcard Decks

Data Cleaning and Preparation Flashcards

6 cards from real Data Science practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 6 Data Cleaning and Preparation flashcards as text
  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?

    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.

  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?

    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.

  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?

    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.

  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?

    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.

  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?

    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.

  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?

    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.