Non_Collaborative_Filtering
Non_Collaborative_Filtering
User-Based & Item-Based Filtering, Similarity Measures, and Worked Prediction Examples
(Note: PCA and Matrix Factorization are intentionally not covered here)
1. What Is a Recommender System?
A recommender system is a system that suggests suitable items to users based on their interests, behaviour, or
previous choices.
Example
Suppose Riya watches and likes several comedy movies. The system may recommend another comedy movie
that she has not watched.
X→Y
It means: if X occurs, Y is also likely to occur.
Example
Suppose supermarket transactions show that many customers who buy diapers also buy baby powder. The rule
can be written as:
Transaction-Itemset Model
Association rules generally use transaction data.
Each row represents one transaction, while the products form its itemset.
Important Measures
Support — how frequently X and Y occur together.
For example, every person buying a mobile phone might receive the same recommendation for a phone cover.
This is why personalized recommender systems are needed.
Personalized Recommendations
A personalized recommendation is created separately for a particular user.
Example
Suppose two users open the same shopping website:
● User A frequently buys sports products.
● User B frequently buys books.
The website should show sports-related recommendations to User A and book recommendations to User B. The
recommendations are different because their preferences are different.
3. User Ratings
Recommender systems learn user interests from ratings. A rating is not always a numerical score. It can be
explicit or implicit.
Example
User Movie Rating
Amit Titanic 5
Amit Batman 3
Neha Titanic 4
Neha Batman 2
Example
Suppose Rahul does not rate a video but watches it completely three times. The system may infer that Rahul
likes the video.
Limitation
Implicit behaviour does not always indicate liking. For example, a user may repeatedly open a product page only
to compare its price, not because they like the product.
4. Collaborative Filtering
Collaborative filtering produces recommendations using the collective behaviour of many users. Its basic idea is:
People who agreed in the past are likely to agree again in the future.
Collaborative filtering normally does not require detailed information about an item. It mainly uses ratings or
user behaviour.
Example
Suppose Asha likes Titanic and The Notebook. Meera also likes Titanic and The Notebook, and Meera
additionally likes La La Land.
Since Asha and Meera have similar preferences, the system may recommend La La Land to Asha.
5. User-Rating Matrix
Collaborative filtering uses a user-rating matrix:
● Rows represent users.
● Columns represent items.
● Cells contain ratings.
● Missing cells represent items that have not been rated.
Example
User Titanic Batman Inception Superman
Amit 5 2 ? 1
Neha 4 1 5 ?
Ravi 1 5 4 5
Priya 5 2 4 ?
The question marks indicate missing ratings. The recommender system tries to predict these values. For
example, it may predict Amit's rating for Inception as 4.5. Because the predicted rating is high, Inception can be
recommended to Amit.
6. Sparse Matrix
A user-rating matrix is generally sparse, meaning most cells are empty.
Example
An online shopping platform may contain 1,000,000 users and 100,000 products. However, an average user
might rate only 10 products. Therefore, almost all values in the matrix will be missing.
For example: User A has rated 20 films, User B has rated 25 films, and they have only one film in common. One
shared rating is usually insufficient to confidently conclude that they are similar.
7. Completing the User's Row
For a particular user, collaborative filtering predicts the missing values in that user's row.
The system predicts Amit's rating for Inception using ratings from similar users. If the predicted rating is:
Main Steps
● Select the target user.
● Compare the target user with other users.
● Identify the most similar users, called neighbours.
● Find items liked by those neighbours.
● Predict the target user's missing ratings.
● Recommend items having high predicted ratings.
Example
User Titanic Batman Inception
Amit 5 2 ?
Neha 4 2 5
Ravi 1 5 2
Amit and Neha have similar ratings — both gave Titanic a high rating and both gave Batman a low rating.
Therefore, Neha is a suitable neighbour for Amit.
Because Neha gave Inception a rating of 5, the system may recommend Inception to Amit.
9. Measuring User Similarity
To apply UBCF, we must calculate how similar two users are. The main approaches are Pearson correlation,
mean-centred cosine similarity, and significance weighting.
Pearson correlation compares how each rating differs from that user's average rating.
Formula
w(u,i) = Σ[(r(u,j) - r̄u)(r(i,j) - r̄i)] / [√Σ(r(u,j) - r̄u)² × √Σ(r(i,j) - r̄i)²]
Where:
● w(u,i) = similarity between users u and i
● r(u,j) = rating given by user u to item j
● r(i,j) = rating given by user i to item j
● r̄u = average rating of user u
● r̄i = average rating of user i
● I(ui) = items rated by both users
Simple Example
Movie User A User B
M1 5 4
M2 3 2
M3 4 3
User B consistently gives one point less than User A, but both follow exactly the same preference pattern: M1 is
their favourite, M3 comes second, and M2 is their least favourite.
1
Therefore, their preferences are considered perfectly similar.
Example
Suppose User A has rated 50 movies, User B has rated 60 movies, only two movies are common, and their
ratings for those two movies are identical. Pearson correlation may produce a similarity close to 1. However, two
common movies are not enough to confidently say that the users have the same taste.
High similarity does not always mean reliable similarity. The number of common ratings must also be
considered.
Basic Example
A = (5, 4, 1) B = (4, 5, 1)
The two users give high ratings to the first two items and a low rating to the third. Therefore, the vectors point
in similar directions and their cosine similarity will be high.
The adjusted vectors are identical. Therefore, their similarity is 1. This correctly recognises that the users have
the same preference pattern even though User B generally gives lower ratings.
This approach ignores Movies 1 and 4. Its disadvantage is that a high similarity may be obtained from very few
shared items.
Union Approach
All items rated by either user are included: {Movie 1, Movie 2, Movie 3, Movie 4}. A missing mean-centred rating
can be treated as zero.
This reduces similarity when users have many unshared items. It acts as a form of significance adjustment
because the denominator becomes larger while unshared items do not increase the numerator.
Important Caution
A missing rating does not necessarily mean that the user dislikes the item. It may simply mean that the user
has not seen or purchased it. Treating every missing raw rating as an actual zero rating can be misleading.
Example
Suppose Pearson similarity = 0.90, commonly rated items = 2, reliability threshold = 10.
Simple Example
Amit's average rating is 3.5. Two similar users rated Inception:
Prediction:
ŕ = 4.5
Main Steps
● Select an item already liked by the user.
● Compare that item with other items.
● Find items with similar rating patterns.
● Predict the user's ratings for those items.
● Recommend the highest-rated unseen items.
Example
Suppose many users who liked Titanic also liked The Notebook. If Riya gave Titanic a rating of 5 but has not
watched The Notebook, the system may recommend The Notebook to her.
Item-Rating Pattern
User Titanic The Notebook Batman
U1 5 5 2
U2 4 4 1
U3 5 4 2
U4 2 2 5
Titanic and The Notebook receive similar ratings from the same users. Therefore, they have high item-item
similarity. Batman has the opposite rating pattern and is not similar to them.
12. Difference Between UBCF and IBCF
Point User-Based CF Item-Based CF
Main comparison User with user Item with item
Main question Which users are similar? Which items are similar?
Recommendation Items liked by similar users Items similar to those already liked
Matrix operation Complete a user's row Complete an item's column
Example Users like Amit also liked Inception Inception is similar to movies Amit liked
Stability User preferences may change Item relationships are often more stable
Suitable when Number of users is manageable There are many users but fewer items
13. Content-Based Recommendation
A content-based system uses the characteristics or description of items. It recommends items similar to those a
user liked previously.
Example
Suppose a user likes movies with the following characteristics: Science fiction, Space, Adventure, Christopher
Nolan.
Advantages
● Can recommend new items that have no ratings.
● Does not require similar users.
● Recommendations can be explained using item features.
Limitations
● Requires good item descriptions.
● May repeatedly recommend very similar items.
● May not introduce users to different types of content.
This repeated recommendation of similar items is sometimes called over-specialisation.
14. Hybrid Recommender System
A hybrid system combines two or more recommendation approaches. It may combine:
● Collaborative filtering
● Content-based filtering
● User information
● Item information
● Context such as time, location or device
Example
An online movie platform may calculate:
FinalScore = 4.3
New-User Problem
A newly registered user has not rated anything. The system cannot find similar users.
Possible solution: ask the user to select favourite categories or rate a few popular items.
New-Item Problem
A newly added item has no ratings. Collaborative filtering cannot easily recommend it.
Possible solution: use content-based information such as category, genre, description and brand.
Quick Summary
Term Meaning
Association rules Recommend items frequently occurring together
Personalized recommendation Give different recommendations to different users
Explicit rating Directly provided by the user
Implicit rating Inferred from user behaviour
Collaborative filtering Learn recommendations from the preferences of many users
Term Meaning
User-rating matrix Stores users, items and ratings
Sparse matrix A matrix containing many missing ratings
UBCF Recommend items liked by similar users
Pearson correlation Compare users' rating patterns after adjusting for their averages
Cosine similarity Compare the direction of rating vectors
Significance weighting Reduce similarity when users share very few ratings
IBCF Recommend items similar to the items the user already likes
Content-based system Recommend items using their features or descriptions
Hybrid system Combine multiple recommendation methods
PCA and matrix factorization Intentionally omitted for now, as requested
Worked Example 1: Predicting Missing Ratings (Pearson-Based UBCF)
We can calculate all three missing ratings using user-based collaborative filtering and only the values available in
the table.
Given Ratings
User Titanic Batman Inception Superman
Amit 5 2 ? 1
Neha 4 1 5 ?
Ravi 1 5 4 5
Priya 5 2 4 ?
We will use:
● Pearson correlation to find similar users.
● Only positively similar users as neighbours.
● Mean-centred prediction.
The prediction formula is:
Their pattern is identical: Neha always gives one point less than Amit.
s(Amit, Neha) = 1
Amit and Priya also have common ratings:
s(Amit, Priya) = 1
Both Neha and Priya rated Inception, so both can be used.
s(Neha, Amit) = 1
Amit's Superman rating is 1, and Amit's average is 2.67. Because there is only one positively similar neighbour:
The prediction is low because Amit, whose rating pattern is similar to Neha's, rated Superman only 1.
Completed Matrix
User Titanic Batman Inception Superman
Amit 5 2 3.67 1
Neha 4 1 5 1.66
Ravi 1 5 4 5
Priya 5 2 4 2.00
Final Answers
● Amit – Inception = 3.67
● Neha – Superman = 1.66
● Priya – Superman = 2.00
These predictions should be treated cautiously because the table is very small. In particular, some similarities
are based on only two commonly rated movies; with two points, Pearson correlation can easily become +1,
even when there is not enough data to establish reliable similarity.
Worked Example 2: Predicting Chan's Ratings (Cosine-Similarity UBCF)
Let us calculate all three missing ratings for Chan using the complete data and cosine-similarity-based user
collaborative filtering.
C = (0, 4.5, 0, 4, 1, 0)
Similarity(C,U) = (C · U) / (|C| |U|)
C · M = (0)(2.5)+(4.5)(3.5)+(0)(3)+(4)(3.5)+(1)(2.5)+(0)(3) = 15.75+14+2.5 =
32.25
Michel's magnitude:
The highest predicted missing rating is for Matrix, so among the three unseen movies, Matrix should be
recommended first to Chan.
Important distinction: zero is used for N/A while calculating the cosine similarities. During final prediction,
users who have N/A for the movie must be excluded from both the numerator and denominator.