Hybrid Movie Recommendation Engine

TF-IDF content vectors fused with KNN collaborative filtering through a tunable weighted score.

ML / DL2023All work

Fig. 01Hybrid Movie Recommendation Engine title card
TF-IDF content vectors fused with KNN collaborative filtering through a tunable weighted score.

What it is

What it does

Three notebooks, three recommenders. Content-based filtering builds stemmed metadata tags for 4,809 TMDB movies and ranks full-matrix cosine similarities; collaborative filtering runs brute-force cosine KNN over a sparsified user-rating matrix; the hybrid joins both result sets and sorts by a weighted score you can tune.

Why it exists

Content-based feels samey, collaborative dies on new movies with ten ratings. I kept both honest, side by side, then let a one-line weighted blend decide. You can see what each brings before they get mixed.

4,809
Movies vectorised
100
Neighbours queried
2→1
Signals fused

Repo Amit-kr26/MOVIE-RECOMMENDATION-USING-CONTENT-AND-COLLABORATIVE-BASED-FILTERINGStack Python · scikit-learn · TF-IDF · KNN · pandas

Build5decisions

How it is built

Content pipeline

Overview + genres + keywords + top-3 cast + director become tags: multi-word names space-stripped ('Science Fiction' → ScienceFiction), Porter-stemmed, then TfidfVectorizer(stop_words='english') feeds a full 4809×4809 cosine similarity matrix.

Fuzzy lookup

difflib.get_close_matches resolves misspelled titles ('Intersteler' still works) before ranking; results return as the top 100 neighbours sorted by similarity.

Collaborative sparsification

The user×movie pivot drops noise first (movies need >10 ratings, users >50) then converts to a csr_matrix for NearestNeighbors(metric='cosine', algorithm='brute', n_neighbors=20), queried for 100 neighbours.

Title normalisation

Year suffixes are stripped from titles before matching so content-side and collaborative-side frames join cleanly.

Explicit hybrid weighting

hybrid.ipynb outer-joins both frames and computes HybridScore = 0.955 × similarity + 0.005 × distance. The weights sit at the top of the notebook as exposed constants.

How the pieces connect

Two recommenders Fuse TMDB 4,806 movies + credits Tag bag + stem genres, cast, crew TF-IDF cosine 4,806² matrix MovieLens pivot 610 users KNN cosine CSR, 20 neighbours Movie title query Fuzzy match difflib, typo tolerant Outer merge on Title HybridScore 0.955 : 0.005 Top 15 100 ∪ 99 pool the two ranked frames