Midterm 2 S24
Midterm 2 S24
1. What can this function possibly return, given di erent possible arguments?
def is_positive(a):
if a > 0:
return True
elif a < 0:
return False
A. 3
B. 9
C. 18
D.
0
1
3
3
4
6
6
7
9
ff
3. Which statement about a DataFrame is false?
4. Which regular expression operator means "at least one of the preceding symbol"?
A. +
B. *
C. ?
D. _
A. We reject the null hypothesis that the two groups have the same mean time.
B. We can't reject the null hypothesis that the two groups have the same mean time.
C. We reject the null hypothesis that the two groups are di erent.
D. Nothing, because we should have used a chi-square test to check whether these
groups are di erent.
6. Under what circumstances would we be most likely to use the "with" keyword?
class BinaryTree:
def __init__(self, val):
self.val = val
self.left = None
self.right = None
def mystery(tree):
if left:
mystery(tree.left)
else:
tree.left = BinaryTree(1)
if right:
mystery(tree.right)
else:
tree.right = BinaryTree(1)
return tree
9. In a train/test split performed for supervised machine learning, how are the examples
typically divided between the train and test sets?
A. Training set gets the "harder" problems, test set gets the "easier" problems.
B. Training set gets the "easier" problems, test set gets the "harder" problems.
C. Training set gets the beginning and middle of the data, and test set gets the end of
the data.
D. The test set is randomly sampled from all the data.
merge(): Take as an argument another Cluster object, and updates the current
cluster to include both sets of points. (Returns None.)
You should use what you know and the problem description to determine an
appropriate name for the constructor and what arguments these methods need.
fi
Problem 2 - (10 points)
Assume your Cluster implementation from the rst problem works. Write a function
assign(point, c1, c2) that takes a point p (an (x,y) tuple) and adds it to either the
points list of cluster c1 or the points list of cluster c2, whichever has a closer centroid.
(Return None.) Assume you have access to a function my_dist(p1, p2) that can
calculate distances between (x,y) tuples p1 and p2.
fi
Additional scratch space