Esempio n. 1
0
def score_result(reducer_function, data, x_scaled, ini, dimensions, label_data,
                 title):
    knn = Knn()
    score = []
    valor_k = range(ini, dimensions)
    for k in valor_k:
        new_data = reducer_function(data, x_scaled, k)
        score.append(knn.avg(new_data, label_data))

    Visualization.hit_rate_per_k(valor_k, score, title)
    def run(self, alg, bean_list, filename="img.png", weighted=False):
        accuracy = []
        #self.set_train_test_set(generator,bean_list)
        for k in self.k_values:
            for train in self.train_set:
                # Train
                alg.train([bean_list[a] for a in train])
            for test in self.test_set:
                # Test
                result = alg.teste([bean_list[a] for a in test], k=k)

                # Result
                accuracy.append(Knn.accuracy(result))
                print("acuracy knn {0} with k {1}".format(accuracy[-1], k))

            self.mean_accuracy(accuracy)

        # Plot the graphic
        Visualization.hit_rate_per_k(self.mean_accuracy_list, self.k_values,
                                     filename, weighted)