o1-preview-2024-09-12· OpenAI
WildChat-4.8M (AI2)
Create fuzzy logic like senior programmer!…
- User
Create fuzzy logic like senior programmer! title,type,genres,releaseYear,imdbAverageRating,imdbNumVotes,availableCountries write in ipynb
- Assistant
Create fuzzy logic like senior programmer! title,type,genres,releaseYear,imdbAverageRating,imdbNumVotes,availableCountries write in ipynb
# Fuzzy Logic Movie Recommendation System
This notebook demonstrates how to create a fuzzy logic system for recommending movies based on several attributes such as release year, IMDb average rating, and the number of votes. We will use the `scikit-fuzzy` library to implement the fuzzy inference system.
```python
# Import necessary libraries
import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl
We will define the following fuzzy variables:
release_year): Input variable representing the year the movie was released.imdb_rating): Input variable representing the average rating of the movie on IMDb.imdb_votes): Input variable representing the number of votes the movie has received on IMDb.recommendation): Output variable representing the recommendation level of the movie.We assume that movies can be classified as:
# Create the universe variables
release_year = ctrl.Antecedent(np.arange(1980, 2025, 1), 'release_year')
We classify the ratings as:
imdb_rating = ctrl.Antecedent(np.arange(0, 10.1, 0.1), 'imdb_rating')
We classify the number of votes as:
imdb_votes = ctrl.Antecedent(np.arange(0, 1000000, 1000), 'imdb_votes')
The recommendation score can be:
recommendation = ctrl.Consequent(np.arange(0, 11, 1), 'recommendation')
release_year['old'] = fuzz.trimf(release_year.universe, [1980, 1980, 2000])
release_year['recent'] = fuzz.trimf(release_year.universe, [1995, 2005, 2015])
release_year['new'] = fuzz.trimf(release_year.universe, [2010, 2024, 2024])
imdb_rating['low'] = fuzz.trimf(imdb_rating.universe, [0, 0, 5])
imdb_rating['average'] = fuzz.trimf(imdb_rating.universe, [4, 5.5, 7])
imdb_rating['high'] = fuzz.trimf(imdb_rating.universe, [6.5, 10, 10])
imdb_votes['few'] = fuzz.trimf(imdb_votes.universe, [0, 0, 50000])
imdb_votes['some'] = fuzz.trimf(imdb_votes.universe, [25000, 100000, 250000])
imdb_votes['many'] = fuzz.trimf(imdb_votes.universe, [200000, 1000000, 1000000])
recommendation['low'] = fuzz.trimf(recommendation.universe, [0, 0, 5])
recommendation['medium'] = fuzz.trimf(recommendation.universe, [3, 5, 7])
recommendation['high'] = fuzz.trimf(recommendation.universe, [6, 10, 10])
%matplotlib inline
import matplotlib.pyplot as plt
release_year.view()
imdb_rating.view()
imdb_votes.view()
recommendation.view()
We will define the following rules:
rule1 = ctrl.Rule(release_year['new'] & imdb_rating['high'] & imdb_votes['many'], recommendation['high'])
rule2 = ctrl.Rule(release_year['old'] & imdb_rating['low'] & imdb_votes['few'], recommendation['low'])
rule3 = ctrl.Rule(imdb_rating['average'] & imdb_votes['some'], recommendation['medium'])
rule4 = ctrl.Rule(release_year['recent'] & imdb_rating['high'], recommendation['high'])
rule5 = ctrl.Rule(imdb_rating['low'], recommendation['low'])
recommendation_ctrl = ctrl.ControlSystem([rule1, rule2, rule3, rule4, rule5])
recommendation_simulation = ctrl.ControlSystemSimulation(recommendation_ctrl)
Let's test the system with a sample movie:
# Set input values
recommendation_simulation.input['release_year'] = 2018
recommendation_simulation.input['imdb_rating'] = 8.5
recommendation_simulation.input['imdb_votes'] = 350000
# Perform the computation
recommendation_simulation.compute()
print(f"Recommended Score: {recommendation_simulation.output['recommendation']:.2f}")
recommendation.view(sim=recommendation_simulation)
We've successfully created a fuzzy logic system that provides a recommendation score for movies based on their release year, IMDb average rating, and the number of votes. This system can be further expanded by incorporating more variables such as genres and available countries.
Not yet included in a published release.