← Back to Projects
Machine LearningRecommendation SystemComparative Analysis

Comparative Analysis of CBF and UBCF for Book Recommendation Systems

Machine Learning — Recommendation System Comparison

Project Overview

This project compares Content-Based Filtering (CBF) and User-Based Collaborative Filtering (UBCF) for book recommendation under the same data preparation, train-test split, Top-N setting, and evaluation users. The goal is not only to identify which method performs better, but also to explain why the performance gap occurs.

Tools Used

PythonPandasNumPySciPyscikit-learnMatplotlibSeabornTF-IDFCosine SimilarityPearson CorrelationCSR Matrixgdown

Dataset & Preparation

The raw data consists of 271,360 book records, 1,149,780 rating records, and 278,858 user records. After removing implicit ratings (rating 0), aligning interactions at Book-Title level, and applying iterative filtering with at least 10 user interactions and 3 title interactions, the modeling data contains 4,196 users, 16,490 titles, and 133,907 interactions.

Machine Learning Workflow

Data Understanding → Data Cleaning → Explicit Rating Filtering → User-Title Aggregation → Iterative K-Core Filtering → 80:20 Split per User → CBF with TF-IDF Metadata Similarity → UBCF with User-Item Matrix & User Similarity → Top-10 Recommendation → Precision, Recall, F1-Score & Diagnostic Evaluation

Evaluation Results

0.028

CBF achieved macro-average Precision of 0.0277 across 300 evaluated users.

0.084

CBF achieved macro-average Recall of 0.0840, higher than UBCF's 0.0073.

0.038

CBF achieved macro-average F1-Score of 0.0377, compared with 0.0042 for UBCF.

300

Both methods were evaluated on the same 300 users with Top-10 recommendation lists.

Why the Results Differ

100

CBF produced recommendations for all evaluated users, giving 100% recommendation coverage in the diagnostic summary.

75

UBCF only produced recommendations for 75% of evaluated users, with an average recommendation count of 7.5 instead of 10.

99.9

The UBCF train user-item matrix is extremely sparse at about 99.85%, limiting overlapping ratings between users and weakening neighborhood-based recommendation opportunities.

19.7

CBF achieved a 19.67% hit rate in the diagnostic summary, while UBCF achieved 3.00%, showing that the observed performance gap is also related to recommendation availability and sparse interactions.

Evaluation Setup

Relevant items in the test data are defined using Book-Rating ≥ 9. The filtered dataset is split per user into approximately 78.75% train and 21.25% test. Evaluation uses 300 users selected from 3,135 evaluable users, with Top-N fixed at 10 for both methods.

Project Conclusion

In this experimental setting, CBF performs better than UBCF on Precision, Recall, F1-Score, recommendation coverage, and hit rate. The result should be interpreted as specific to this dataset and evaluation design: CBF benefits from book metadata, while UBCF is strongly affected by the sparse user-item interaction matrix and limited user overlap.

Evaluation & Diagnostic Visuals

Ground truth relevance distribution in the test data
Ground-truth relevance distribution on the test set using rating ≥ 9
Average CBF and UBCF recommendation metrics
Macro-average Precision, Recall, and F1-Score comparison between CBF and UBCF