Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

same recommendations to all the users #6

Closed
yestoprince opened this issue Feb 12, 2019 · 6 comments
Closed

same recommendations to all the users #6

yestoprince opened this issue Feb 12, 2019 · 6 comments
Assignees

Comments

@yestoprince
Copy link

yestoprince commented Feb 12, 2019

@takuti
I tried to build a recommendation engine using matrix factorization but after training my model i found that it is giving same recommendations to all the users is there any issue with it i followed all the instructions as per your tutorial.
can you please check my code to see is there any issue with the code ? or with your prediction method.
Thanks :)

Here is my code

`using CSV

train = CSV.read("training_data_book.csv", delim = ',', escapechar = '\' )
test = CSV.read("testing_data_book.csv", delim=',', escapechar='\')

Created dictionaries in below code for mapping the original ids with sequential ids

user_mappings = Dict{Int, Int}()
book_mappings = Dict{String, Int}()
user_counter, book_counter = 0,0
events = Event[]

for row in eachrow(train)
global user_counter, book_counter
user_id, book_id, rating = row[:UserID], row[:ISBN], row[:Rating]
haskey(user_mappings, user_id) || (user_mappings[user_id] = (user_counter += 1))
haskey(book_mappings, book_id) || (book_mappings[book_id] = (book_counter += 1))
push!(events, Event(user_mappings[user_id], book_mappings[book_id], rating))
end

Calling to data Accessor

da = DataAccessor(events, user_counter, book_counter)
recommender = MF(da, Parameters(:k => 2))

Here i build my model

build(recommender, learning_rate=15e-4, max_iter=100)

Predicting 5 recommendation of user whose sequential id is 10

for i in recommendations_to_books(recommend(recommender, 35, 10, [1:book_counter...]))
main_data[main_data.ISBN .== i, :BookTitle] |> println
end

for i in recommendations_to_books(recommend(recommender, 15, 10, [1:book_counter...]))
main_data[main_data.ISBN .== i, :BookTitle] |> println
end
`

@yestoprince
Copy link
Author

yestoprince commented Feb 12, 2019

Here the recommender for user 35 as well as user 15 above giving same recommendation and i tested for other users ids as well the result is still the same :( Please help
@takuti

@yestoprince
Copy link
Author

screen shot 2019-02-12 at 3 41 58 pm

Check this screenshot @takuti

@takuti takuti self-assigned this Feb 20, 2019
@takuti
Copy link
Owner

takuti commented Mar 23, 2019

@yestoprince Sorry for the late response.

Can you first check if recommend(recommender, user, 10, [1:book_counter...]) gives the same predicted ratings to all user-item pairs? For example, our tiny example in README actually gives same recommendation to user 1, 2, and 3, but predicted values are different:

julia> recommend(recommender, 1, k, candidates)
2-element Array{Pair{Int64,Float64},1}:
 6 => 0.0890438
 2 => 0.0465087

julia> recommend(recommender, 2, k, candidates)
2-element Array{Pair{Int64,Float64},1}:
 6 => 0.207168
 2 => 0.108206

julia> recommend(recommender, 3, k, candidates)
2-element Array{Pair{Int64,Float64},1}:
 6 => 0.0890386
 2 => 0.0465061

In this case, recommender works fine, and problem is just a lack of training samples or inappropriate configuration of Parameters().

Also, please make sure if all users and items have at least 1 rating event. To give an example, the README example has no events for user 4 and 5:

const n_user = 5
const n_item = 10

events = [Event(1, 2, 1), Event(3, 2, 1), Event(2, 6, 4)]

da = DataAccessor(events, n_user, n_item)

Consequently, both prediction and recommendation results for those two users become same, because there is no chance to update their model parameters:

julia> recommend(recommender, 4, k, candidates)
2-element Array{Pair{Int64,Float64},1}:
 6 => 0.0643689
 2 => 0.0336207

julia> recommend(recommender, 5, k, candidates)
2-element Array{Pair{Int64,Float64},1}:
 6 => 0.0643689
 2 => 0.0336207

Note that missing events are equally filled by 0.1 by default:

# initialize with small values
# (random is also possible)
P = ones(n_user, rec.hyperparams[:k]) * 0.1
Q = ones(n_item, rec.hyperparams[:k]) * 0.1

For further investigation, we need to take a look at your data and implementation detail of recommendations_to_books function.

@yestoprince
Copy link
Author

Ok thanks but now i moved to Python for building recommendation engine. Do you have experience in that ? i also have set of errors in that too ?

@takuti
Copy link
Owner

takuti commented Mar 26, 2019

Yes I do. As long as dataset is same, I believe you'll face the same situation. Otherwise, it's a bug of Recommendation.jl. If so, it'd be appreciated if you could report the issue.

@takuti takuti closed this as completed Mar 26, 2019
@takuti
Copy link
Owner

takuti commented Mar 26, 2019

Feel free to reopen this issue if you have additional comments on this package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants