<commit_before>from tensorrec import TensorRec
from tensorrec.eval import fit_and_eval
from tensorrec.loss_graphs import RMSEDenseLossGraph, SeparationLossGraph, SeparationDenseLossGraph, WMRBLossGraph, \
    WMRBAlignmentLossGraph
from test.datasets import get_movielens_100k

import logging
logging.getLogger().setLevel(logging.INFO)

train_interactions, test_interactions, user_features, item_features = get_movielens_100k(negative_value=0)

epochs = 300
alpha = 0.00001
n_components = 10
biased = False
verbose = True
learning_rate = .1

n_sampled_items = int(item_features.shape[0] * .01)

fit_kwargs = {'epochs': epochs, 'alpha': alpha, 'verbose': verbose, 'learning_rate': learning_rate,
              'n_sampled_items': n_sampled_items}

model_baseline = TensorRec(n_components=n_components, biased=biased)
rmse_result = fit_and_eval(model_baseline, user_features, item_features, train_interactions, test_interactions,
                           fit_kwargs)
print("RMSE: \t\t%s, \t%s" % rmse_result)

model_baseline = TensorRec(n_components=n_components, biased=biased, loss_graph=RMSEDenseLossGraph)
rmse_dense_result = fit_and_eval(model_baseline, user_features, item_features, train_interactions, test_interactions,
                                 fit_kwargs)
print("RMSEDense: \t%s, \t%s" % rmse_dense_result)

model_baseline = TensorRec(n_components=n_components, biased=biased, loss_graph=SeparationLossGraph)
sep_result = fit_and_eval(model_baseline, user_features, item_features, train_interactions, test_interactions,
                          fit_kwargs)
print("Separation: \t%s, \t%s" % sep_result)

model_baseline = TensorRec(n_components=n_components, biased=biased, loss_graph=SeparationDenseLossGraph)
sep_dense_result = fit_and_eval(model_baseline, user_features, item_features, train_interactions, test_interactions,
                                fit_kwargs)
print("SepDense: \t%s, \t%s" % sep_dense_result)

model_wmrb = TensorRec(n_components=n_components, biased=biased, loss_graph=WMRBLossGraph)
wmrb_result = fit_and_eval(model_wmrb, user_features, item_features, train_interactions, test_interactions,
                           fit_kwargs)
print("WMRB: \t\t%s, \t%s" % wmrb_result)

model_wmrb = TensorRec(n_components=n_components, biased=biased, loss_graph=WMRBAlignmentLossGraph)
wmrb_alignment_result = fit_and_eval(model_wmrb, user_features, item_features, train_interactions, test_interactions,
                                     fit_kwargs)
print("WMRBAlignment: \t%s, \t%s" % wmrb_alignment_result)

print('--------------------------------------------------')
print("RMSE: \t\t%s, \t%s" % rmse_result)
print("RMSEDense: \t%s, \t%s" % rmse_dense_result)
print("Separation: \t%s, \t%s" % sep_result)
print("SepDense: \t%s, \t%s" % sep_dense_result)
print("WMRB: \t\t%s, \t%s" % wmrb_result)
print("WMRBAlignment: \t%s, \t%s" % wmrb_alignment_result)<commit_msg>MAINT: Refactors movielens script<commit_after>from tensorrec import TensorRec
from tensorrec.eval import fit_and_eval
from tensorrec.loss_graphs import (
    RMSELossGraph, RMSEDenseLossGraph, SeparationLossGraph, SeparationDenseLossGraph, WMRBLossGraph
)
from tensorrec.prediction_graphs import DotProductPredictionGraph, CosineDistancePredictionGraph
from test.datasets import get_movielens_100k

import logging
logging.getLogger().setLevel(logging.INFO)

train_interactions, test_interactions, user_features, item_features = get_movielens_100k(negative_value=0)

epochs = 300
alpha = 0.00001
n_components = 10
biased = True
verbose = True
learning_rate = .1

n_sampled_items = int(item_features.shape[0] * .01)

fit_kwargs = {'epochs': epochs, 'alpha': alpha, 'verbose': verbose, 'learning_rate': learning_rate,
              'n_sampled_items': n_sampled_items}

res_strings = []

for loss_graph in (RMSELossGraph, RMSEDenseLossGraph, SeparationLossGraph, SeparationDenseLossGraph, WMRBLossGraph):
    for pred_graph in (DotProductPredictionGraph, CosineDistancePredictionGraph):

        model = TensorRec(n_components=n_components, biased=biased, loss_graph=loss_graph(),
                          prediction_graph=pred_graph())
        result = fit_and_eval(model, user_features, item_features, train_interactions, test_interactions, fit_kwargs)

        res_string = "{}".format(loss_graph.__name__)
        for _ in range(0, (30 - len(res_string))):
            res_string += " "
        res_string += "{}".format(pred_graph.__name__)
        for _ in range(0, (60 - len(res_string))):
            res_string += " "
        res_string += ": \t{} \t{}".format(result[0], result[1])

        print(res_string)
        res_strings.append(res_string)

print('--------------------------------------------------')
for res_string in res_strings:
    print(res_string)
{'fraction_non_alphanumeric': 0.12067881835323696, 'fraction_numerical': 0.010894615545778337, 'mean_word_length': 4.431171786120592, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5369322', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1539, 'n_words': 283}