{"id":16260165,"url":"https://github.com/twolodzko/tfmf","last_synced_at":"2025-03-19T22:31:06.505Z","repository":{"id":66164763,"uuid":"138872059","full_name":"twolodzko/tfmf","owner":"twolodzko","description":"Collaborative Filtering Using Matrix Factorization in TensorFlow","archived":false,"fork":false,"pushed_at":"2018-11-21T13:09:23.000Z","size":29,"stargazers_count":9,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T11:50:38.578Z","etag":null,"topics":["collaborative-filtering","machine-learning","python","tensorflow"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twolodzko.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-27T11:25:11.000Z","updated_at":"2020-11-21T14:13:07.000Z","dependencies_parsed_at":"2023-04-05T11:16:18.512Z","dependency_job_id":null,"html_url":"https://github.com/twolodzko/tfmf","commit_stats":{"total_commits":23,"total_committers":3,"mean_commits":7.666666666666667,"dds":"0.13043478260869568","last_synced_commit":"7b3fcff0b6fb3e40a835d599b4e91892d64c5b2f"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twolodzko%2Ftfmf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twolodzko%2Ftfmf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twolodzko%2Ftfmf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twolodzko%2Ftfmf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twolodzko","download_url":"https://codeload.github.com/twolodzko/tfmf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244515636,"owners_count":20464923,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["collaborative-filtering","machine-learning","python","tensorflow"],"created_at":"2024-10-10T16:06:35.105Z","updated_at":"2025-03-19T22:31:06.499Z","avatar_url":"https://github.com/twolodzko.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"This package implements ``MatrixFactorizer`` class for collaborative filtering\nusing matrix factorization with implicit (Hu et al, 2008) and explicit ratings\n(Koren et al, 2009, Yu et al, 2012). The ``MatrixFactorizer`` class works with\nsparse data (scipy.sparse_ matrices) and uses TensorFlow_ as a workhorse. The\ntrained models can be easily saved and restored.\n\nExample\n-------\n\nBelow an example of using ``MatrixFactorizer`` class for explicit ratings is shown.\nThe data is converted to to ``scipy.sparse.dok_matrix`` format using the\n``sparse_matrix`` function provided in the package as a convenience wraper.\n\n.. code-block:: python\n\n   import numpy as np\n   from tfmf import MatrixFactorizer, sparse_matrix\n\n   user_id = [0,0,1,1,2,2]\n   movie_id = [0,1,2,0,1,2]\n   rating = [1,1,2,2,3,3]\n   X = sparse_matrix(user_id, movie_id, rating)\n\nThe model is trained using the ``fit`` method. We choose to use two latent dimmensions\nand random batches of size 4 for the training. To make predictions from the model, we\nuse ``predict_all`` method that makes predictions for the whole factorized matrix\n(or slices of it), but more standard choice would be to use ``predict(user_ids, item_ids)``\nmethod for making predictions for individual users and items.\n\n.. code-block:: python\n\n   mf = MatrixFactorizer(n_components=2, batch_size=4, implicit=False)\n   mf.fit(X)\n   mf.predict_all().A\n   ## array([[1.013387 , 1.0056534, 1.11131  ],\n   ##        [1.926976 , 1.8363876, 1.9962051],\n   ##        [1.9263643, 2.969007 , 2.9673567]], dtype=float32)\n   X.A\n   ## array([[1, 1, 0],\n   ##        [2, 0, 2],\n   ##        [0, 3, 3]])\n\nThe learned parameters are saved to temporary directory.\n\n.. code-block:: python\n\n   import tempfile\n   tmpdir = tempfile.gettempdir()\n   mf.save(tmpdir + '/tfmf')\n\nNext, we initialize the class once again. Using the ``init_with_shape`` method,\n``MatrixFactorizer`` class is set-up to model the matrix of shape (n_users, n_items)\nwith randomly initialized parameters. Predictions from such model are meaningless,\nbecause it wasn't trained yet.\n\n.. code-block:: python\n\n   mf = MatrixFactorizer(n_components=2, batch_size=4, implicit=False)\n   mf.init_with_shape(3, 3)\n   mf.predict_all().A\n   ## array([[ 4.6303128e-05, -5.7351419e-05,  1.7567796e-05],\n   ##        [-1.0485943e-04,  6.2389910e-05, -3.7540267e-05],\n   ##        [-1.2580390e-04, -2.4326339e-04, -3.4460012e-05]], dtype=float32)\n\nInstead of training, we resore the previously learned parameters. Such restored model\ncan be trained further using the ``partial_fit`` method, or used to make predictions.\n\n.. code-block:: python\n\n   mf.restore(tmpdir + '/tfmf')\n   mf.predict_all().A\n   ## array([[1.013387 , 1.0056534, 1.11131  ],\n   ##        [1.926976 , 1.8363876, 1.9962051],\n   ##        [1.9263643, 2.969007 , 2.9673567]], dtype=float32)\n\nReferences\n----------\n\nKoren, Y., Bell, R., \u0026 Volinsky, C. (2009).\nMatrix factorization techniques for recommender systems. Computer, 42(8).\n\nYu, H. F., Hsieh, C. J., Si, S., \u0026 Dhillon, I. (2012, December).\nScalable coordinate descent approaches to parallel matrix factorization for recommender systems.\nIn Data Mining (ICDM), 2012 IEEE 12th International Conference on (pp. 765-774). IEEE.\n\nHu, Y., Koren, Y., \u0026 Volinsky, C. (2008, December).\nCollaborative filtering for implicit feedback datasets.\nIn Data Mining, 2008. ICDM'08. Eighth IEEE International Conference on (pp. 263-272). IEEE.\n\n\n.. _scipy.sparse: https://docs.scipy.org/doc/scipy/reference/sparse.html\n.. _TensorFlow: http://tensorflow.org/","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwolodzko%2Ftfmf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwolodzko%2Ftfmf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwolodzko%2Ftfmf/lists"}