Data Science with Python Certification Data Science with Python (Basic) 4 — Questions and Answers
Question 1: What is the purpose of StandardScaler in scikit-learn?
- Scales target labels to integers
- Transforms features to have zero mean and unit variance (Correct answer)
- Normalizes features to the range [0,1]
- Encodes categorical variables as integers
Correct answer: Transforms features to have zero mean and unit variance
StandardScaler standardizes features by removing the mean and scaling to unit variance (z-score normalization).
Question 2: Which of the following correctly reads a CSV file into a pandas DataFrame?
- pd.open_csv('file.csv')
- pd.read_csv('file.csv') (Correct answer)
- pd.load('file.csv')
- pd.import_csv('file.csv')
Correct answer: pd.read_csv('file.csv')
pd.read_csv() is the standard pandas function for parsing a comma-separated values file into a DataFrame.
Question 3: What does the term 'overfitting' mean in machine learning?
- The model performs poorly on both training and test data
- The model learns training data too well and fails to generalize to new data (Correct answer)
- The training process takes too many epochs
- The model has too few parameters to learn the pattern
Correct answer: The model learns training data too well and fails to generalize to new data
Overfitting occurs when a model memorizes training data noise, resulting in high training accuracy but poor performance on unseen data.
Question 4: In Python, what does the zip() function do when applied to two lists?
- Compresses both lists into a single file
- Pairs elements from both lists into tuples, stopping at the shortest list (Correct answer)
- Concatenates the two lists end-to-end
- Returns the set intersection of the two lists
Correct answer: Pairs elements from both lists into tuples, stopping at the shortest list
zip() aggregates elements from multiple iterables into tuples, stopping when the shortest iterable is exhausted.
Question 5: Which NumPy function returns the indices that would sort an array?
- np.sort()
- np.argsort() (Correct answer)
- np.sortindex()
- np.rank()
Correct answer: np.argsort()
np.argsort() returns the integer indices that would sort the array, not the sorted values themselves.
Question 6: What is the role of the fit() method in a scikit-learn estimator?
- Transforms the input data without learning any parameters
- Trains the model by learning parameters from the training data (Correct answer)
- Evaluates model accuracy on a test set
- Loads pre-trained model weights from disk
Correct answer: Trains the model by learning parameters from the training data
fit() trains the estimator by computing and storing the model parameters learned from the provided training data.
Question 7: What does the pandas method df.merge() perform?
- Stacks two DataFrames vertically
- Joins two DataFrames horizontally based on common key column(s) (Correct answer)
- Removes duplicate rows across two DataFrames
- Concatenates two DataFrames ignoring the index
Correct answer: Joins two DataFrames horizontally based on common key column(s)
df.merge() combines two DataFrames by matching rows on one or more key columns, similar to SQL JOIN operations.
What is the purpose of StandardScaler in scikit-learn?