{"id":31649323,"url":"https://github.com/zolppy/recommendation-system","last_synced_at":"2026-04-12T01:36:20.090Z","repository":{"id":311216954,"uuid":"1042918561","full_name":"zolppy/recommendation-system","owner":"zolppy","description":"This project demonstrates the creation of a content-based image recommendation system. It leverages a pre-trained VGG16 deep learning model to extract meaningful feature vectors from images. These features are then compared using cosine similarity to identify and recommend visually similar images.","archived":false,"fork":false,"pushed_at":"2025-08-22T20:01:45.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-12T01:35:32.486Z","etag":null,"topics":["computer-vision","deep-learning","keras","machine-learning","numpy","recommendation-system","sklearn","tensorflow","vgg16"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","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/zolppy.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-22T19:53:26.000Z","updated_at":"2025-12-27T23:56:22.000Z","dependencies_parsed_at":"2025-08-22T22:08:21.676Z","dependency_job_id":null,"html_url":"https://github.com/zolppy/recommendation-system","commit_stats":null,"previous_names":["zolppy/recomendation-system"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zolppy/recommendation-system","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zolppy%2Frecommendation-system","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zolppy%2Frecommendation-system/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zolppy%2Frecommendation-system/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zolppy%2Frecommendation-system/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zolppy","download_url":"https://codeload.github.com/zolppy/recommendation-system/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zolppy%2Frecommendation-system/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31701641,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-11T21:17:31.016Z","status":"ssl_error","status_checked_at":"2026-04-11T21:17:24.556Z","response_time":54,"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":["computer-vision","deep-learning","keras","machine-learning","numpy","recommendation-system","sklearn","tensorflow","vgg16"],"created_at":"2025-10-07T07:42:12.749Z","updated_at":"2026-04-12T01:36:19.546Z","avatar_url":"https://github.com/zolppy.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Image Recommendation System using VGG16 and Cosine Similarity\n\nThis project demonstrates the creation of a content-based image recommendation system. It leverages a pre-trained VGG16 deep learning model to extract meaningful feature vectors from images. These features are then compared using cosine similarity to identify and recommend visually similar images.\n\n## Table of Contents\n\n  - [Project Overview](#project-overview)\n  - [Dataset](#dataset)\n  - [Methodology](#methodology)\n  - [How to Run](#how-to-run)\n  - [Evaluation](#evaluation)\n  - [Dependencies](#dependencies)\n\n## Project Overview\n\nThe core idea is to transform images into a high-dimensional space where their proximity represents visual similarity. A powerful, pre-trained Convolutional Neural Network (CNN) is used for this transformation. Once images are represented as numerical vectors, we can calculate the similarity between them and build a recommendation engine.\n\nThe notebook accomplishes the following:\n\n1.  Loads and preprocesses the `tf_flowers` image dataset.\n2.  Uses a pre-trained VGG16 model on ImageNet to extract feature vectors from all images.\n3.  Implements a recommendation function based on the cosine similarity between these feature vectors.\n4.  Evaluates the recommendation system's performance using an average precision metric.\n\n## Dataset\n\nThe project uses the **`tf_flowers`** dataset, available through `tensorflow_datasets`.\n\n  - **Total Images:** 3,670\n  - **Number of Classes:** 5\n  - **Class Names:** `dandelion`, `daisy`, `tulips`, `sunflowers`, `roses`\n\nThe dataset is split as follows:\n\n  - **Training Set:** 80%\n  - **Validation Set:** 10%\n  - **Test Set:** 10%\n\n## Methodology\n\nThe workflow is divided into four main stages:\n\n1.  **Data Loading and Preprocessing:**\n\n      - Images are loaded from the `tf_flowers` dataset.\n      - Each image is resized to $224 \\\\times 224$ pixels to match the input dimensions required by the VGG16 model.\n      - Pixel values are normalized from the `[0, 255]` range to `[0, 1]`.\n      - The datasets are batched for efficient processing.\n\n2.  **Feature Extraction:**\n\n      - A VGG16 model, pre-trained on the ImageNet dataset, is loaded without its final classification layer (`include_top=False`).\n      - This base model acts as a powerful feature extractor. Each image is passed through the network, and the output from the last convolutional block is flattened to produce a high-dimensional feature vector.\n      - This process is applied to all images in the training, validation, and test sets.\n\n3.  **Similarity Calculation:**\n\n      - **Cosine Similarity** is used to measure the similarity between the feature vectors of two images. It calculates the cosine of the angle between two vectors, providing a score between -1 and 1 (or 0 and 1 for non-negative vectors). A score closer to 1 indicates higher similarity.\n      - The formula for cosine similarity between two vectors $A$ and $B$ is:\n        $$\\text{similarity} = \\cos(\\theta) = \\frac{A \\cdot B}{\\|A\\| \\|B\\|}$$\n\n4.  **Recommendation and Evaluation:**\n\n      - To test the system, random images are selected from the test set to act as queries.\n      - For each query image, its feature vector is compared against the feature vectors of all images in the training set.\n      - The images from the training set with the highest cosine similarity scores are returned as recommendations.\n\n## How to Run\n\n1.  **Clone the repository or download the `main.ipynb` file.**\n\n2.  **Install the necessary dependencies.** You can install them using pip:\n\n    ```bash\n    pip install numpy tensorflow tensorflow-datasets matplotlib scikit-learn\n    ```\n\n3.  **Open and run the notebook.**\n\n      - Open the `main.ipynb` file in a Jupyter environment such as JupyterLab, Jupyter Notebook, or Google Colab.\n      - Execute the cells in sequential order. The notebook will automatically download the dataset, build the model, extract features, and run the evaluation.\n\n## Evaluation\n\nThe performance of the recommendation system is evaluated using **Average Precision**.\n\nFor each query image from the test set:\n\n1.  The system retrieves the top 10 most similar images from the training set.\n2.  **Precision** is calculated as the proportion of these 10 recommended images that belong to the same class as the query image.\n    $$\\text{Precision} = \\frac{\\text{Number of relevant recommendations}}{\\text{Total number of recommendations}}$$\n3.  The **Average Precision** is the mean of the precision scores calculated for all query images. This final score provides a measure of the system's ability to retrieve visually similar and semantically relevant images.\n\nThe notebook's output includes the precision score for each query and the final average precision, along with a brief discussion of the result.\n\n## Dependencies\n\n  - `Python 3.x`\n  - `numpy`\n  - `tensorflow`\n  - `tensorflow_datasets`\n  - `matplotlib`\n  - `scikit-learn`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzolppy%2Frecommendation-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzolppy%2Frecommendation-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzolppy%2Frecommendation-system/lists"}