Exemplo n.º 1
0
    def fraudar(self):
        '''
        plt.imshow(self.original_I,interpolation='none',cmap='Greys')
        plt.colorbar()
        plt.show()
        '''
        pred = list()
        sparse_I = csr_matrix(self.original_I)
        reviews = [(i, j) for i, j in zip(*sparse_I.nonzero())]

        graph = fraudar.ReviewGraph(1, fraudar.aveDegree)

        # Create reviewers and products.
        reviewers = [
            graph.new_reviewer("{0}".format(i)) for i in range(self.n)
        ]
        products = [graph.new_product("{0}".format(i)) for i in range(self.m)]

        # Add reviews.
        for review in reviews:
            graph.add_review(reviewers[review[0]], products[review[1]], 1)

        # Run the algorithm.
        graph.update()

        # write anomalous reviewrs to output.txt
        for r in graph.reviewers:
            if r.anomalous_score == 1:
                pred.append(r.name)

        _eval = self.evaluate_fraudar(pred)
        print('Fraudar: ', _eval)
        return pred, _eval
Exemplo n.º 2
0
def analyze(blocks):
    """Analyze a synthetic data set with a given number of blocks.

    Args:
      blocks: the number of blocks.
    """
    graph = fraudar.ReviewGraph(blocks)
    synthetic.load(graph)

    graph.update()

    detected = [r for r in graph.reviewers if r.anomalous_score]
    correct = [r for r in detected if "anomaly" in r.name]

    print(
        len(correct) / len(detected),
        len(correct) / synthetic.ANOMALOUS_REVIEWER_SIZE)
Exemplo n.º 3
0
 def create_fraudar_graph(nblock=1):
     """Create a review graph defined in Fraud Eagle package.
     """
     return fraudar.ReviewGraph(int(nblock))