Machine Learning Movie Recommendation System Project

Machine Learning project 07

Machine Learning Movie Recommendation System Project

Build and evaluate a complete movie recommendation system workflow with reproducible Python code, explicit metrics, and honest limitations.

Explore Machine Learning training in VizagView all project ideas

Dataset and objective

A small embedded table of users, movie titles, and explicit 1-5 ratings.

Skills practised

  • User-item matrices
  • Cosine similarity
  • Item-based recommendations
  • Cold-start limitations

Requirements

  • Python 3.10 or later
  • A terminal or command prompt
  • python -m pip install pandas scikit-learn
  • About 45-60 minutes to build and review

Machine Learning workflow

  1. Data: A small embedded table of users, movie titles, and explicit 1-5 ratings.
  2. Preprocessing: A movie-by-user matrix fills missing interactions with zero for this compact item-similarity demonstration.
  3. Model: Cosine similarity ranks movies with rating patterns closest to the selected title.
  4. Evaluation: The script returns the three highest-scoring different titles; production ranking needs offline and online evaluation beyond this toy table.

Complete Python code

Save the code as ml_movie_recommendation.py. The random state and data handling are included so the result can be reproduced and reviewed.

"""Recommend movies with item-item cosine similarity on example ratings."""

from __future__ import annotations

import pandas as pd
from sklearn.metrics.pairwise import cosine_similarity


RATINGS = [
    ("Asha", "Arrival", 5), ("Asha", "Interstellar", 5), ("Asha", "Toy Story", 3),
    ("Bala", "Arrival", 4), ("Bala", "Interstellar", 5), ("Bala", "The Martian", 5),
    ("Chen", "Toy Story", 5), ("Chen", "Finding Nemo", 5), ("Chen", "The Martian", 3),
    ("Divya", "Arrival", 5), ("Divya", "The Martian", 4), ("Divya", "Inception", 5),
    ("Eshan", "Interstellar", 4), ("Eshan", "Inception", 5), ("Eshan", "The Martian", 4),
    ("Farah", "Toy Story", 5), ("Farah", "Finding Nemo", 4), ("Farah", "Arrival", 2),
    ("Gita", "Inception", 5), ("Gita", "Interstellar", 4), ("Gita", "Arrival", 4),
    ("Hari", "Finding Nemo", 5), ("Hari", "Toy Story", 4), ("Hari", "The Martian", 2),
]


def similarity_table() -> pd.DataFrame:
    ratings = pd.DataFrame(RATINGS, columns=["user", "movie", "rating"])
    matrix = ratings.pivot_table(index="movie", columns="user", values="rating", fill_value=0)
    similarities = cosine_similarity(matrix)
    return pd.DataFrame(similarities, index=matrix.index, columns=matrix.index)


def recommend(movie: str, count: int = 3) -> pd.Series:
    similarities = similarity_table()
    if movie not in similarities.index:
        raise ValueError(f"Unknown movie. Choose from: {', '.join(similarities.index)}")
    return similarities.loc[movie].drop(movie).sort_values(ascending=False).head(count)


def main() -> None:
    available = list(similarity_table().index)
    print("Available movies:", ", ".join(available))
    movie = input("Movie you liked: ").strip()
    try:
        recommendations = recommend(movie)
    except ValueError as error:
        print(error)
        return
    print("\nSimilar movies from this small example dataset:")
    for title, score in recommendations.items():
        print(f"- {title}: similarity {score:.3f}")
    print("A real recommender needs far more users, items, bias checks, and evaluation.")


if __name__ == "__main__":
    main()

How the pipeline works

A movie-by-user matrix fills missing interactions with zero for this compact item-similarity demonstration.

Cosine similarity ranks movies with rating patterns closest to the selected title. The script returns the three highest-scoring different titles; production ranking needs offline and online evaluation beyond this toy table.

Run the project

  1. Create and activate a virtual environment.
  2. Install the dependencies with python -m pip install pandas scikit-learn.
  3. Run python ml_movie_recommendation.py.
  4. Review every printed metric together with the limitation below; a single score never proves deployment readiness.

How to interpret the evaluation

Classification projects report class-aware metrics so majority classes do not hide weak performance. Regression projects report errors in target units and include R-squared or a simple baseline where appropriate. Always verify the split strategy matches how new data will arrive.

Accuracy, ethics, and safety limits

The sample is too small for claims about personal taste. Filling missing ratings with zero is a teaching simplification, and no demographic or behavioural inference should be made.

Ways to extend the project

Load a larger licensed ratings set, centre user ratings, add popularity and diversity controls, evaluate precision@K, and handle new users and new movies.

Continue learning Machine Learning

Try the next project, return to the Softenant project library, or explore the Machine Learning course in Vizag for guided data preparation, model evaluation, and portfolio feedback.