{"id":13492500,"url":"https://github.com/RiccardoAncarani/python_recommender_system","last_synced_at":"2025-03-28T10:32:13.520Z","repository":{"id":117601473,"uuid":"87635407","full_name":"RiccardoAncarani/python_recommender_system","owner":"RiccardoAncarani","description":"A simple user-based collaborative filtering recommender system, built with Python and Flask","archived":false,"fork":false,"pushed_at":"2017-04-08T15:52:53.000Z","size":26,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-31T06:35:01.015Z","etag":null,"topics":["collaborative-filtering","flask","information-retrieval","machine-learning","python","recommendation-engine","recommender-system"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RiccardoAncarani.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-04-08T13:22:20.000Z","updated_at":"2022-02-18T19:53:34.000Z","dependencies_parsed_at":"2024-01-16T09:52:41.242Z","dependency_job_id":"ac7650fb-e9b5-4aa2-aed3-18e5fe678b5b","html_url":"https://github.com/RiccardoAncarani/python_recommender_system","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RiccardoAncarani%2Fpython_recommender_system","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RiccardoAncarani%2Fpython_recommender_system/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RiccardoAncarani%2Fpython_recommender_system/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RiccardoAncarani%2Fpython_recommender_system/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RiccardoAncarani","download_url":"https://codeload.github.com/RiccardoAncarani/python_recommender_system/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246012579,"owners_count":20709469,"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","flask","information-retrieval","machine-learning","python","recommendation-engine","recommender-system"],"created_at":"2024-07-31T19:01:06.618Z","updated_at":"2025-03-28T10:32:11.855Z","avatar_url":"https://github.com/RiccardoAncarani.png","language":"Python","readme":"# Python Recommender System\n## A small (and still buggy) framework for product recommendations\n### Still in dev.\n\n# Theory\nThis recommender system uses a technique called **User Based Collaborative filtering**.\n\nA user based collaborative filter is a kind of filter that recommends products to a user that users like him bought. \n\nMathematically speaking, in this model each user is a N-dimensional vector, where N is the number of products in the dataset, the similarity between two users is measured via cosine, that ranges from -1 to +1.\n\n- +1 means that the two users have the same purchcase history\n- -1 means that the two users have the opposite purchcase history\n\n# Implementation\nThis framework is built with Flask, and uses SQLAlchemy for ORM\n\n# Endpoints\n## /api/new/customer/name\nInsert a new customer into the DB\n\n```bash\ncurl http://127.0.0.1:5000/api/new/customer/riccardo\n{ \"status\" : \"insert ok\" }\n\n```\n\n## /api/new/item/name\nInsert a new item into the DB\n\n```bash\ncurl http://127.0.0.1:5000/api/new/item/hammer\n{ \"status\" : \"insert ok\" }\n```\n\n## /api/new/purchcase/customer/item\nInsert a new event, customer bought item\n\n```bash\ncurl http://127.0.0.1:5000/api/new/purchcase/riccardo/hammer\n{ \"status\" : \"insert ok\" }\n```\n\n## /api/predict/customer\nGet a prediction for the user named customer, return the vector of the nearest user with similar purchcases, this is still dev. but in the final version this API will return the names of the items that are recommended for customer.\n\nNow it just consider the nearest user, but the assumption that the nearest user necessarily has *more* items than customer is just wrong, I'll implement it ASAP.\n\n```bash\ncurl http://127.0.0.1:5000/api/predict/riccardo\n{ \"response\" : \"apparently meaningless vector\" }\n```\n\n## /api/update_matrix\nThis API update the global matrix that holds all the user vectors.\n\nHis aim is to provide a manual way to keeping the matrix updated just when is needed, otherwise the matrix would be rebuilt every insertion into the DB.\n\n```bash\ncurl http://127.0.0.1:5000/api/update_matrix\n{ \"response\" : \"Matrix updated\" }\n```\n\n\nIf you look at the source, there are more endpoints but they are just for debugging purpose.\n\n# Defining how the matrix is sensitive to updates\nYou'll have to keep the global matrix updated, otherwise this system is pretty useless.\n\nI choose to have a buffer of insert operation before the matrix is rebuilt, you have the freedom to edit this parameter in order to meet your needs:\n\n```python\n...\nbuffer = 2 # This is the number of insert events before an update\nevents = 0 # This is the global counter of insert events\n...\n```\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRiccardoAncarani%2Fpython_recommender_system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRiccardoAncarani%2Fpython_recommender_system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRiccardoAncarani%2Fpython_recommender_system/lists"}