question archive Use the two functions you implemented to calculate the accuracy for every cluster and the whole algorithm, defined as above

Use the two functions you implemented to calculate the accuracy for every cluster and the whole algorithm, defined as above

Subject:Computer SciencePrice:3.86 Bought12

Use the two functions you implemented to calculate the accuracy for every cluster and the whole algorithm, defined as above. Implement the following function in analysis.py:

def accuracy(data, labels, centroids):
    """
    Calculate the accuracy of the algorithm. You 
    should use update_assignment and majority_count 
    (that you previously implemented)

    Arguments:
        data: a list of lists representing all data points
        labels: a list of ints representing all data labels
        centroids: the centroid dictionary

    Returns: a float representing the accuracy of the algorithm
    """

 

 

I have already implemented:

 

def update_assignment(data, labels, centroids):

closest = {}

for centroid in centroids:

closest[centroid] = []

for label, point in zip(labels, data):

centroid = assign_data(point, centroids)

closest[centroid].append(label)

return {centroid: points for centroid, points in closest.items()

if len(points) > 0}

 

 

def majority_count(labels):

maj = {}

for label in labels:

if label in maj.keys():

maj[label] += 1

else:

maj[label] = 1

v = list(maj.values())

return max(v)

Option 1

Low Cost Option
Download this past answer in few clicks

3.86 USD

PURCHASE SOLUTION

Option 2

Custom new solution created by our subject matter experts

GET A QUOTE

rated 5 stars

Purchased 12 times

Completion Status 100%