You have a dataset of ages: [22, 25, 29, 24, 30, 22, 28]. What are the mean and median values?
import numpy as np ages = [22, 25, 29, 24, 30, 22, 28] mean_age = np.mean(ages) median_age = np.median(ages) print(f"Mean: {mean_age}, Median: {median_age}")
Mean is the average, median is the middle value when sorted.
Mean is sum of all ages divided by count: (22+25+29+24+30+22+28)/7 = 25.71. Median is the middle value after sorting: [22,22,24,25,28,29,30], middle is 25.
Given the data points: [1, 2, 2, 3, 3, 3, 4, 4, 5], which histogram correctly shows the frequency of each number?
import matplotlib.pyplot as plt import numpy as np data = [1, 2, 2, 3, 3, 3, 4, 4, 5] plt.hist(data, bins=5, edgecolor='black') plt.show()
Count how many times each number appears.
Number 1 appears once, 2 appears twice, 3 appears three times, 4 appears twice, 5 appears once.
Which statement correctly describes a Pearson correlation coefficient of -0.85 between two variables?
Correlation values near -1 or 1 indicate strong relationships.
A value of -0.85 means a strong negative linear relationship: as one variable increases, the other tends to decrease strongly.
What error will this code raise?
import numpy as np data = [1, 2, 3, 4, 5] variance = np.var(data, ddof=1) print(variance)
import numpy as np data = [1, 2, 3, 4, 5] variance = np.var(data, ddof=1) print(variance)
Check the parentheses in the function call.
The np.var function call is missing a closing parenthesis, causing a SyntaxError.
You run k-means clustering on a dataset with k values from 2 to 6. The silhouette scores are: {2: 0.45, 3: 0.52, 4: 0.48, 5: 0.40, 6: 0.35}. Which k should you choose for best cluster separation?
Higher silhouette score means better cluster separation.
The highest silhouette score is 0.52 at k=3, indicating best cluster separation.
