Utilizing Catboost Algorithm for Movie Recommendation
By analyzing past interactions, such as movie ratings and viewing history, CatBoost can identify patterns and similarities between users, enabling it to recommend movies that align with each user’s unique tastes and preferences.
Dataset : Dataset for the below code can be downloaded:
Step 1: Import necessary Libraries
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
import time
from catboost import CatBoostRegressor
from sklearn.preprocessing import LabelEncoder
Step 2: Loading and Merge the Data
Load the movie and ratings data from CSV files, and merge the movies and ratings dataframes on the ‘movieId’ column.
movies = pd.read_csv('movies.csv')
ratings = pd.read_csv('ratings.csv')
# Merge movies and ratings data on movieId
data = pd.merge(ratings, movies, on='movieId')
Step 3: Encoding Categorical Features
Encode categorical features (‘genres’ and ‘title’) using LabelEncoder.
# Encode categorical features
data['genres'] = LabelEncoder().fit_transform(data['genres'])
data['title'] = LabelEncoder().fit_transform(data['title'])
Step 4: Selecting Features and Target, and Splitting the Data
Defining features (X) and target (y) variables and splitting the data into training and testing sets.
# Select features and target
X = data[['userId', 'movieId', 'genres', 'title']]
y = data['rating']
# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
Step 5: Implementing Catboost Algorithm
catboost_model = CatBoostRegressor(iterations=1000, learning_rate=0.1, depth=10, loss_function='RMSE', verbose=100)
start_time = time.time()
catboost_model.fit(X_train, y_train, cat_features=['genres', 'title'])
training_time_cat = time.time() - start_time
y_pred_cat = catboost_model.predict(X_test)
mse_cat = mean_squared_error(y_test, y_pred_cat)
rmse_cat = mse_cat ** 0.5
print(f"CatBoost RMSE: {rmse_cat}")
Output:
CatBoost RMSE :0.8675435401303696
Elevating Movie Recommendations with CatBoost
In todays digital era, Offering the customers with what they need plays a crucial role in marketing. When it comes to streaming platforms it is even more difficult to find a perfect movie to watch from a overwhelming array of choices. However, with advancements in machine learning techniques like CatBoost, personalized movie recommendations have become more accurate and tailored to individual preferences.
In this article, we will implement movie recommendations model using CatBoost and explore how this powerful algorithm enhances the cinematic experience for viewers.
Table of Content
- CatBoost Algorithm for Movie Recommendation System
- Why CatBoost for Recommendation Systems?
- Utilizing Catboost Algorithm for Movie Recommendation