# Basic recommendation engine using R

In our day to day life, we come across a large number of Recommendation engines like Facebook Recommendation Engine for Friends’ suggestions, and suggestions of similar Like Pages, Youtube recommendation engine suggesting videos similar to our previous searches/preferences. In today’s blog post I will explain how to build a basic recommender System.

#### Types of Collaborative Filtering:

1. User based Collaborative Filtering
2. Item based Collaborative filtering
In this post will explain about User based Collaborative Filtering. This algorithm usually works by searching a large group of people and finding a smaller set with tastes similar to yours. It looks at other things they like and combines them to create a ranked list of suggestions.

Implementing User Based Collaborative Filtering:
This involves two steps:
1. Calculating Similarity Function
2. Recommend items to users based on user Similarity Score
Consider the below data sample of Movie critics and their movie rankings, the objective is to recommend the unrated movies based on similar users:

#### Step1- Calculate Similarity Score for CHAN:

Creating Similarity score for people helps us to identify similar people. We use Cosine based Similarity function to calculate the similarity between the users. Know more about cosine similarity here. In R we have a cosine function readily available:
user_sim = cosine(as.matrix(t(x)))

#### Step2- recommending Movies for CHAN:

For recommending movies for Chan using the above similarity matrix, we need to first fill the N/A where he has not rated. As first step, separate the non-rated movies by Chan and a weighted matrix is created by multiplying user similarity score (user_sim[,7]) with ratings given by other users.
Next step is to sum up all the columns of the weight matrix, then divide by the sum of all the similarities for critics that reviewed that movie. The result calculation gives what the user might rate this movie, the results as below:
The above explanation is written in the below R function:
rec_itm_for_user = function(userNo)
{ #calcualte column wise sum
col_sums= list()
rat_user = critics[userNo,2:7]
x=1
tot = list()
z=1
for(i in 1:ncol(rat_user)){
if(is.na(rat_user[1,i]))
{
col_sums[x] = sum(weight_mat[,i],na.rm=TRUE)
x=x+1
temp = as.data.frame(weight_mat[,i])
sum_temp=0
for(j in 1:nrow(temp))
{ if(!is.na(temp[j,1]))
{
sum_temp = sum_temp+user_sim[j,7]
}
}
tot[z] = sum_temp z=z+1
}
}
z=NULL
z=1
for(i in 1:ncol(rat_user)){
if(is.na(rat_user[1,i]))
{
rat_user[1,i] = col_sums[[z]]/tot[[z]] z=z+1
}
}
return(rat_user)
}
Calling the above function gives the below results:

rec_itm_for_user(7)
Titanic Batman Inception Superman.Returns spiderMan Matrix

2.811   4.5     2.355783           4            1    3.481427
Recommending movies for Chan will be in the order: Matrix (3.48), Titanic(2.81), Inception(2.35).
complete sourceCode is available on github

1. If you are facing any issue in your Epson Printer like Epson Error Code 0xF3 then you can resolve this issue by the help of expert’s technicians of Epson Printer or you may dial their toll-free i.e 1-888-500-9609.

2. Attend The Data Science Training in Bangalore From ExcelR. Practical Data Science Training in Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Science Courses in Bangalore.

3. Thanks for sharing this useful information! Hope that you will continue with the kind of stuff you are doing. If you want you can also read this blog which talk about how to Fix Windows 7 Update Error 8007000e in a very easy way.

4. Great article like this require readers to think as they read. I took my time when going through the points made in this article. I agree with much this information.
Best Data Science training in Mumbai

Data Science training in Mumbai

5. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.
360digitmg data science institutes

6. The content is well recognized, so no one could claim that it is just one person's opinion yet it covers and justifies all the valid points. Hope to read some more work from you.
SAP training in Kolkata
SAP training Kolkata
Best SAP training in Kolkata
SAP course in Kolkata

7. What a useful information provided by this blog! It’s remarkable. Thanks for helping me out… I will definitely get in touch with your blogs,
Epson printer in error state

8. Attend The Business Analytics Courses From ExcelR. Practical Business Analytics Courses Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Analytics Courses.

9. I think this is a standout amongst the most critical data for me. What"s more, i"m happy perusing your article. Be that as it may, ought to comment on some broad things ExcelR Business Analytics Courses

10. ExcelR provides Business Analytics Courses. It is a great platform for those who want to learn and become a Business Analytics. Students are tutored by professionals who have a degree in a particular topic. It is a great opportunity to learn and grow.

11. I want to say thanks to you. I have bookmark your site for future updates. ExcelR Data Analyst Course

12. If it's not too much trouble share more like that. ExcelR Business Analytics Courses

13. Hey! Someone in my Facebook group shared this site with us so I came to look it over. I'm definitely enjoying the information. I'm bookmarking and will be tweeting this to my followers! Wonderful blog and amazing style and design. internet security

14. I've been surfing online more than three hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. In my view, if all website owners and bloggers made good content as you did, the internet will be much more useful than ever before. energy shot supplement

15. Great Article .Its beneficial for me Thanks for sharing .if looking you accounting service then check it

quickbooks customer service phone number

16. This is so amazing article thanks for sharing this type useful wonderful information please share in future again and again .if you are looking accounting service you can get by this at

QuickBooks customer service

17. Most packaging boxes can look like an overwhelming mess to the uninitiated. You may be wondering, how a 2d drawing with a bunch of dotted lines is going to turn into a 3d box. Well, there are free options to get you the right box for your unique needs.

18. Fantastic!! you are doing good job! I impressed. Many bodies are follow to you and try to some new.. After read your comments I feel; Its very interesting and every guys sahre with you own works. Great!!
ve may bay tu Phap ve Viet Nam

vé máy bay từ singapore về việt nam

vé máy bay từ úc về việt nam

ve may bay tu Han Quoc ve Viet Nam

ve may bay tu Nhat Ban ve Viet Nam

ve may bay tu My ve Viet Nam

ve may bay tu Duc ve Viet Nam

data scientist training and placement

20. very informative article . keep sharing it .if you have need software service you can call at quickbooks customer service

21. What are your company values? What kind of message do you want to convey to your customers? If you’re a fun-loving company, your bath bomb boxes and other packaging should reflect that. Perhaps you want to try out bright, peppy colors, or inject some humor.

22. Truly, this article is really one of the very best in the history of articles. I am a antique ’Article’ collector and I sometimes read some new articles if I find them interesting. And I found this one pretty fascinating and it should go into my collection. Very good work! data science course in mysore

23. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details. data science course in mysore

24. I like your post. I appreciate your blogs because they are really good. Please go to this website for Data Science course in Bangalore. These courses are wonderful for professionals.

25. I was surfing net and fortunately came across this site and found very interesting stuff here. Its really fun to read. I enjoyed a lot. Thanks for sharing this wonderful information. business analytics course in mysore

26. I truly like your style of blogging. I added it to my preferred's blog webpage list and will return soon…https://360digitmg.com/course/certification-program-on-digital-marketing

27. Great very helpful blog. Thanks For Sharing Such A Wonderful Blog. I will definitely go ahead and take advantage of this. Your Blog Is Very Informative. Again Thanks For Sharing This Blogs With Us. For more learning go through Skillslash.
For Data Science Course Data Science Course In Bangalore

28. Nice Blog! such a informative things you are sharing ,I really liked your content. If you wanna know about "Skillslash | Training with live industry experience that gets you hired" go to Data science courses in bangalore

29. 360DigiTMG, the top-rated organisation among the most prestigious industries around the world, is an educational destination for those looking to pursue their dreams around the globe. The company is changing careers of many people through constant improvement, 360DigiTMG provides an outstanding learning experience and distinguishes itself from the pack. 360DigiTMG is a prominent global presence by offering world-class training. Its main office is in India and subsidiaries across Malaysia, USA, East Asia, Australia, Uk, Netherlands, and the Middle East.

30. Start your career in Data Science with 360DgiTMG Data Science training programs that are specifically designed to enter the job market with the required skills. data science institute in chennai

31. 360DigiTMG offers courses ranging for basic to advanced, start your career journey with us and let us aid you in bagging your dream job. best data science courses in chennai

32. Learn to build powerful models to solve business problems by generating useful insights and discover the various scientific processes and methods used to transform the information available in huge datasets into meaningful results. master all the tools and techniques in Data Science and gain domain-specific knowledge which will help you to add more value to your profile. Sign up for the Data Science course in hyderabad with Placements and multiple your chances of working across all industries and job functions.data analytics training in hyderabad

33. Are you not ready to risk your and your family's health this pandemic time by joining an offline Data Analyst course. we have a solution for you, enroll in an online Data Analyst course that will equip you with all the knowledge needed for a job in just 6 months.business analytics course in nagpur

34. Someone sometimes with visits your blog regularly and recommended it in my experience to read as well.
Software Testing Tools Training in Hyderabad

35. It’s not how it’s about where? Get trained at 360DigiTMG, the best Data Analytics training institute, and experience the power of technical knowledge. Hone your skills with the ground-breaking curriculum. data analytics course in gurgaon

36. Acquire a firm grounding in the theory of Data Science by signing up for the Data Science courses in hyderabad. Master the relevant skills along with all the essential tools and techniques of Data Science. Get to avail benefits like Flexible timings, Best industry trainers, and a meticulously crafted curriculum with hands-on projects that will give you exposure to a real-world working environment.data science training in hyderabad