Пример #1
0
    def itemContent(self, attributes='', splitAttribute='', newUsers=None, newObservationData=None, eval=False, similarItem=None):
        newItems = self._items.copy()
        if attributes:
            newItems = self._items[attributes]
        if splitAttribute:
            newItems = self._splitAttribute(newItems, splitAttribute)
        icr = gl.item_content_recommender.create(newItems, 'item_id', self._ratings, 'user_id', target='rating')
        recs = icr.recommend(users=newUsers, new_observation_data=newObservationData, k=10).join(self._items, on='item_id').sort('rank')
        print 'Recomendacoes por conteudo com base completa'
        print(recs)

        if similarItem:
            similarity = icr.get_similar_items(similarItem).join(self._items, on={'similar': 'item_id'}).sort('rank')
            print 'Recomendacoes por item'
            print(similarity)

        if eval:
            icrTrain = gl.item_content_recommender.create(newItems, 'item_id', self._train, 'user_id', target='rating')
            evalPrecisionRecall = icrTrain.evaluate_precision_recall(self._test)
            evalRMSE = icrTrain.evaluate_rmse(self._test, target='rating')
            eval = icrTrain.evaluate(self._test)
            print 'Avaliacao com grupos train e test'
            print(eval)
            print 'Valores de Precision e Recal'
            print(evalPrecisionRecall)
            print 'RMSE'
            print(evalRMSE)

        if newUsers:
            route = Route(recs['latitude'], recs['longitude'], recs['name'])
            route.map(newUsers[0])
Пример #2
0
    def itemSimilarity(self,
                       similarityType='jaccard',
                       newUsers=None,
                       newObservationData=None,
                       eval=False,
                       similarItem=None):
        print(self._ratings.dtype())
        isr = gl.item_similarity_recommender.create(
            self._ratings, target='rating', similarity_type=similarityType)
        recs = isr.recommend(users=newUsers,
                             new_observation_data=newObservationData).join(
                                 self._items, on='item_id').sort('rank')
        print(recs)

        if eval:
            isrTrain = gl.item_similarity_recommender.create(
                self._train, target='rating', similarity_type=similarityType)
            evalPrecisionRecall = isrTrain.evaluate_precision_recall(
                self._test)
            evalRMSE = isrTrain.evaluate_rmse(self._test, target='rating')
            eval = isrTrain.evaluate(self._test)
            print(eval)

        if similarItem:
            similarity = isr.get_similar_items(similarItem).join(
                self._items, on={
                    'similar': 'item_id'
                }).sort('rank')
            print(similarity)

        if newUsers and newObservationData:
            route = Route(recs['latitude'], recs['longitude'])
            route.map()
Пример #3
0
    def itemSimilarity(self, similarityType='jaccard', newUsers=None, newObservationData=None, eval=False, similarItem=None):
        # print(self._ratings.dtype())
        ratings_without_recommend = self._ratings.filter_by(newUsers, 'user_id', exclude=True)
        isr = gl.recommender.ranking_factorization_recommender.create(ratings_without_recommend, target='rating')
        recs = isr.recommend(users=newUsers, new_observation_data=newObservationData).join(self._items, on='item_id').sort('rank')
        print 'Recomendacoes por similaridade com base completa'
        print(recs)

        if eval:
            print 'Recomendacoes EVAAL'
            # Executa o treinamento e teste com os grupos previamente criados
            isrTrain = gl.recommender.ranking_factorization_recommender.create(self._train, target='rating')
            # Retorna o precision e o recall
            evalPrecisionRecall = isrTrain.evaluate_precision_recall(self._test)
            # Avaliação do erro Root Mean Square Error
            evalRMSE = isrTrain.evaluate_rmse(self._test, target='rating')
            eval = isrTrain.evaluate(self._test)
            print 'Avaliacao com grupos train e test'
            print(eval)
            print 'Valores de Precision e Recal'
            print(evalPrecisionRecall)
            print 'RMSE'
            print(evalRMSE)

        #import pdb; pdb.set_trace()
        # Recomendação feita baseada em item
        if similarItem:
            similarity = isr.get_similar_items(similarItem).join(self._items, on={'similar': 'item_id'}).sort('rank')
            print 'Recomendacoes por item'
            print(similarity)

        # Escreve as rotas para serem utilizadas no web
        if newUsers and newObservationData:
            route = Route(recs['latitude'], recs['longitude'], recs['name'])
            route.map()
Пример #4
0
    def itemContent(self,
                    attributes='',
                    splitAttribute='',
                    newUsers=None,
                    newObservationData=None,
                    eval=False,
                    similarItem=None):
        newItems = self._items.copy()
        if attributes:
            newItems = self._items[attributes]
        if splitAttribute:
            newItems = self._splitAttribute(newItems, splitAttribute)
        icr = gl.item_content_recommender.create(newItems,
                                                 'item_id',
                                                 self._ratings,
                                                 'user_id',
                                                 target='rating')
        recs = icr.recommend(users=newUsers,
                             new_observation_data=newObservationData).join(
                                 self._items, on='item_id').sort('rank')
        print(recs)

        if similarItem:
            similarity = icr.get_similar_items(similarItem).join(
                self._items, on={
                    'similar': 'item_id'
                }).sort('rank')
            print(similarity)

        if eval:
            icrTrain = gl.item_content_recommender.create(newItems,
                                                          'item_id',
                                                          self._train,
                                                          'user_id',
                                                          target='rating')
            evalPrecisionRecall = icrTrain.evaluate_precision_recall(
                self._test)
            evalRMSE = icrTrain.evaluate_rmse(self._test, target='rating')
            eval = icrTrain.evaluate(self._test)
            print(eval)

        if newUsers and newObservationData:
            route = Route(recs['latitude'], recs['longitude'])
            route.map()