<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ankit Raj on Medium]]></title>
        <description><![CDATA[Stories by Ankit Raj on Medium]]></description>
        <link>https://medium.com/@srivastavaankit667?source=rss-33a966a395bd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HgOn_kKD-bhQ4ZVrB8Y8gA.jpeg</url>
            <title>Stories by Ankit Raj on Medium</title>
            <link>https://medium.com/@srivastavaankit667?source=rss-33a966a395bd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 09:51:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@srivastavaankit667/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Data Harvesting simplified using Python, Flask, and SQL]]></title>
            <link>https://medium.com/analytics-vidhya/data-harvesting-simplified-using-python-flask-and-sql-d7049fa14bea?source=rss-33a966a395bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7049fa14bea</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[data-harvesting]]></category>
            <category><![CDATA[etl]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Ankit Raj]]></dc:creator>
            <pubDate>Mon, 14 Dec 2020 13:13:00 GMT</pubDate>
            <atom:updated>2020-12-15T13:31:01.255Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/650/0*DADRx5XKOjoNipkz" /></figure><p>Ever thought of having an app that could be used as a search engine to query an API, harvest data, and perform basic ETL operations before dumping the processed data into a SQL table.</p><p>Seems a bit confusing?</p><p>Of course, as there is much processing required before that data could be used for analysis.</p><p>So, how about we build an app that handles all the data processing in the backend and keeps on populating a SQL table that we could use for further analysis.</p><p>Interesting enough? Buckle up then, it’s a long one…..</p><p><strong>First things first, what exactly are we harvesting and where are we storing the processed data?</strong></p><p>I build this app to harvest music data from Spotify API and store the processed data in a SQL server database. And, it goes without saying that you can modify this application as per your project requirements.</p><p>Now, before we jump into the interesting part of building the application, let’s first keep our database ready.</p><p><strong>How should database architecture look like?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*dtIApvWeT4QFFWgPj5vhWA.png" /><figcaption>Fig 1.1. SQL Database</figcaption></figure><p>As we can see from Fig 1.1, we will be needing a working table: WKR_SPOTIFY_DATA, to dump the raw data after processing, a final table: SPOTIFY_DATA, to store the data with correct datatypes, and a stored procedure: BLD_SPOTIFY_DATA, to insert data into the final table from the worker table.</p><p>Let’s just take a quick look at the two table designs and the stored procedure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fU6HH8dHLFZaKlARILEkqg.png" /><figcaption>Fig 1.2. Database table designs</figcaption></figure><p>So, our worker table just stores everything in VARCHAR format, and the final table stores them with the correct datatypes. We also have created columns for all the data that we need from Spotify, so now we have a clear idea of what we need to extract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*KapdTPWbcyOEbe-osZVOag.png" /><figcaption>Fig 1.3. Stored Procedure Declaration</figcaption></figure><p>First, we need to create a stored procedure and we will be performing two operations with this stored procedure that are explained below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*HQAu-50W6ivQQEk68FQdoA.png" /><figcaption>Fig 1.4. First functionality of the Stored Procedure</figcaption></figure><p>This step populates the final table with the data stored in the worker table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*bI0rdOzXjP-Zsi0SQTabpQ.png" /><figcaption>Fig 1.5. Second functionality of the Stored Procedure</figcaption></figure><p>Once the data is dumped into the final table, it is important to keep the worker table clean for the next data dump.</p><p>All right then, we have our database set up to store the processed data, it’s time to start building our app.</p><p><strong>How will our application make connections to the API and the database?</strong></p><p>We will be using spotipy to connect to the Spotify API and sqlalchemy to create the database connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*HJuLxIxu5n_2gUYzRHUJUQ.png" /><figcaption>Fig 2.1. Connection Manager</figcaption></figure><p>A simple class to handle the different connection requests will always come in handy when dealing with multiple connection requests.</p><p>Now that we have got different connections covered, as shown in Fig 2.1, it’s time to proceed to the main part of this project, and yes you guess it right, it’s time to create the architecture for extracting and processing the required information from the Spotify API request.</p><p><strong>What functionalities do we need to harvest and process the extracted data?</strong></p><p>Just to be clear, as the main focus of this article is on building a flask application, I won’t be going into details about each of the functionalities. I, however, will share the article in references that guided me while building this application.</p><p>But, nothing to worry about, we will still discuss each of the functionality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*wzbsQ7volZA97959KnVO9A.png" /><figcaption>Fig 3.1. Spotify Data Harvestor Construction</figcaption></figure><p>So, here’s what our constructor looks like, as shown in Fig 3.1., we have instantiated all the variables that we will be needing throughout the class. We will be passing the Spotify connection, database engine, artist URI, and artist name when creating an object of this class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*M4L1vKnT_ItGgUyCn55GVQ.png" /><figcaption>Fig 3.2. Function to extract the song features from an album</figcaption></figure><p>A pretty straight forward functionality, shown in Fig 3.2, to extract the various features of a song using an album URI. As initially shown in our database tables, we need song features like album name, track number, song id, song name, and song URI from Spotify.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*YSgFvbeSoIDC8RGasqGlzQ.png" /><figcaption>Fig 3.3. Function to extract the audio features of an album songs</figcaption></figure><p>We surely need more information about a song track, if have to perform some kind of audio analysis, right?</p><p>Well yeah, and thankfully Spotify even got us covered in terms of the different audio features, required for any kind of audio analysis. All we need to do is to make the correct API call to Spotify.</p><p>The function shown in Fig 3.3 covers all the steps required to extract the audio features of all the tracks of an album.</p><p>Alright, so we have created the functions required to extract the features that we need, it’s time to start processing them into a pandas dataframe and finally dump them into the database worker table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xd0RQoQZKbkUDvwoOaKEvw.png" /><figcaption>Fig 3.4.1. Function to call the extraction methods</figcaption></figure><p>The first part of our final method for building a database table, Fig 3.4.1, calls the extraction methods so that the spotify_albums dictionary instantiated in the constructor is ready for building our final pandas dataframe.</p><p>Just make sure not to overkill the API calls when iterating over the Spotify albums, I would suggest calling the sleep function after every 5 iterations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bvpgWVCR9bE3lsCROhOvig.png" /><figcaption>Fig 3.4.2. Function to build the dataframe and dump data into worker table</figcaption></figure><p>We have now extracted all the song and audio features. The last thing left, before we start dumping the data into the worker table, is to use a dictionary and extend it over all the album features. We will be converting this dictionary into a pandas dataframe, as pandas provides functionality to convert the dataframe directly into a SQL table.</p><p>A few important things to note here:</p><ul><li>We will be passing the name of our worker table in the database,</li><li>Sqlalchemy engine will be passed as the connection (don’t worry I will show you that configuration as well),</li><li>Make sure you keep if_exists=’append’, so that you don’t create a new table in each session and use the existing table,</li><li>Just keep index=False, we don’t need indexing here,</li><li>We need multiple data to insert, so we need to keep method=’multi’,</li><li>And keep the chunk to a safe size of 100, so that we don’t run into some issue while the data dump.</li></ul><p>Now that we have got data dumped into our worker table, the next thing left is to perform a little transformation to dump the data from the worker table to the final table.</p><p>And, guess what we already have a stored procedure ready to take care of that for us. So, all we need to do is to call that stored procedure, right?</p><p>Well, let’s see how easily can we do that with the help of the sqlalchemy engine, created in the Connection Manager.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*kjuCRnmU3BTNg9_um3r1Ew.png" /><figcaption>Fig 3.5. ETL Architecture for the final transformation</figcaption></figure><p>Alright then, we have created the entire backend required for our app.</p><p>And the good thing is that along with that all the heavy lifting is done, what’s left is just to create a web app and obviously a few more lines of code. And, trust me with a tool like flask, it will be a piece of cake.</p><p><strong>How do we build our flask web application?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*i0hTLeCKzSf0M10STsDPVg.png" /><figcaption>Fig 4.1. Call the dependencies</figcaption></figure><p>Before we start building our flask app, make sure you call all the dependencies, as shown in Fig 4.1, before we move on to the application building.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3K85TfIe7ORcY7uf98smmg.png" /><figcaption>Fig 4.2. Flask App Architecture</figcaption></figure><p>We are now ready with all the required dependencies, we can now start building the flask app.</p><p>Let’s try to simplify the steps required for our flask app, as shown in Fig 4.2.</p><ul><li>Create a flask app.</li><li>Define the __name__ variable to run the flask app.</li><li>Build a function that renders the home page on running the application, and the flask way to handle that is with a simple annotation that routes to home page denoted by ‘/’.</li><li>Build a function that takes input from the user in the form of a request, from the web page, and makes a call to the backend operations explained above. Our extract method does exactly that and again make sure to annotate the method with the web page extension, denoted by ‘/extract’.</li><li>Finally, just to give an overview of the functionality of the extract method, it takes a user input, queries the Spotify API, using the Spotify connection created in the Connection Manager, to extract all the artist URI and artist name for all the items of a track, stores them in a dictionary, as shown in Fig 4.2., calls the SpotifyDataHarvester for each item in the dictionary to dump the data into the worker table, and finally when the worker table is prepared, calls the ETL to build the final table.</li><li>And, now all that’s left for you is to design and built a UI for this app. You can refer to my GitHub repository, mentioned below, for the UI design that I used.</li></ul><p>Phewww….. that was a lot of code, wasn’t it?</p><p>So, just give yourself a few moments of peace, before we jump into the good stuff.</p><p>And, I believe you already know what’s left to do.</p><p>Yes, you are absolutely right!</p><p>It’s time to give our app, a test run. So, let’s get done with that.</p><p><strong>Final App Testing</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kb8sFDzJa4Y1Oo9Byv_onA.png" /><figcaption>Fig 5.1. Home Screen</figcaption></figure><p>Okay… so our app looks nice, and the home page loaded without any issue. Let’s try harvesting some data for a track.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5RfzGg3sEo9i7CuyQgzhvw.png" /><figcaption>Fig 5.2. Harvesting in process</figcaption></figure><p>So, the harvest has started, let’s take a quick look at what’s happening behind in the console screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*bVZJChfQ0ijFAbPRzEuToA.png" /><figcaption>Fig 5.3. Backend Processing Console Screen</figcaption></figure><p>Looks like the data extraction is going well and some data is already dumped into the working table. God! Don’t you love these little print statements………</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FC3ABoGhRaPXC8d3yj30Aw.png" /><figcaption>Fig 5.4. Harvest complete screen</figcaption></figure><p>Finally, the harvest is completed, we got our sweet little completion message.</p><p>Now it’s time to see our final table is populated or not, plus the worker table should be truncated after each harvest as we discussed earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c1j4JJ-MP596IzkQlbrNKQ.png" /><figcaption>Fig 5.5.1. Final Table</figcaption></figure><p>Ahaa.. we got our final table populated, let’s just make sure the worker table is truncated, before we wind up and celebrate all the hard work, we just did.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mk0U53XYCY76-2hH-2NaTA.png" /><figcaption>Fig 5.5.2. Worker Table</figcaption></figure><p>Here we go, the worker table is truncated, as expected, after the harvest.</p><p>God, this was a long tour, wasn’t it…?</p><p>But, thanks a lot for keeping up with me this long.</p><p>I hope this app will help ease up the mundane data harvesting process and you will rather start enjoying the data harvest…</p><p>You can find the full project on my GitHub repository mentioned below,</p><p><a href="https://github.com/AnkitRajSri/Music_Data_Extractor">https://github.com/AnkitRajSri/Music_Data_Extractor</a></p><p>Happy harvesting…..</p><p><strong>References:</strong></p><p><a href="https://medium.com/better-programming/how-to-extract-any-artists-data-using-spotify-s-api-python-and-spotipy-4c079401bc37">How to Extract Any Artist’s Data Using Spotify’s API, Python, and Spotipy</a></p><p><a href="https://rareloot.medium.com/extracting-spotify-data-on-your-favourite-artist-via-python-d58bc92a4330">https://rareloot.medium.com/extracting-spotify-data-on-your-favourite-artist-via-python-d58bc92a4330</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7049fa14bea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/data-harvesting-simplified-using-python-flask-and-sql-d7049fa14bea">Data Harvesting simplified using Python, Flask, and SQL</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Text Processing made easy with textslack]]></title>
            <link>https://medium.com/analytics-vidhya/text-processing-made-easy-with-textslack-4214ae6bc67a?source=rss-33a966a395bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/4214ae6bc67a</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-preprocessing]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[text-analysis]]></category>
            <dc:creator><![CDATA[Ankit Raj]]></dc:creator>
            <pubDate>Fri, 09 Oct 2020 22:47:42 GMT</pubDate>
            <atom:updated>2020-11-09T22:38:34.186Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/859/0*Rkm5bqN0qC2bgnyg.jpeg" /></figure><p>Whenever we think about natural language processing (NLP) tasks, what is the first thing that comes into our mind? Yes, you guess it right, Text Processing. And what exactly we mean when we use the term text processing? In simple words, it is the process of transforming text into a form that could be digested by machine learning algorithms.</p><p>Well, we are not going to talk about the entire text processing process here, but rather we will discuss and utilize a pre-built library that deals with some of the preliminary and most important steps required in text processing, and that is text cleaning and generating insights from text.</p><p>You might have noticed, whenever we have to deal with unstructured text data, we basically end up writing the same piece of code every time. Wouldn’t it be great if we have an architecture or a library that could deal with the mundane task of text cleaning and feature extraction for us?</p><p>“textslack” is one such architecture that I built that cleans your text data and also includes additional functionalities to extract useful insights from the text.</p><p>So, let’s just jump right into it, shall we?</p><p>First things first, where do we get this package from? Well, like most of the python packages available open-source, it’s just a pip install away.</p><p>So, here we go…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RALzYY9aFsxuPh0mlHXQRQ.png" /></figure><p>Tada… it’s installed in no time.</p><p>Now, let’s move on to the part where we import this library in our notebook or IDE, whatever you prefer. I usually prefer a notebook for initial analysis before utilizing the code for the main project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EuF0tHMowfbe8e1SNxM6Mg.png" /></figure><p>And, it’s done, ignore the future warnings though.</p><p>Some of you, however, may face a few of the nltk download errors while importing the library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*rDMj5n80tZPuOoc2hplArA.png" /></figure><p>Nothing to worry though, you just need to import nltk, download the missing resource, and import textslack again, respectively in that order. I will, however, include these resources in the next version release.</p><p>Now, that we have imported the library, let’s give it a try on some random text data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v_2VXQnozi5J55j361ikjQ.png" /></figure><p>For that, we just need to create an instance of the TextSlack module that we imported from textslack and call the transform method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-jZC0fDeCFB1IWwdQkkzhg.png" /></figure><p>Easy, isn’t it? The text has been normalized and cleaned of all the stop words, punctuations, etc. in a single function call.</p><p>But, that’s just text cleaning, what about the other features that I talked about earlier? Don’t worry! we are gonna cover everything that textslack has to offer.</p><p>What if, we were only interested in the nouns, or verbs, or adjectives, present in a text? Let’s give that thought a try and try to clean the text off everything, but adverbs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*2IZd2Y13yIkBraEiK7auqA.png" /></figure><p>Hmm… seems like we only have one adverb in our text.</p><p>Anyway, we can similarly filter out the text for nouns, verbs, and adjectives by calling extract_nouns, extract_verbs, and extract_adjectives functions respectively.</p><p>So, now we have seen everything textslack has to offer in terms of cleaning, let’s see what other insights can we extract.</p><p>What about the overall sentiment of the text? Well, let’s see.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*f407kVtdwZMv87E8-Sb_yg.png" /></figure><p>We got an overall negative sentiment, which is somehow justified because of the word “hate”, which has a really high sentiment polarity, present in the text.</p><p>Now, coming on to the final feature of the library, let’s see how many times the word “movie” has been mentioned in the text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*-d-93G9iUgWdKyKvm-bn7A.png" /></figure><p>To avoid any confusion, for now, it’s simply giving us the frequency of a word in its mentioned form, not the frequency of the word in its base form. So, it won’t count if the word “movies” was present in the text. I know, it’s not exactly what we were looking for. But, this will be taken care of in the next version release.</p><p>So, yeah that was all about the basic functionalities of textslack, keep checking for new features in future version updates.</p><p>Thank you for your attention, I hope, you all will give it a try, and hopefully, this library will be helpful in dealing with your text analysis.</p><p><strong>Library link:</strong></p><p><a href="https://pypi.org/project/textslack/">https://pypi.org/project/textslack/</a></p><p><strong>References:</strong></p><ul><li><a href="https://towardsdatascience.com/nlp-text-preprocessing-and-cleaning-pipeline-in-python-3bafaf54ac35">NLP Text Preprocessing and Cleaning Pipeline in Python</a></li><li><a href="https://towardsai.net/p/data-mining/text-mining-in-python-steps-and-examples-78b3f8fd913b">Text Mining in Python: Steps and Examples</a></li></ul><p><a href="https://towardsdatascience.com/text-cleaning-methods-for-natural-language-processing-f2fc1796e8c7">https://towardsdatascience.com/text-cleaning-methods-for-natural-language-processing-f2fc1796e8c7</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4214ae6bc67a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/text-processing-made-easy-with-textslack-4214ae6bc67a">Text Processing made easy with textslack</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Content-based Movie Recommender System]]></title>
            <link>https://medium.com/analytics-vidhya/content-based-movie-recommender-system-c684d663ee38?source=rss-33a966a395bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/c684d663ee38</guid>
            <category><![CDATA[recommendation-system]]></category>
            <category><![CDATA[machine-learning-python]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Ankit Raj]]></dc:creator>
            <pubDate>Sun, 02 Aug 2020 16:11:28 GMT</pubDate>
            <atom:updated>2020-09-12T15:43:45.977Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cPa0_xoPiLC3l5khvyGy0w.png" /></figure><p><strong>Abstract</strong></p><p>Content-Based Movie Recommender System built using the cosine similarity scores</p><p><strong>Table of Content</strong></p><p>1. Executive Summary</p><p>2. Introduction</p><p>3. Algorithm</p><p>3.1. Content-Based filtering</p><p>3.2. Cosine Similarity</p><p>4. Objective</p><p>5. Methodology</p><p>5.1. Sample Database schema</p><p>5.2. Python-Oracle Database connection</p><p>5.3. Preparing the sample dataset</p><p>5.4. Identifying the highest rated movies and getting the best movie details</p><p>5.5. Merging key features and building a cosine similarity matrix</p><p>5.6. Generating Recommendations</p><p>5.7. Results</p><p>6. Conclusion</p><p>7. Project Repository</p><p>8. References</p><p><strong>1.</strong> <strong>Executive Summary</strong></p><p>Whenever we visit a digital platform, we no longer need to worry about what to watch next as we are served with a bunch of recommendations to choose from. But how exactly the platform decides what to recommend to a specific user, and if the user is going to like that.</p><p>In this project, we attempt to build a specific kind of recommendation system by extending the RELMDB oracle database. We attempt to build a recommender system that identifies the best movie, based on the number of IMDb votes and the average IMDb rating, and suggest movies with similar content to the user. We start by importing and munging data from the oracle database to create our base dataset. We, then, identify the best movie and use the cosine similarity algorithm to recommend the top 10 similar movies to the user.</p><p><strong>2.</strong> <strong>Introduction</strong></p><p>A recommender system is a type of information filtering system that attempts to predict a user’s preferences and makes suggestions, based on these preferences.</p><p>Recommender Systems have become ubiquitous in our lives and have implementations in a wide range of online platforms that we use. Whether we want to purchase online, having trouble deciding which song to listen or what to watch next, in the need of a new friend or looking for someone to date, there are recommendations available for almost everything, we need from an online platform. Even the google search results consider a user’s preferences and the results vary for different users. These systems are, often, able to collect information about a user’s choices and can use this information to improve future suggestions. These recommender systems consider different factors like popularity, the similarity between items, and even similarity between different users’ choices and can use these approaches to improve suggestions in the future. If Netflix, for instance, notices that the trailer of a newly launched Netflix original shared on Facebook is liked by some users, it can use this information to recommend this show to the specific users as soon as the show is released on Netflix. Similarly, if Netflix notices that some users have reacted negatively to some content shared on Facebook, it can resist recommending such content to those users. Additionally, the recommender systems can make recommendations based on the content of a show watched or liked by a user. For example, if Prime Videos observe a user has watched plenty of highly-rated sci-fi movies, it will look for other sci-fi movies with similar content and ratings and suggest those movies to the user.</p><p>Though there are plenty of approaches to build a recommender system, this project specifically focuses on a special type of movie recommender system that digs into the details of a movie with the highest number of IMDb votes and highest average IMDb rating, and considering it as the best movie, it recommends top 10 movies having similar content.</p><p><strong>3.</strong> <strong>Algorithm</strong></p><p>For our project, we focused on Content-based filtering for generating recommendations.</p><p><strong>3.1.</strong> <strong>Content-Based Filtering</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*qw5w1ClAW0DEdGzI5kUs2g.png" /><figcaption><strong>Fig 3.1. Content-Based Filtering</strong></figcaption></figure><p>Content-Based filtering doesn’t involve other users, but based on our preference, the algorithm will simply pick items with similar content to generate recommendations for us.</p><p>This algorithm offers less diverse recommendations, but it will work regardless of the fact of whether user rates things or not.</p><p>For example, there can be a situation where a user potentially likes sci-fi action movies, but he might never know unless he decides to give it a try autonomously. So, what this filter does, it will keep on recommending superhero movies or similar. We can calculate this similarity on many attributes, but in our case, we build this recommender system based on the following key features:</p><p>· IMDb Vote</p><p>· Mean IMDb Rating</p><p>· Genre</p><p>· Director</p><p>· Cast Member and Cast Role</p><p>· Movie Year</p><p>· User-specific tags</p><p>Now, moving forward to the term that we keep on mentioning, similarity, and what it means in our context. It might not seem like something we could quantify, but it can be measured. Before we proceed to the methodologies, we used to build our content-based recommender system, let’s briefly discuss the concept of cosine-similarity, one of the metrics that can be used to calculate the similarity between users or contents.</p><p><strong>3.2.</strong> <strong>Cosine Similarity</strong></p><p>Cosine Similarity can be defined as a method to measure the difference between two non-zero vectors. In our case, the film title and the key movie features represent the coordinates of a movie vector. Thus, in order to calculate the similarity between the two movies, if we know the film title and key features of both the movies, we just need to calculate the difference between the two movie vectors.</p><p>The cosine similarity formula can be mathematically described as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*0n2aHtmTwDolc5Y7dSm-OA.png" /><figcaption><strong>Fig 3.2. Cosine Similarity formula</strong></figcaption></figure><p>A.B = Dot product between the two movies vectors,</p><p>||A||||B|| = Product of the magnitudes of the two movie vectors</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*4ub83DgxaqIWtNtyWxGchQ.png" /><figcaption><strong>Fig 3.3.</strong> <strong>Movie vectors representation</strong></figcaption></figure><p>As shown in Fig 3.3., the area below the movie vectors A and B, represent the contents of the movies, and the angle, θ, between them represents the similarities between the movie contents. Thus, the lower the angle θ, the more similar the movie contents are.</p><p>The cosine similarity values can range between 0 and 1, depending on the θ value bounded between 0 and 90.</p><p><strong>4.</strong> <strong>Objective</strong></p><p>The proposed recommender system attempts to identify the movies with contents similar to the best movie using a detailed movie dataset created by merging different tables imported from the RELMDB oracle database. The objective is to create recommendations of the movies, based on their similarity scores with the best-rated movie. Based on the similarity scores, the recommender system would be able to identify the top 10 movies having the highest similarity scores and present them as the top 10 recommendations.</p><p><strong>5.</strong> <strong>Methodology</strong></p><p><strong>5.1.</strong> <strong>Sample Database schema</strong></p><p>To build the content-based movie recommender system, the oracle database is used to extend the RELMDB database, modify the tables as per and add a few tables as per our requirement. Below is the final database schema that we have used, in order to create a detailed dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*c1WH4zbYab0Fxeq_mryWPg.png" /><figcaption><strong>Fig 5.1.</strong> <strong>Movie Database Schema</strong></figcaption></figure><p><strong>5.2.</strong> <strong>Python-Oracle Database Connection</strong></p><p>To import the database tables to the python class, <strong>cx_oracle</strong> library is used to create a connection with the oracle database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*gFtra3aPxBBCP-E32lD5Kg.png" /><figcaption><strong>Fig 5.2. Database Connection</strong></figcaption></figure><p><strong>5.3.</strong> <strong>Preparing the sample dataset</strong></p><p>Pandas library functions are used to create the sample dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*SxrriusdFNZEbugra8MR8w.png" /><figcaption><strong>Fig 5.3. Data Preparation</strong></figcaption></figure><p><strong>5.4.</strong> <strong>Identifying the highest rated movies and getting the best movie details</strong></p><p>After sorting the detailed movies dataset by the number of IMDb votes, the mean IMDb ratings are calculated for the movies, and the movie with the highest average IMDb rating is considered as the best or the highest rated movie.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*zjhxs_7Ynj1XTs3-4JoO-Q.png" /><figcaption><strong>Fig 5.4. Identifying the best movie</strong></figcaption></figure><p><strong>5.5.</strong> <strong>Merging key features and building a cosine similarity matrix</strong></p><p>To fit a 2D count vector of the scikit-learn library, all the key features of the movies are merged in a single column and the cosine similarity method of the scikit-learn library is used to create a cosine similarity matrix with the count movie vectors used as the input matrices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*f-PVMBJdsiEwmMEtL1TG-A.png" /><figcaption><strong>Fig 5.5. Cosine Similarity Matrix</strong></figcaption></figure><p><strong>5.6.</strong> <strong>Generating Recommendations</strong></p><p>Top 10 movies are then sorted based on the cosine similarity scores and returned as the final recommendations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*21Wp8_PuXZduuTGbiogJQg.png" /><figcaption><strong>Fig 5.6. Generate Recommendations</strong></figcaption></figure><p><strong>5.7.</strong> <strong>Results</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*a2sMhVtKCFHKBUyL-2kbFg.png" /><figcaption><strong>Fig 5.7. Recommendation Results</strong></figcaption></figure><p>To evaluate the top 10 recommendations generated by our recommender system, we then compared the recommended movies with the best-rated movie “The Shawshank Redemption”, by running a SQL Script showing the key features like the IMDb ratings, IMDb votes and the film year.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*NjhoBA4DbFHbkdzM3DnLYA.png" /><figcaption><strong>Fig 5.8. Comparison between the recommended movies profiles</strong></figcaption></figure><p>By observing these key features, we can see that the recommended movies have a similar profile based on these key features.</p><p><strong>6.</strong> <strong>Conclusion</strong></p><p>To conclude, a recommender system powered by content-based filtering performed using the cosine similarity algorithm can make better recommendations for users by suggesting them movies that have similar key features like the IMDb votes, average IMDb rating, genre, release year, casts, directors, user tags, etc.</p><p><strong>7.</strong> <strong>Project Repository</strong></p><p>Please visit my GitHub repository.</p><p><a href="https://github.com/AnkitRajSri/MovieRecommenderSystem">https://github.com/AnkitRajSri/MovieRecommenderSystem</a></p><p><strong>8.</strong> <strong>References</strong></p><p><a href="https://pdfs.semanticscholar.org/767e/ed55d61e3aba4e1d0e175d61f65ec0dd6c08.pdf">https://pdfs.semanticscholar.org/767e/ed55d61e3aba4e1d0e175d61f65ec0dd6c08.pdf</a></p><p><a href="https://medium.com/@bkexcel2014/building-movie-recommender-systems-using-cosine-similarity-in-python-eff2d4e60d24">https://medium.com/@bkexcel2014/building-movie-recommender-systems-using-cosine-similarity-in-python-eff2d4e60d24</a></p><p><a href="https://link.springer.com/chapter/10.1007/978-3-642-21793-7_63">https://link.springer.com/chapter/10.1007/978-3-642-21793-7_63</a></p><p><a href="https://www.kdnuggets.com/2019/04/building-recommender-system.html">https://www.kdnuggets.com/2019/04/building-recommender-system.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c684d663ee38" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/content-based-movie-recommender-system-c684d663ee38">Content-based Movie Recommender System</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>