Commit
·
7cbefa6
1
Parent(s):
6e95f91
Top anime recommender completed
Browse files
anime_recommender/source/{collaborative_recommenders.py → collaborative_recommender.py}
RENAMED
|
@@ -4,7 +4,7 @@ from anime_recommender.exception.exception import AnimeRecommendorException
|
|
| 4 |
from anime_recommender.entity.config_entity import CollaborativeModelConfig
|
| 5 |
from anime_recommender.entity.artifact_entity import DataTransformationArtifact, CollaborativeModelArtifact
|
| 6 |
from anime_recommender.utils.main_utils.utils import load_csv_data, save_model, load_object
|
| 7 |
-
from anime_recommender.model_trainer.
|
| 8 |
|
| 9 |
class CollaborativeModelTrainer:
|
| 10 |
"""
|
|
|
|
| 4 |
from anime_recommender.entity.config_entity import CollaborativeModelConfig
|
| 5 |
from anime_recommender.entity.artifact_entity import DataTransformationArtifact, CollaborativeModelArtifact
|
| 6 |
from anime_recommender.utils.main_utils.utils import load_csv_data, save_model, load_object
|
| 7 |
+
from anime_recommender.model_trainer.collaborative_modelling import CollaborativeAnimeRecommender
|
| 8 |
|
| 9 |
class CollaborativeModelTrainer:
|
| 10 |
"""
|
anime_recommender/source/content_based_recommender.py
CHANGED
|
@@ -4,7 +4,7 @@ from anime_recommender.exception.exception import AnimeRecommendorException
|
|
| 4 |
from anime_recommender.entity.config_entity import ContentBasedModelConfig
|
| 5 |
from anime_recommender.entity.artifact_entity import ContentBasedModelArtifact, DataIngestionArtifact
|
| 6 |
from anime_recommender.utils.main_utils.utils import load_csv_data
|
| 7 |
-
from anime_recommender.model_trainer.
|
| 8 |
from anime_recommender.constant import *
|
| 9 |
|
| 10 |
class ContentBasedModelTrainer:
|
|
|
|
| 4 |
from anime_recommender.entity.config_entity import ContentBasedModelConfig
|
| 5 |
from anime_recommender.entity.artifact_entity import ContentBasedModelArtifact, DataIngestionArtifact
|
| 6 |
from anime_recommender.utils.main_utils.utils import load_csv_data
|
| 7 |
+
from anime_recommender.model_trainer.content_based_modelling import ContentBasedRecommender
|
| 8 |
from anime_recommender.constant import *
|
| 9 |
|
| 10 |
class ContentBasedModelTrainer:
|
anime_recommender/source/top_anime_recommenders.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from anime_recommender.exception.exception import AnimeRecommendorException
|
| 3 |
+
from anime_recommender.loggers.logging import logging
|
| 4 |
+
from anime_recommender.utils.main_utils.utils import load_csv_data
|
| 5 |
+
from anime_recommender.entity.artifact_entity import DataIngestionArtifact
|
| 6 |
+
from anime_recommender.model_trainer.top_anime_filtering import PopularityBasedFiltering
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class PopularityBasedRecommendor:
|
| 10 |
+
|
| 11 |
+
def __init__(self,data_ingestion_artifact = DataIngestionArtifact):
|
| 12 |
+
try:
|
| 13 |
+
self.data_ingestion_artifact = data_ingestion_artifact
|
| 14 |
+
except Exception as e:
|
| 15 |
+
raise AnimeRecommendorException(e,sys)
|
| 16 |
+
|
| 17 |
+
def initiate_model_trainer(self,filter_type:str):
|
| 18 |
+
try:
|
| 19 |
+
logging.info("Loading transformed data...")
|
| 20 |
+
df = load_csv_data(self.data_ingestion_artifact.feature_store_anime_file_path)
|
| 21 |
+
|
| 22 |
+
recommender = PopularityBasedFiltering(df)
|
| 23 |
+
|
| 24 |
+
if filter_type == 'popular_animes':
|
| 25 |
+
popular_animes = recommender.popular_animes(n =10)
|
| 26 |
+
logging.info(f"Popular Anime recommendations: {popular_animes}")
|
| 27 |
+
|
| 28 |
+
elif filter_type == 'top_ranked_animes':
|
| 29 |
+
top_ranked_animes = recommender.top_ranked_animes(n =10)
|
| 30 |
+
logging.info(f"top_ranked_animes recommendations: {top_ranked_animes}")
|
| 31 |
+
|
| 32 |
+
elif filter_type == 'overall_top_rated_animes':
|
| 33 |
+
overall_top_rated_animes = recommender.overall_top_rated_animes(n =10)
|
| 34 |
+
logging.info(f"overall_top_rated_animes recommendations: {overall_top_rated_animes}")
|
| 35 |
+
|
| 36 |
+
elif filter_type == 'favorite_animes':
|
| 37 |
+
favorite_animes = recommender.favorite_animes(n =10)
|
| 38 |
+
logging.info(f"favorite_animes recommendations: {favorite_animes}")
|
| 39 |
+
|
| 40 |
+
elif filter_type == 'top_animes_members':
|
| 41 |
+
top_animes_members = recommender.top_animes_members(n = 10)
|
| 42 |
+
logging.info(f"top_animes_members recommendations: {top_animes_members}")
|
| 43 |
+
|
| 44 |
+
elif filter_type == 'popular_anime_among_members':
|
| 45 |
+
popular_anime_among_members = recommender.popular_anime_among_members(n =10)
|
| 46 |
+
logging.info(f"popular_anime_among_members recommendations: {popular_anime_among_members}")
|
| 47 |
+
|
| 48 |
+
elif filter_type == 'top_avg_rated':
|
| 49 |
+
top_avg_rated = recommender.top_avg_rated(n =10)
|
| 50 |
+
logging.info(f"top_avg_rated recommendations: {top_avg_rated}")
|
| 51 |
+
|
| 52 |
+
except Exception as e:
|
| 53 |
+
raise AnimeRecommendorException(e,sys)
|
requirements.txt
CHANGED
|
@@ -5,4 +5,5 @@ streamlit
|
|
| 5 |
transformers
|
| 6 |
huggingface_hub
|
| 7 |
datasets
|
| 8 |
-
scikit-surprise
|
|
|
|
|
|
| 5 |
transformers
|
| 6 |
huggingface_hub
|
| 7 |
datasets
|
| 8 |
+
scikit-surprise
|
| 9 |
+
-e .
|
run_pipeline.py
CHANGED
|
@@ -3,11 +3,10 @@ from anime_recommender.loggers.logging import logging
|
|
| 3 |
from anime_recommender.exception.exception import AnimeRecommendorException
|
| 4 |
from anime_recommender.source.data_ingestion import DataIngestion
|
| 5 |
from anime_recommender.entity.config_entity import TrainingPipelineConfig,DataIngestionConfig,DataTransformationConfig,CollaborativeModelConfig,ContentBasedModelConfig
|
| 6 |
-
# ,DataTransformationConfig
|
| 7 |
from anime_recommender.source.data_transformation import DataTransformation
|
| 8 |
-
from anime_recommender.source.
|
| 9 |
from anime_recommender.source.content_based_recommender import ContentBasedModelTrainer
|
| 10 |
-
|
| 11 |
|
| 12 |
if __name__ == "__main__":
|
| 13 |
try:
|
|
@@ -36,18 +35,18 @@ if __name__ == "__main__":
|
|
| 36 |
print(collaborative_model_trainer_artifact)
|
| 37 |
|
| 38 |
# Content Based Model Training
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
|
| 52 |
except Exception as e:
|
| 53 |
raise AnimeRecommendorException(e, sys)
|
|
|
|
| 3 |
from anime_recommender.exception.exception import AnimeRecommendorException
|
| 4 |
from anime_recommender.source.data_ingestion import DataIngestion
|
| 5 |
from anime_recommender.entity.config_entity import TrainingPipelineConfig,DataIngestionConfig,DataTransformationConfig,CollaborativeModelConfig,ContentBasedModelConfig
|
|
|
|
| 6 |
from anime_recommender.source.data_transformation import DataTransformation
|
| 7 |
+
from anime_recommender.source.collaborative_recommender import CollaborativeModelTrainer
|
| 8 |
from anime_recommender.source.content_based_recommender import ContentBasedModelTrainer
|
| 9 |
+
from anime_recommender.source.top_anime_recommenders import PopularityBasedRecommendor
|
| 10 |
|
| 11 |
if __name__ == "__main__":
|
| 12 |
try:
|
|
|
|
| 35 |
print(collaborative_model_trainer_artifact)
|
| 36 |
|
| 37 |
# Content Based Model Training
|
| 38 |
+
content_based_model_trainer_config = ContentBasedModelConfig(training_pipeline_config)
|
| 39 |
+
content_based_model_trainer = ContentBasedModelTrainer(content_based_model_trainer_config=content_based_model_trainer_config,data_ingestion_artifact=data_ingestion_artifact)
|
| 40 |
+
logging.info("Initiating Content Based Model training.")
|
| 41 |
+
content_based_model_trainer_artifact = content_based_model_trainer.initiate_model_trainer()
|
| 42 |
+
logging.info("Content Based Model training completed.")
|
| 43 |
+
print(content_based_model_trainer_artifact)
|
| 44 |
|
| 45 |
+
# Popularity Based Filtering
|
| 46 |
+
logging.info("Initiating Popularity based filtering.")
|
| 47 |
+
filtering = PopularityBasedRecommendor(data_ingestion_artifact=data_ingestion_artifact)
|
| 48 |
+
popularity_recommendations = filtering.initiate_model_trainer(filter_type='top_avg_rated')
|
| 49 |
+
logging.info("Popularity based filtering completed.")
|
| 50 |
|
| 51 |
except Exception as e:
|
| 52 |
raise AnimeRecommendorException(e, sys)
|
setup.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from setuptools import find_packages, setup
|
| 2 |
+
from typing import List
|
| 3 |
+
|
| 4 |
+
def get_requirements() -> List[str] :
|
| 5 |
+
"""
|
| 6 |
+
This function returns the list of requirements
|
| 7 |
+
"""
|
| 8 |
+
requirements_lst:List[str] = []
|
| 9 |
+
try:
|
| 10 |
+
with open("requirements.txt", "r") as file:
|
| 11 |
+
lines = file.readlines()
|
| 12 |
+
for line in lines:
|
| 13 |
+
requirement = line.strip()
|
| 14 |
+
if requirement and requirement != "-e .":
|
| 15 |
+
requirements_lst.append(requirement)
|
| 16 |
+
except FileNotFoundError:
|
| 17 |
+
print("requirements.txt file not found")
|
| 18 |
+
return requirements_lst
|
| 19 |
+
|
| 20 |
+
print(get_requirements())
|
| 21 |
+
|
| 22 |
+
setup(
|
| 23 |
+
name="AnimeRecommendationSystem",
|
| 24 |
+
version= "0.0.1",
|
| 25 |
+
author= "Krishnaveni Ponna",
|
| 26 |
+
author_email= "[email protected]",
|
| 27 |
+
packages= find_packages(),
|
| 28 |
+
install_requires = get_requirements()
|
| 29 |
+
)
|