{"id":46843301,"url":"https://github.com/saheedniyi02/krecommend","last_synced_at":"2026-03-10T14:01:35.295Z","repository":{"id":57698001,"uuid":"493982713","full_name":"saheedniyi02/krecommend","owner":"saheedniyi02","description":"A python package for creating content-based text recommender systems on pandas dataframes and SQLAlchemy tables","archived":false,"fork":false,"pushed_at":"2022-06-07T09:38:42.000Z","size":846,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-28T09:26:25.950Z","etag":null,"topics":["cosine-similarity","flask-sqlalchemy","nlp","numpy","pandas","python","recommendation-algorithms","recommendation-engine","recommendation-system","recommender-system","scikit-learn","sql","sqlalchemy","sqlite3","tfidf-vectorizer"],"latest_commit_sha":null,"homepage":"","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/saheedniyi02.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-19T08:21:05.000Z","updated_at":"2022-06-09T13:17:37.000Z","dependencies_parsed_at":"2022-09-26T21:02:00.094Z","dependency_job_id":null,"html_url":"https://github.com/saheedniyi02/krecommend","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/saheedniyi02/krecommend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saheedniyi02%2Fkrecommend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saheedniyi02%2Fkrecommend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saheedniyi02%2Fkrecommend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saheedniyi02%2Fkrecommend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saheedniyi02","download_url":"https://codeload.github.com/saheedniyi02/krecommend/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saheedniyi02%2Fkrecommend/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30336057,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T12:41:07.687Z","status":"ssl_error","status_checked_at":"2026-03-10T12:41:06.728Z","response_time":106,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cosine-similarity","flask-sqlalchemy","nlp","numpy","pandas","python","recommendation-algorithms","recommendation-engine","recommendation-system","recommender-system","scikit-learn","sql","sqlalchemy","sqlite3","tfidf-vectorizer"],"created_at":"2026-03-10T14:00:50.883Z","updated_at":"2026-03-10T14:01:35.285Z","avatar_url":"https://github.com/saheedniyi02.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003ca href=\"https://github.com/saheedniyi02/krecommend\"\u003ekrecommend\u003c/a\u003e\nA python package for creating content-based text recommender systems on pandas dataframes and SQLAlchemy tables.\n\nThe recommendations are gotten by using cosine similarity to get similar items to a requested item and the top k similar items are then recommended.\n### Dependencies\nkrecommend requires the following dependencies:\n\n\u003cul\u003e\u003cli\u003ePython\u003c/li\u003e\n\u003cli\u003eNumPy\u003c/li\u003e\n\u003cli\u003eSciPy\u003c/li\u003e\n\u003cli\u003eScikit-learn\u003c/li\u003e\n\u003cli\u003ePandas for dealing with dataframes\u003c/li\u003e\n\u003cli\u003eSQLAlchemy for dealing with SQL tables\u003c/li\u003e\u003c/ul\u003e\n\n## Installation\nInstallation can be done with `pip`:\n```shell\n$ pip install krecommend\n```\n## How to use \nThe detailed examples can be found \u003ca href=\"https://github.com/saheedniyi02/Test-krecommend\"\u003ehere\u003c/a\u003e\n#### For a pandas data frame.\n#Provided with a simple dataframe with index \"id\" ,\ntext (string) columns \"title\" and \"content\",\"int\" column \"Views\".\n\n##### load the dataframe\n```py\nimport pandas as pd\ndataframe = pd.read_csv(\"file_path\", index_col=0)\n#set the id as the index\ndataframe.set_index(\"id\")\n```\n##### import,initialize and fit on a pandas dataframe\n```py\nrecommender = KRecommend(k=2)\nrecommender.fit(dataframe, text_columns=[\"content\",\"title\"])\n\n```\n##### get recommendations.\n```py\ntest_content=\"This is a test content\"\ntest_title=\"This is a test title\"\n#the .predict method accepts lists only, even if the length is 1.\nrecommendations=recommender.predict(test=[test_content,test_title])\n```\n\nThe returned recommendations is a simple python dictionary with length (k, the number of requested recommendations)\\\nEach key in the dictionary represents the index (value of the \"id\" in this case) of that particular\nrecommendation in the dataframe, while the value represents the similarity (in %),The items in the dictionary are arranged in descending order of the similarity.\n\n\n\n\n#### For an SQL alchemy table.\n##### A simple SQLAlchemy table (ensure you add items to your table)\n```py\nfrom curses import meta\nfrom sqlalchemy import create_engine, MetaData, Column, Integer, String, Table\n\n#database engine\nengine = create_engine(\"sqlite:///database.db\", echo=True)\nmeta = MetaData()\n\n\n\"\"\"a table with name 'Posts', primary_key 'id', text (string) columns 'title' and 'content' and Int column 'views' \"\"\"\nposts = Table(\n    \"Posts\",\n    meta,\n    Column(\"id\", Integer, primary_key=True),\n    Column(\"title\", String),\n    Column(\"content\", String),\n    Column(\"views\",Integer)\n)\n\n\n\n```\n###### import,initialize and fit on SQLAlchemy table\n```py\n#database connection\nconnection = engine.connect()\nfrom krecommend.recommend import KRecommend\n#k represents the number of documents to be recommend\nrecommender = KRecommend(k=4)\nrecommender.fit_on_sql_table(table_name=\"Posts\",id_column= \"id\",text_columns=[\"content\",\"title\"],connection= connection)\n#close connection\nconnection.close()\n```\n\n###### get recommendations.\n```py\ntest_content=\"This is a test content\"\ntest_title=\"This is a test title\"\n#the .predict_on_sql_table method accepts lists only, even if the length is 1.\nrecommendations=recommender.predict_on_sql_table(test=[test_content,test_title])\n```\nThe returned recommendations is a simple python dictionary with length (k, the number of requested recommendations)\\\nEach key in the dictionary represents the primary_key of that particular\nrecommendation in the database, while the value represents the similarity (in %).The items in the dictionary are arranged in descending order of the similarity.\n\n\n\nThe primary key can then be used to query the table to get more information on the recommendations.\n\n\n\n#### For a flask-sqlalchemy table\n###### create the simple Flask-SQLAlchemy table (ensure you add items to your table)\n```py\nfrom flask import Flask\nfrom flask_sqlalchemy import SQLAlchemy\n\napp = Flask(__name__)\napp.config[\"SQLALCHEMY_DATABASE_URI\"] = \"sqlite:///database.db\"\ndb = SQLAlchemy(app)\n\n\"\"\"a table with name 'Posts', primary_key 'id', text (string) columns 'title' and 'content' and Int column 'views' \"\"\"\nclass Posts(db.Model):\n    __tablename__=\"Posts\"\n    id = db.Column(db.Integer, primary_key=True)\n    title = db.Column(db.String(64))\n    content = db.Column(db.String(64))\n    views = db.Column(db.Integer, unique=True, index=True, nullable=False)\n\n```\n\n###### import,initialize and fit on SQLAlchemy table\n```py\n\nfrom krecommend.recommend import KRecommend\n#k represents the number of documents to be recommend\n#database connection\nconnection=db.engine.connect()\nrecommender = KRecommend(k=4)\nrecommender.fit_on_sql_table(table_name=\"Posts\",id_column= \"id\",text_columns=[\"content\",\"title\"],connection= connection)\n#close connection\nconnection.close()\n```\nThe recommendations can easily be gotten using the `.predict_on_sql_table` as seen above.\n\n#### Warning and possible sources of error\n\u003col\u003e\u003cli\u003eOnly text columns are accepted in the text_columns parameter.\nInteger or float columns will return an error.\u003c/li\u003e\u003cbr\u003e\n\u003cli\u003eKRecommend only saves information on your table at the time it is fitted, any information on your table added after\nKRecommend has been fitted won't exist in the recommendations generated.\n\u003cul\u003e\u003cli\u003eImplications: \u003col\u003e\u003cli\u003eA recommendation might have been deleted (after fitting) from the table as at the time it is being recommend so it might no longer be found in the database.\u003c/li\u003e\n              \u003cli\u003eSome content might have been modified which might affect the strength of the recommendations.\u003cli\u003e\u003c/li\u003e\u003c/ol\u003e\n\u003cli\u003eSolution: it is important to fit KRecommend again at intervals,so changes in contents will be reflected in the recommendations.For example you can schedule  the `.fit_on_sql_table` method to run every hour (or any interval of your choice)\u003c/li\u003e\u003c/li\u003e\u003c/ul\u003e\n\u003cli\u003eIt is good practice to close the connection after fitting.\u003c/li\u003e\n\u003cli\u003eThere must be k+1 (k represents the requested no of recommendations) items in the requested table.\u003c/li\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaheedniyi02%2Fkrecommend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaheedniyi02%2Fkrecommend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaheedniyi02%2Fkrecommend/lists"}