Skip to content

About

Bayesian Network model for predicting personalized movie preferences using MovieLens ratings, Tag Genome features, and user-specific preference modeling.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Movie Preference Prediction Using Bayesian Networks

Project Overview

This project develops an interpretable Bayesian Network for predicting whether an individual user will like or dislike a movie based on the relationship between their historical preferences and the characteristics of the movie.

The analysis uses the MovieLens ratings dataset and Tag Genome, which represents movies through relevance scores for descriptive characteristics such as masterpiece, realistic, depressing, and unique. Historical user ratings are transformed into personalized preference profiles, which are then combined with movie characteristics to create user-movie compatibility features.

A six-feature Bayesian Network was ultimately selected after comparing models of varying complexity, a structure-learned Bayesian Network, logistic regression, and a majority-class baseline. The final model achieved 70.82% accuracy, 70.19% balanced accuracy, and a 0.7029 macro F1-score on an untouched holdout set containing more than 1.5 million observations.

Recognition: This work received a WGU Excellence Award for exceptional performance in a graduate Advanced AI and ML project.

Project Objectives

  • Predict clear like/dislike movie preferences at the individual-user level.
  • Transform historical rating behavior into personalized movie-characteristic preferences.
  • Combine user preferences with MovieLens Tag Genome characteristics to measure user–movie compatibility.
  • Prevent data leakage by separating historical and holdout observations before constructing user preference profiles or selecting model features.
  • Reduce a high-dimensional Tag Genome representation to a compact set of informative predictors.
  • Optimize Bayesian Network complexity while maintaining predictive performance.
  • Compare a manually structured predictive Bayesian Network with a data-driven structure-learned network.
  • Benchmark Bayesian Network performance against majority-class and logistic regression classifiers.
  • Preserve probabilistic interpretability while achieving competitive classification performance.

Results

The optimized model uses six personalized compatibility features:

  • masterpiece
  • horrible
  • depressing
  • realistic
  • compassionate
  • unique

Each compatibility feature represents the interaction between a user's historical preference for a movie characteristic and the relevance of that characteristic to a particular movie.

Final Holdout Performance

Metric Six-Feature Bayesian Network Structure-Learned Bayesian Network
Accuracy 0.7082 0.6969
Balanced Accuracy 0.7019 0.6876
Macro Precision 0.7075 0.6991
Macro Recall 0.7019 0.6876
Macro F1 0.7029 0.6881

Optimized Bayesian Network Holdout Confusion Matrix

The final six-feature Bayesian Network generalized well to 1,588,143 untouched holdout observations representing approximately 26,000 users.

The model correctly identified both preference classes substantially better than the majority-class baseline, while maintaining relatively balanced performance between users who liked and disliked the evaluated movies.

Prediction Analysis

The final Bayesian Network models six user-movie compatibility characteristics as direct parents of the preference outcome:

Six-Parent Bayesian Network for User Movie Preference

This structure was intentionally retained because it provides a direct probabilistic relationship between each selected compatibility characteristic and the predicted preference outcome.

A separate structure-learning experiment used hill-climbing search with Bayesian Information Criterion (BIC) scoring to discover dependencies directly from the training data. Although the learned network captured additional relationships among compatibility characteristics, it produced lower holdout performance than the six-parent predictive network.

The Bayesian representation also allows model behavior to be examined through conditional probabilities rather than feature importance alone. For example, the analysis demonstrates substantial changes in predicted preference probability across different combinations of personalized compatibility states.

Key Features

Personalized Preference Modeling

Raw ratings are centered relative to each user's historical mean rather than interpreted identically across all users. This accounts for differences in individual rating behavior and allows preferences to be defined relative to each user's typical ratings.

Tag Genome Feature Engineering

Movie characteristics are derived from the MovieLens Tag Genome. Semantic redundancy among Tag Genome labels is analyzed using sentence-transformer embeddings, Genome relevance correlations, and manual review before redundant characteristics are consolidated.

User-Movie Compatibility

For each selected characteristic, compatibility is calculated as:

user historical preference × movie characteristic relevance

This transforms separate user and movie information into features describing how closely a particular movie aligns with an individual user's historical preferences.

Leakage-Resistant Preprocessing

Each user's observations are separated into historical and holdout partitions before user preference profiles are constructed. Feature selection and discretization thresholds are derived exclusively from historical data and applied unchanged to holdout observations.

Feature Selection

The original Tag Genome representation is progressively reduced through:

  • semantic redundancy consolidation,
  • movie-coverage screening,
  • between-user preference variation,
  • correlation-based redundancy removal,
  • mutual-information ranking, and
  • Bayesian Network feature-count optimization.

The preprocessing pipeline ultimately identifies 15 candidate compatibility features, from which model optimization selects six for the final network.

Probabilistic Interpretability

Unlike a conventional classifier that primarily returns a predicted class or score, the Bayesian Network explicitly represents conditional relationships between compatibility states and movie preference. This allows predictions to be interpreted as probabilities conditioned on a user's compatibility with particular movie characteristics.

Technologies Demonstrated

  • Python
  • pandas
  • NumPy
  • scikit-learn
  • pgmpy
  • Bayesian Networks
  • Probabilistic graphical models
  • Bayesian parameter estimation
  • Structure learning
  • Hill-climbing search
  • Bayesian Information Criterion (BIC)
  • Mutual information
  • Feature engineering
  • Feature selection
  • Classification
  • Logistic regression
  • Sentence transformers
  • Data preprocessing
  • Model optimization
  • Computational benchmarking
  • Jupyter Notebook

Dataset

This project uses the MovieLens ratings dataset and Tag Genome.

The ratings data provide user–movie rating histories, while the Tag Genome provides relevance scores describing movies through a large collection of semantic characteristics.

Because the original MovieLens data are large, the source dataset is not included directly in this repository. The notebooks expect the source MovieLens data to be available locally and construct the required modeling artifacts from those files.

The preprocessing pipeline identifies users with sufficient Tag Genome-covered rating histories, excludes ambiguous repeated user–movie ratings, constructs historical preference profiles, and generates the binary modeling datasets used by the Bayesian Network.

Model Architecture

The final model is a discrete Bayesian Network with six compatibility predictors directly connected to the binary preference target:

Model: Six-Feature Predictive Bayesian Network

Predictors:
├── masterpiece
├── horrible
├── depressing
├── realistic
├── compassionate
└── unique

Target:
└── preference_class
    ├── dislike
    └── like

Compatibility States:
├── low
├── medium
└── high

Parameter Estimation:
└── Bayesian estimation

Compatibility values are discretized into low, medium, and high states using thresholds learned exclusively from historical data.

The target is defined relative to each user's historical mean rating:

dislike: centered rating < -0.40
neutral: -0.40 ≤ centered rating ≤ 0.40
like:    centered rating > 0.40

Neutral observations are excluded from final binary modeling so that the model focuses on clear expressions of user preference.

Model Comparison

Model development included several levels of comparison:

  1. Majority-Class Baseline
    Establishes the minimum predictive performance expected from a useful classifier.

  2. Logistic Regression
    Provides a conventional machine-learning benchmark using the same optimized compatibility features.

  3. Predictive Bayesian Networks
    Networks containing progressively larger subsets of the highest-ranked compatibility features were evaluated to determine the appropriate balance between predictive performance and complexity.

    Bayesian Network Performance by Feature Count

  4. Structure-Learned Bayesian Network
    Hill-climbing structure search with BIC scoring was used to determine whether a data-driven network topology improved upon the manually structured predictive network.

The six-feature predictive Bayesian Network was selected because it provided the strongest combination of predictive performance, compact model structure, and direct probabilistic interpretability.

Dependencies

The project was developed in Python and uses the following primary libraries:

numpy
pandas
scikit-learn
pgmpy
matplotlib
sentence-transformers
pyarrow

Exact package versions may vary depending on the execution environment.

Repository Structure

Movie_Preference_Bayesian_Network/
├── README.md
├── EDA.ipynb
├── Preprocessing.ipynb
├── Model.ipynb
├── Optimization.ipynb
├── data/
│   └── processed/
│       ├── bn_history_binary.parquet
│       ├── bn_holdout_binary.parquet
│       └── bn_preprocessing_config.json
├── images/
│   ├── bayesian_network.png
│   ├── bn_feature_optimization.png
│   └── predictive_bn_confusion_matrix.png
└── results/
    ├── bn_final_holdout_results.csv
    ├── bn_final_model_summary.json
    ├── bn_learned_confusion_matrix.csv
    └── bn_predictive_confusion_matrix.csv

Notebook Workflow

EDA.ipynb
Explores rating behavior, user activity, Tag Genome coverage, feature variability, semantic redundancy, and repeated ratings.

Preprocessing.ipynb
Constructs historical and holdout partitions, develops personalized preference profiles, performs feature screening and selection, creates compatibility features, discretizes Bayesian Network inputs, and exports modeling configuration metadata.

Model.ipynb
Develops the initial Bayesian Network models, evaluates feature counts, compares against logistic regression, performs structure-learning experiments, and evaluates final model structures.

Optimization.ipynb
Optimizes Bayesian Network feature count and complexity, evaluates the structure-learned alternative, performs final holdout testing, compares benchmark models, and evaluates computational performance.

Usage

  1. Obtain the required MovieLens ratings and Tag Genome source data.
  2. Configure the source-data paths used by the notebooks.
  3. Run the notebooks in the following order:
EDA.ipynb
Preprocessing.ipynb
Model.ipynb
Optimization.ipynb

The preprocessing notebook generates the modeling datasets and configuration information required by the later notebooks.

Future Improvements

Potential extensions include:

  • Evaluating alternative Bayesian Network structure-learning algorithms and scoring criteria.
  • Exploring hierarchical or user-segment-specific probabilistic models.
  • Incorporating additional movie metadata alongside Tag Genome characteristics.
  • Evaluating temporal preference changes using rating timestamps.
  • Comparing Bayesian Network probabilities with additional recommendation and classification approaches.
  • Investigating methods for retaining neutral preference observations through ordinal or multiclass probabilistic modeling.
  • Developing a recommendation layer that ranks unseen movies using predicted preference probabilities.

About

Bayesian Network model for predicting personalized movie preferences using MovieLens ratings, Tag Genome features, and user-specific preference modeling.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages