Exemplo n.º 1
0
    def fit(self, ratings):
        import hpfrec

        users = pd.Index(ratings.user.unique())
        items = pd.Index(ratings.item.unique())

        if 'rating' in ratings.columns:
            count = ratings.rating.values.copy()
        else:
            _logger.info('no ratings found, assuming 1.0')
            count = 1.0

        hpfdf = pd.DataFrame({
            'UserId': users.get_indexer(ratings.user),
            'ItemId': items.get_indexer(ratings.item),
            'Count': count
        })

        hpf = hpfrec.HPF(self.features, reindex=False, **self._kwargs)

        _logger.info('fitting HPF model with %d features', self.features)
        hpf.fit(hpfdf)

        self.user_index_ = users
        self.item_index_ = items
        self.user_features_ = hpf.Theta
        self.item_features_ = hpf.Beta

        return self
Exemplo n.º 2
0
def run_recommender(train_df, latent_factor):
    """Start the recommender."""
    recommender = hpfrec.HPF(k=latent_factor, random_seed=123,
                             allow_inconsistent_math=True, ncores=24)
    recommender.step_size = None
    logger.warning("Model is training, Don't interrupt.")
    recommender.fit(train_df)
    return recommender
Exemplo n.º 3
0
def run_recommender(train_df, latent_factors):  # pragma: no cover
    """Start the recommender."""
    recommender = hpfrec.HPF(k=latent_factors, random_seed=123,
                             ncores=-1, stop_crit='train-llk', verbose=True,
                             reindex=False, stop_thr=0.000001, maxiter=3000)
    recommender.step_size = None
    _logger.warning("Model is training, Don't interrupt.")
    recommender.fit(train_df)
    return recommender
Exemplo n.º 4
0
def train():
    print('Training HPF model')
    recommender = hpfrec.HPF(k=latent_factors,
                             random_seed=123,
                             ncores=-1,
                             stop_crit='train-llk',
                             verbose=True,
                             reindex=False,
                             stop_thr=0.000001,
                             maxiter=3000)
    recommender.step_size = None
    _logger.warning("Model is training, Don't interrupt.")
    recommender.fit(train_df)
    return recommender