def run( features, item_features_matrix, interactions, user_features, user_features_matrix, cf_model, lsiup_model, n_iter, test_size, cold_start, learning_rate, no_components, a_alpha, b_alpha, epochs, ): logger.debug("Fitting the model with %s", locals()) no_interactions = len(interactions.data) if cf_model: logger.info("Fitting the CF model") modelfnc = lambda: CFModel(dim=no_components) elif lsiup_model: logger.info("Fitting the LSI-UP model") modelfnc = lambda: LsiUpModel(dim=no_components) else: modelfnc = lambda: LightFM( learning_rate=learning_rate, no_components=no_components, item_alpha=a_alpha, user_alpha=b_alpha ) model, auc = fit_model( interactions=interactions, item_features_matrix=item_features_matrix, n_iter=n_iter, epochs=epochs, modelfnc=modelfnc, test_size=test_size, cold_start=cold_start, user_features_matrix=user_features_matrix, ) logger.debug("Average AUC: %s", auc) if not cf_model and not lsiup_model: model.add_item_feature_dictionary(features.feature_ids, check=False) try: # Can only get similar tags if we have tag features test_features = ("tag:bic", "tag:survival", "tag:regression", "tag:mcmc") for test_feature in test_features: logger.debug( "Features most similar to %s: %s", test_feature, model.most_similar(test_feature, "item", number=10) ) except KeyError: pass return auc
def run(features, item_features_matrix, interactions, user_features, user_features_matrix, cf_model, lsiup_model, n_iter, test_size, cold_start, learning_rate, no_components, a_alpha, b_alpha, epochs): logger.debug('Fitting the model with %s', locals()) no_interactions = len(interactions.data) if cf_model: logger.info('Fitting the CF model') modelfnc = lambda: CFModel(dim=no_components) elif lsiup_model: logger.info('Fitting the LSI-UP model') modelfnc = lambda: LsiUpModel(dim=no_components) else: modelfnc = lambda: LightFM(learning_rate=learning_rate, no_components=no_components, item_alpha=a_alpha, user_alpha=b_alpha) model, auc = fit_model(interactions=interactions, item_features_matrix=item_features_matrix, n_iter=n_iter, epochs=epochs, modelfnc=modelfnc, test_size=test_size, cold_start=cold_start, user_features_matrix=user_features_matrix) logger.debug('Average AUC: %s', auc) if not cf_model and not lsiup_model: model.add_item_feature_dictionary(features.feature_ids, check=False) try: # Can only get similar tags if we have tag features test_features = ('tag:bic', 'tag:survival', 'tag:regression', 'tag:mcmc') for test_feature in test_features: logger.debug('Features most similar to %s: %s', test_feature, model.most_similar(test_feature, 'item', number=10)) except KeyError: pass return auc
def run(features, item_features_matrix, interactions, cf_model, lsiup_model, n_iter, test_size, cold_start, learning_rate, no_components, a_alpha, b_alpha, epochs): logger.debug('Fitting the model with %s', locals()) no_interactions = len(interactions.data) if cf_model: logger.info('Fitting the CF model') modelfnc = lambda: CFModel(dim=no_components) elif lsiup_model: logger.info('Fitting the LSI-UP model') modelfnc = lambda: LsiUpModel(dim=no_components) else: modelfnc = lambda: LightFM(learning_rate=learning_rate, no_components=no_components, item_alpha=a_alpha, user_alpha=b_alpha) model, auc = fit_model(interactions=interactions, item_features_matrix=item_features_matrix, n_iter=n_iter, epochs=epochs, modelfnc=modelfnc, test_size=test_size, cold_start=cold_start) logger.debug('Average AUC: %s', auc) if not cf_model and not lsiup_model: model.add_item_feature_dictionary(features.feature_ids, check=False) features.add_latent_representations(model.item_features) titles = ('Lord of the Rings: The Two Towers, The (2002)', 'Toy Story (1995)', 'Terminator, The (1984)', 'Europa Europa (Hitlerjunge Salomon) (1990)') for title in titles: logger.debug('Most similar movies to %s: %s', title, features.most_similar_movie(title, number=20)) # Can only get similar tags if we have tag features test_features = ('genome:art house', 'genome:dystopia', 'genome:bond') for test_feature in test_features: try: logger.debug('Features most similar to %s: %s', test_feature, model.most_similar(test_feature, 'item', number=10)) except KeyError: pass return auc