def task(self): dataset = clust.parse_input(open('adults.txt', 'r'), 1000) all_errors = [] # Generate a random initial assignment for clusters in self.CLUSTERS: # get the lowest error over three runs errors = [ clust.kmeans(dataset, clusters)[1] for i in xrange(self.SAMPLES) ] error = sorted(errors)[0] all_errors.append({"x": clusters, "y": error}) chart = { "chart": { "defaultSeriesType": "line" }, "xAxis": { "title": { "text": "Clusters" }, "min": 1 }, "yAxis": { "title": { "text": "Mean Squared Error" } }, "title": { "text": "K-means Results" }, "series": [{ "data": all_errors }] } return chart
def task(self): dataset = clust.parse_input(open('adults.txt', 'r'), 1000) all_errors = [] # Generate a random initial assignment for clusters in self.CLUSTERS: # get the lowest error over three runs errors = [ clust.kmeans(dataset, clusters)[1] for i in xrange(self.SAMPLES) ] error = sorted(errors)[0] all_errors.append({ "x": clusters, "y": error }) chart = {"chart": {"defaultSeriesType": "line"}, "xAxis": {"title": {"text": "Clusters"}, "min": 1 }, "yAxis": {"title": {"text": "Mean Squared Error"}}, "title": {"text": "K-means Results"}, "series": [ {"data": all_errors } ]} return chart
def get_dataset(self): return clust.parse_input(open('adults-small.txt', 'r'), 200)
def get_dataset(self): return clust.parse_input(open('adults-small.txt', 'r'), 100)
def setUp(self): self.dataset = clust.parse_input(open('adults.txt', 'r'), 100)