How I personalized my YouTube recommendation using YT API?
Last Updated on June 7, 2021 by Editorial Team
Author(s): Daksh Trehan
Machine Learning
How to utilize most of YouTubeβs API?
Last week, I wrote about how YouTube Algorithm works and the AI workflow behind it. But based on the information available regarding its recommendation system, I think there are some flaws inΒ it:
- It highly prefers watch time and obviously, longer videos will have high watch time and it tends to recommend higher duration videos after a certainΒ period.
- YouTube has a lot of clickbait videos, low-quality content and yet it is recommended and no actions are taken on false information imparted.
- Satisfaction rates such as LikeCount, DislikeCount have little effect on recommendations that could be improved.
During my research regarding the YT algorithm, I found a really interesting article by Chris Lovejoy where using YT API, he managed to create a personalized recommendation system. Inspired by his thought process and an insightful article, I decided to create my own YT recommendation algorithm using YTΒ APIs.
The Plan
The plan was to create a system that can suggest relevant videos following a personalized plan. The motive was to avoid looking for the best video in a pool of 1000s of videos but rather to get a video that statistically suits myΒ taste.
The plan could save me a lot of hours looking for that particular relevant content and maybe help me to avoid distraction.
The workflow consisted of using getting video information using YouTubeβs API and then rank them statistically according to my taste. Later, to have some ease we can also automate the whole process usingΒ Python.
Getting familiar with YouTubeβs API
YouTube API is the car driving this project. It will bring you every sort of information about the video, be it, statistical or descriptive.
Referring to the documentation, it can work both for channels as well as videos and return us with their respective metadata.
To start with the API, we need an API key that could be generated using Developer Console.
Follow the below code to get content based on yourΒ queries.
The output will leave us with a JSON object, which could be later parsed and useful information can be extracted.
This would provide descriptive attributes of a video/channel.
To get statistical attributes, we need to take id from descriptive attributes and follow the following code.
Creating the PerfectΒ Formula?
Iβm not a big fan of YouTubeβs recommendation system. I think it lacks several important attributes or maybe I have got a peculiarΒ taste.
Now that Iβd got familiar with YouTube API and can easily generate useful information, it was time to switch on my creative machine and develop ranking metrics that could suit my preferences.
Several factors could make a good video. It could be the view count, watch duration, the satisfaction rate of video(like comment, share), or maybe more relatable tags to my searchΒ query.
The easiest approach would be to settle with a video with a high view count, but logically, if a channel has 10M subscribers then getting 100k views on a video wonβt be a big deal for him. But if some content of a channel with 10k subscribers hit 100k view count, we can infer the content was up to theΒ mark.
In that case, getting a view-to-subscriber ratio might be the best metric to choose relevantΒ videos.
But, the content of the channel with a low subscriber count can boost the ratio. I tweaked the code a little bit and added some limits and set the videos to have at least 10k views and 1k subscribers.
Further, view count and the number of subscribers couldnβt be the only measure of ranking. I introduced likecount-to-dislikecount ratio to further pick relevant and trustworthy content.
Adding the view-to-subscriber ratio and likecount-to-dislikecount ratio, I developed a score for eachΒ video.
It is universally assumed that any content on YouTube is at its prime time within 24β48 hours and fetch most views and satisfaction rate. But, contrary to the fact, I decided to keep it manual for eachΒ query.
To get a precise result, I also tweaked around with descriptive attributes and checked if the βqueryβ is present in both the title as well as description.
I counted the occurrence of queries in the title as well as the description. And followed the idea of βMore the Merrierβ.
And at the last step, I modified my final score function. First, focus on keyword in title and description, return with content with maximum content. Later return content with maximum view-to-subscriber ratio and likecount-to-dislikecount ratio.
Final Result
I tested my workflow for query βKubernetesβ and got following result.
The results fetched are great and reliable but in my opinion, things could get a littleΒ better.
Overall, it was a fun project revolving around the understanding of YouTubeβs API and YouTubeβs recommendation system workflow.
The workflow of the code can be concluded as:
- Manually enter the query, time frame, and API key to extractΒ videos.
- Filter videos according to Descriptive and Statistical attributes.
- Rank theΒ videos.
- Display theΒ output.
You can find the full code at myΒ Github.
Closing Thoughts
The project is still in its initial stages and could be improved a lot, some of the steps that can be taken into accountΒ are:
- The whole process of fetching personalized videos could be automated.
- A better metric implementation to get even betterΒ results.
- Deployment of the code on cloud servers for publicΒ use.
If you like this article, please consider subscribing to my newsletter: Daksh Trehanβs Weekly Newsletter.
Conclusion
Hopefully, this article has given you an insight into the YouTube recommendation system and how one can construct one forΒ them.
But, the information portrayed in this article regarding generic YouTube recommendation systems is solely based on some theories that are experienced by users or publicized by YouTube developers. The personalized algorithm could be pushed further to its limits and we can fetch even betterΒ results.
References:
[1] I created my own YouTube algorithm (to stop me wastingΒ time)
[2] How is YouTube using AI to recommend videos?
[3] Exploring YouTube Data API: Indian Pythonista
Find me on Web: www.dakshtrehan.com
Follow me at LinkedIn: www.linkedin.com/in/dakshtrehan
Read my Tech blogs: www.dakshtrehan.medium.com
Connect with me at Instagram: www.instagram.com/_daksh_trehan_
Want to learnΒ more?
How is YouTube using AI to recommend videos?
Detecting COVID-19 Using Deep Learning
The Inescapable AI Algorithm: TikTok
GPT-3 Explained to a 5-year old.
Tinder+AI: A perfect Matchmaking?
An insiderβs guide to Cartoonization using Machine Learning
How Google made βHum to Search?β
One-line Magical code to perform EDA!
Give me 5-minutes, Iβll give you a DeepFake!
Cheers
How I personalized my YouTube recommendation using YT API? was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.
Published via Towards AI