<jupyter_start><jupyter_text>Loading dataset<jupyter_code>from beta_rec.datasets.movielens import Movielens_100k
from beta_rec.data import BaseData
dataset = Movielens_100k()
split_dataset = dataset.load_leave_one_out(n_test=1)
data =  BaseData(split_dataset)<jupyter_output>download_file: url: http://files.grouplens.org/datasets/movielens/ml-100k.zip, raw_file_path: /Users/zaiqiao/anaconda3/lib/python3.7/site-packages/beta_rec-0.2.1-py3.7.egg/datasets/ml_100k/raw/ml_100k.zip
Start downloading file ml-100k.zip with url http://files.grouplens.org/datasets/movielens/ml-100k.zip...<jupyter_text>Model config<jupyter_code>config = {
    "config_file":"../configs/mf_default.json"
}
# the 'config_file' key is required, that is used load a default config. Other keys can be specified to replace the default settings.<jupyter_output><empty_output><jupyter_text>Model intialization and training<jupyter_code>from beta_rec.recommenders import MatrixFactorization
model = MatrixFactorization(config)
model.train(data)

# @To be discussed
# model.train(train_df) # Case 1, without validation, stop training by loss or max_epoch
# model.train(train_df,valid_df[0]) # Case 2, with validation, stop training by performance on validation set
# model.train(train_df,valid_df[0],test_df[0])  # Case 3, same as Case 2, but also evaluate performance for each epoch on test set.

## Note that the best model will be save automatically, and record the model-save-dir.<jupyter_output>loading config file ../configs/mf_default.json
--------------------------------------------------------------------------------
Received parameters from command line (or default):
+--------+----------+
| keys   | values   |
|--------+----------|
+--------+----------+
--------------------------------------------------------------------------------
logs will save in file: /Users/zaiqiao/Workspace/beta_rec/logs/MF_default_20201004_232119_rpvtin .stdout.log .stderr.log
2020-10-04 23:21:19 [INFO]-
Python version: 3.7.6 (default, Jan  8 2020, 13:42:34) 
[Clang 4.0.1 (tags/RELEASE_401/final)
2020-10-04 23:21:19 [INFO]-
2020-10-04 23:21:19 [INFO]-pytorch version: 1.6.0
2020-10-04 23:21:19 [INFO]-The intermediate running statuses will be reported in folder: /Users/zaiqiao/Workspace/beta_rec/runs/MF_default_20201004_232119_rpvtin
2020-10-04 23:21:19 [INFO]-Model checkpoint will save in file: /Users/zaiqiao/Workspace/beta_rec/checkpoints/MF_default_20201004_232119_rpvtin
2020-10-04 23:21:19 [INFO[...]<jupyter_text>Model trainng<jupyter_code>model.test(data.test[0])<jupyter_output><empty_output><jupyter_text>Load a pre-trained Model, and Predict for new dataset<jupyter_code>from beta_rec.recommenders import MatrixFactorization
config = {
    "config_file":"../configs/mf_default.json",
}
# model_dir = model.config["system"]["model_save_dir"] # default saving dir for current model
model_dir = "/home/zm324/workspace/beta_rec/checkpoints/MF_default_20200912_173445_gccwwj/mf.model" # a specfic model
model = MatrixFactorization(config)
model.init_engine(data) 
# this is necessary, since we cannot intialize a model before we get the the numbers of users and items

model.load(model_dir = model_dir)
scores = model.predict(data.test[0])
scores
scores.shape<jupyter_output><empty_output><jupyter_text>Model tuning<jupyter_code>## Before using tune, you need to install beta_rec to your local python lib
## E.g. go to the project folder, run:
## python setup.py install --record files.txt

## if something wrong, you can uninstall by: xargs rm -rf < files.txt
from beta_rec.datasets.movielens import Movielens_100k
from beta_rec.data import BaseData
dataset = Movielens_100k()
split_dataset = dataset.load_leave_one_out(n_test=1)
data =  BaseData(split_dataset)

config = {
    "config_file":"../configs/mf_default.json",
    "tune":True,
    "max_epoch":2
}
from beta_rec.recommenders import MatrixFactorization
model = MatrixFactorization(config)
tune_result = model.train(data)
tune_result<jupyter_output><empty_output><jupyter_text>Note that ray version should be 0.8.5.<jupyter_code>import ray
ray.__version__
ray.init()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15593220338983052, 'fraction_numerical': 0.05230024213075061, 'mean_word_length': 4.357976653696498, 'pattern_counts': {'":': 5, '<': 28, '<?xml version=': 0, '>': 27, '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}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '33404', 'license': 'MIT', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1373, 'n_words': 310, 'path': 'examples/MF_API_test.ipynb', 'repo_name': 'leungyukshing/beta-recsys', 'size': '4130'}