MCQ Exercises

Author

Amanda Ng

Numpy

Q1. Which of the following correctly creates a 2×3 NumPy array?
Q2. What does np.linspace(0, 10, 5) produce?
Q3. If x = np.array([[1,2,3],[4,5,6]]), what is x.shape?
Q4. Given a = np.array([1,2,3,4]), what does a.mean() return?
Q5. Which NumPy function computes the square root of every element in an array?
Q6. What does x.reshape(6,) do to a 2×3 array?
Q7. Which statement about flatten() and ravel() is correct?
Q8. Given x = np.array([[10,20,30],[40,50,60]]), what does x[:,1] return?

Pandas

Q1. Which statement correctly describes a Pandas Series?
Q2. Which command displays the last 5 rows of a DataFrame df?
Q3. Which function removes all rows containing at least one NA value?
Q4. Which command correctly extracts the columns ‘Age’ and ‘Gender’ as a DataFrame?
Q5. Which command correctly filters rows where age is over 40 and has not experienced heart attack?
Q6. Which command correctly creates a new column storing age 5 years later?
Q7. Which command correctly assigns ‘Male’ when Gender==1 and ‘Female’ otherwise?
Q8. Which command computes mean BMI grouped by Heart_attack status?

Scikitlearn

Q1. From which module do you import LinearRegression?
Q2. Which statement about preparing the outcome for logistic regression is correct?
Q3. What is the purpose of train_test_split()?
Q4. Which statement correctly compares LASSO and Ridge regression?
Q5. Which statement correctly describes how KNN makes predictions?

Matplotlib

Q1. Which statement correctly describes the relationship between a Figure and an Axes in Matplotlib?
Q2. Which command correctly creates a 2×2 grid of subplots?
Q3. Which command correctly creates a scatterplot on an Axes object?
Q4. Which command correctly creates a histogram of Age with 10 bins and visible bin edges?
Q5. Which statement correctly describes the components of a Matplotlib boxplot?

Return to Learning Hub Homepage

Learning Hub Homepage