Data Science with Python Certification Data Science with Python (Basic) 3 — Questions and Answers
Question 1: What is broadcasting in NumPy?
- Sending array data over a network socket
- A mechanism that allows arithmetic operations on arrays of different shapes (Correct answer)
- Converting a 1-D array to a 2-D matrix
- Printing array values to the console
Correct answer: A mechanism that allows arithmetic operations on arrays of different shapes
Broadcasting allows NumPy to perform element-wise operations on arrays with different shapes by virtually expanding the smaller array.
Question 2: In a pandas DataFrame, what is the difference between loc and iloc?
- loc uses column names only; iloc uses row names only
- loc uses label-based indexing; iloc uses integer position-based indexing (Correct answer)
- loc is faster; iloc is for large datasets
- loc works on Series; iloc works on DataFrames
Correct answer: loc uses label-based indexing; iloc uses integer position-based indexing
loc selects data using row/column labels, while iloc selects using integer positions (0-based).
Question 3: Which Python library is primarily used for data manipulation and analysis with labeled data structures?
- NumPy
- SciPy
- pandas (Correct answer)
- Matplotlib
Correct answer: pandas
pandas provides DataFrame and Series structures designed for labeled, tabular data manipulation and analysis.
Question 4: What does a confusion matrix diagonal represent in a classification problem?
- Misclassified samples
- Correctly classified samples (Correct answer)
- Predicted probabilities
- Feature importances
Correct answer: Correctly classified samples
The main diagonal of a confusion matrix shows counts where the predicted class equals the true class (correct predictions).
Question 5: Which NumPy operation computes the dot product of two 1-D arrays?
- np.cross(a,b)
- np.multiply(a,b)
- np.dot(a,b) (Correct answer)
- np.outer(a,b)
Correct answer: np.dot(a,b)
np.dot(a,b) computes the dot (inner) product of two 1-D arrays, resulting in a scalar.
Question 6: What does df.pivot_table() primarily allow you to do in pandas?
- Transpose all rows and columns
- Summarize data by grouping and applying aggregation functions across two dimensions (Correct answer)
- Merge two DataFrames on a key
- Sort a DataFrame by multiple columns
Correct answer: Summarize data by grouping and applying aggregation functions across two dimensions
pivot_table creates a spreadsheet-style pivot table that aggregates data across rows and columns defined by index and column parameters.
Question 7: In seaborn, which plot type is most appropriate for visualizing the distribution of a single continuous variable?
- sns.barplot()
- sns.scatterplot()
- sns.histplot() (Correct answer)
- sns.heatmap()
Correct answer: sns.histplot()
sns.histplot() (or the older sns.distplot()) shows the frequency distribution of a single continuous variable as a histogram.
What is broadcasting in NumPy?