| """ | |
| Training script for DataSynthis_ML_JobTask model. | |
| This script trains the model and saves it for deployment. | |
| """ | |
| from model import MovieRecommender | |
| import os | |
| def main(): | |
| """Train and save the movie recommendation model.""" | |
| print("Starting model training...") | |
| # Initialize model | |
| model = MovieRecommender() | |
| # Train the model | |
| model.train() | |
| # Save the trained model | |
| model.save_model("movie_recommender.pkl") | |
| print("Model training completed and saved!") | |
| # Test the model | |
| print("\nTesting model with user ID 1...") | |
| recommendations = model.recommend_movies(user_id=1, n_recommendations=5, method="svd") | |
| print("Sample recommendations:") | |
| for rec in recommendations: | |
| print(f"- {rec['title']} (ID: {rec['movie_id']}, Rating: {rec['predicted_rating']:.2f})") | |
| print(f"\nAvailable users: {len(model.get_available_users())}") | |
| print(f"User ID range: {min(model.get_available_users())} - {max(model.get_available_users())}") | |
| if __name__ == "__main__": | |
| main() |