<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jinhoon Chung</title>
    <description>The latest articles on DEV Community by Jinhoon Chung (@ddjh20482).</description>
    <link>https://dev.to/ddjh20482</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F834414%2F2c48a293-d887-4813-a2bd-22186da7a8c4.jpg</url>
      <title>DEV Community: Jinhoon Chung</title>
      <link>https://dev.to/ddjh20482</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ddjh20482"/>
    <language>en</language>
    <item>
      <title>A New Way to Recommend Video Games at Amazon Part 3</title>
      <dc:creator>Jinhoon Chung</dc:creator>
      <pubDate>Wed, 18 Jan 2023 15:23:22 +0000</pubDate>
      <link>https://dev.to/ddjh20482/a-new-way-to-recommend-video-games-at-amazon-part-3-1o8</link>
      <guid>https://dev.to/ddjh20482/a-new-way-to-recommend-video-games-at-amazon-part-3-1o8</guid>
      <description>&lt;p&gt;This is part 3 of the whole post. Please refer to the links below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ddjh20482/a-new-way-to-recommend-video-games-at-amazon-part-1-34op"&gt;part 1&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/ddjh20482/a-new-way-to-recommend-video-games-at-amazon-part-2-2lbe"&gt;part 2&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Intro&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In the previous parts, I built a new recommendation system and shown you if the system has value or not. Let's try to display a more personalized list of recommended games for a customer.&lt;/p&gt;

&lt;p&gt;Here is a graph of the numbers of recommended games by predicted ratings.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uErUMaQn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x87n3jvmhdauv443whsy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uErUMaQn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x87n3jvmhdauv443whsy.png" alt="many rating 5" width="540" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is one of the critical cases where one customer would be recommended with above 14,000 games with the predicted rating equaling 5. Amazon would love it if this customer would buy all of them, but it is not very realistic. Let's try to trim down this long list.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Similarity&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;One of the straight forward ways to trim down the long list is to use the game information and find similarities between different games. Examples of information are console information and company information. Unfortunately, the metadata does not contain genre information.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6NT1_bZe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1z9gw1ygvwom0of5zm1z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6NT1_bZe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1z9gw1ygvwom0of5zm1z.png" alt="game_information" width="557" height="133"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Do you see some familiar names? Let's pick one game.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i8pdQ3dE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ug1ftm151zsqgkp44of3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i8pdQ3dE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ug1ftm151zsqgkp44of3.png" alt="selected_game" width="334" height="45"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a famous game owned by Capcom. This game runs on PC, Playstation, and Xbox, but the selected game is for the Xbox console. With a matrix calculation that compares 72,000 game information to the selected game, I can get values from 0 to 1 where 1 means the perfect match, and 0 means no information match.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2FqF_nTo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hfmk18nr5tb64nse2mj7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2FqF_nTo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hfmk18nr5tb64nse2mj7.png" alt="0_to_1" width="135" height="232"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you look at the third row from the bottom, you can see there are 16 games that have the perfect match with the selected game. However, it is actually 15 because one of 16 is the selected game. During matrix calculation, the selected game was compared to all games including itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Trimming the List&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The following step is simple. The similarity ratios are multiplied by the predicted ratings. This is possible because each game is given a similarity ratio and a predicted rating. Even with a high predicted rating, the game would be ranked lower if the similarity ratio is low.&lt;/p&gt;

&lt;p&gt;Let's check out the final list of the top 10 recommended games.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ol1kHMJk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1t8cpj4756lnyy9y4t3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ol1kHMJk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1t8cpj4756lnyy9y4t3.png" alt="top_10" width="667" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can observe other series of Resident Evil. Please ignore the same name as the selected game located in the 4th row. I know that "DMC Devil May Cry", "Strider", and "Mega Man" are from the same company. Except for "Strider" and "Mega Man", all games are 3D graphics.&lt;/p&gt;

&lt;p&gt;Here are the final predicted ratings after multiplying by similarity ratios. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TUZB5rwv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bxvsr92k15e5iryrqlgj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TUZB5rwv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bxvsr92k15e5iryrqlgj.png" alt="final_ratings" width="488" height="44"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first six games still have the perfect predicted rating. The predicted rating starts to be smaller from the 7th game. I do think these numbers would look more interesting if the metadata has genre information because one game has multiple genres.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Final Note&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I personally enjoyed this project because the chosen topic was motivating to me. There are several elements that can be improved. If all of these ideas are finalized, then the next steps are to discuss where and how to put this information for which customers and if these ideas can be applied to the different departments. This was a project completed for the data science Bootcamp program, but I have tried to work it out as if this is a real problem. &lt;/p&gt;

&lt;p&gt;Thank you for reading.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ddjh20482/recommender_system_amazon"&gt;Project GitHub Link&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>A New Way to Recommend Video Games at Amazon Part 2</title>
      <dc:creator>Jinhoon Chung</dc:creator>
      <pubDate>Wed, 18 Jan 2023 15:04:54 +0000</pubDate>
      <link>https://dev.to/ddjh20482/a-new-way-to-recommend-video-games-at-amazon-part-2-2lbe</link>
      <guid>https://dev.to/ddjh20482/a-new-way-to-recommend-video-games-at-amazon-part-2-2lbe</guid>
      <description>&lt;p&gt;This is part 2 of the whole post. Please refer to &lt;a href="https://dev.to/ddjh20482/a-new-way-to-recommend-video-games-at-amazon-part-1-34op"&gt;part 1&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Intro&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A new recommendation system was built in the previous section. It is time to check if the new system has value. It would be tough and complex to figure out if a customer would have a better or worse shopping experience using the system. However, computation and interpretation become more simple if we like to find out if a customer would have a &lt;strong&gt;different&lt;/strong&gt; shopping experience. We will use a hypothesis test and calculate p-values.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Simple Case&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let's pick one customer and one game. Let's say the selected game has an average given rating equaling 1. However, the system predicts the selected customer would rate the selected game 4.76. We can say the system is likely to draw more attention from the customer. In other words, the customer would stop by and check the item which is normally ignored because of the low given rating. This can happen in the opposite direction. This is the case for different shopping experiences.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4A611yeA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ng7j8dudptu4456olepz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4A611yeA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ng7j8dudptu4456olepz.png" alt="pipeline" width="880" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;One Customer with a List of Games&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let's stay with one customer, but we want to check a list of games. The new system predicts ratings on the games, and the games are assigned with average given ratings.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jWVY6oQJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4fbefdp2ilv20yw1l57r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jWVY6oQJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4fbefdp2ilv20yw1l57r.png" alt="table with given ratings and predicted ratings" width="441" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here comes the hypothesis test. We like to know if the given ratings and predicted ratings are significantly different or not. Using the t-test, we can get a p-value for this case. If the p-value is low enough (less than 0.05), then the two lists are different enough. This can conclude this customer would have a different shopping experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;More Customers with a List of Games&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We need to be careful when calculating p-values. There are around 72,000 games in the data. If we compare two types of ratings on all games, p-values will be significant even with a small difference. To solve this issue, the number of games needed to get p-values should be small enough. Normally 30 sample games should be enough, but 50 games might be ideal because I usually check out more than 50 items when shopping, and 30 sounds too small compared to the 72,000 games found in the data. Lastly, Amazon displays 50 games in a specified &lt;a href="https://www.amazon.com/gp/most-wished-for/videogames?ref_=Oct_d_omwf_S&amp;amp;pd_rd_w=Ao5JS&amp;amp;content-id=amzn1.sym.930be8dd-97e5-4e05-b36b-ce7259eebc0a&amp;amp;pf_rd_p=930be8dd-97e5-4e05-b36b-ce7259eebc0a&amp;amp;pf_rd_r=03FANJH49RP59KB9VZHA&amp;amp;pd_rd_wg=rKWWs&amp;amp;pd_rd_r=094c5286-ef1e-4939-8ea6-193c1bc864bf"&gt;page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;While there are around 72,000 games, there are around 1.5 million customer ids in the data. It would cost too much to check 1.5 million individuals. I decide to sample 500 customers with one condition. The customers should have ratings on at least 5 games. The previous section, "One Customer with a List of Games", is repeated 500 times. Therefore, we get 500 p-values.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UCt7_6pl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nw4mqwo4sjewx81al1q2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UCt7_6pl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nw4mqwo4sjewx81al1q2.png" alt="scatter p_value" width="636" height="628"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The red dots show p-values less than 0.05. It turns out that more than 60% of p-values are red dots meaning those customers would have a different shopping experience. I think it is a good number, but it would be Amazon's choice if this sounds like a better business or marketing.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Metadata with Average Given Ratings&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I wanted to put this section away from previous sections to keep a good flow of the analysis. I have shown you the comparison between average given ratings vs. predicted ratings. It is true that one game is rated more than once. To find a representable rating for each game, we can just calculate the average given ratings. Then, a table would be created with unique game ids and average given ratings. Metadata also has game ids (asin). After removing some duplicates, the unique game ids in the metadata would be merged with the table with the average given ratings. Then, these given ratings are compared with the predicted ratings shown in the previous sections.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7PM_VwFF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xy5r5sn8s8e1ojube5c3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7PM_VwFF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xy5r5sn8s8e1ojube5c3.png" alt="meta data example" width="857" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;In the Next Section&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I have gone over all steps above, but there is no realistic output from this analysis. One major reason is that the list of recommended games is too large. In part 3, I will show you how the list can be trimmed and finally show you a useful result.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ddjh20482/recommender_system_amazon"&gt;Project GitHub Link&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/ddjh20482/a-new-way-to-recommend-video-games-at-amazon-part-3-1o8"&gt;Part 3&lt;/a&gt;&lt;/p&gt;

</description>
      <category>recommender</category>
      <category>amazon</category>
      <category>videogames</category>
      <category>python</category>
    </item>
    <item>
      <title>A New Way to Recommend Video Games at Amazon Part 1</title>
      <dc:creator>Jinhoon Chung</dc:creator>
      <pubDate>Wed, 18 Jan 2023 14:36:37 +0000</pubDate>
      <link>https://dev.to/ddjh20482/a-new-way-to-recommend-video-games-at-amazon-part-1-34op</link>
      <guid>https://dev.to/ddjh20482/a-new-way-to-recommend-video-games-at-amazon-part-1-34op</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Intro&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I have completed the Capstone project, and this post is a summary of it. I decided to build a new recommendation system for video games at Amazon.com. The reasons are the followings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I play lots of video games.&lt;/li&gt;
&lt;li&gt;I do shopping at Amazon.com&lt;/li&gt;
&lt;li&gt;35% of Amazon's revenue is from the recommendation system. &lt;a href="https://www.mckinsey.com/industries/retail/our-insights/how-retailers-can-keep-up-with-consumers"&gt;link&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;I don't see a recommendation system that specifically uses customer's ratings at Amazon.com&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are already various recommendations that use "items bought together", "browsing history", "similar products", etc. More than half of the recommended items at Amazon.com are not relevant to my interest, and many items are similar to what I already have and won't buy again.&lt;/p&gt;

&lt;p&gt;It gets even worse when looking at the page for the video game department. Amazon is busy showing the top-selling or top-rated items, new releases, and items with special discounts. I don't feel like the page is personalized.&lt;/p&gt;

&lt;p&gt;The page might gain more attention if Amazon can add a section with a personalized list of recommended games.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Outline&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I plan to write three posts outlined below. This post focuses on the first part.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Introduction and building a recommendation list using customer ratings&lt;/li&gt;
&lt;li&gt;Proving customers would have a different shopping experience&lt;/li&gt;
&lt;li&gt;Trimming down a long list of recommended games and wrapping up&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Data&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;There is a database released by Amazon. There are two parts to the database, review data and metadata. If the links to the two separate datasets below do not work, please use &lt;a href="https://nijianmo.github.io/amazon/index.html"&gt;this link&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Review Data&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The data can be downloaded &lt;a href="http://deepyeti.ucsd.edu/jianmo/amazon/categoryFilesSmall/Video_Games.csv"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;This dataset has four columns, item id (video game id), user id, rating, and timestamp. We do not need the timestamp column for this analysis.&lt;/p&gt;

&lt;p&gt;Here are the first 5 rows of the data.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1Etm7zRu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2cwqn0azoska0wllhmsi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1Etm7zRu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2cwqn0azoska0wllhmsi.png" alt="first 5 rows" width="273" height="174"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the count for each rating and overall distribution. We can see ratings are from 1 to 5, and the majority (58%) of ratings are 5.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xfDrHX4Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c8lq5pmffspt59ktv1yu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xfDrHX4Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c8lq5pmffspt59ktv1yu.png" alt="count" width="101" height="87"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oherjCbk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/igfjdqcy98h7xfhzcjyu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oherjCbk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/igfjdqcy98h7xfhzcjyu.png" alt="distribution" width="440" height="512"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;MetaData&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The data can be downloaded &lt;a href="http://deepyeti.ucsd.edu/jianmo/amazon/metaFiles2/meta_Video_Games.json.gz"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;This metadata has various information on video games, but we only need item id, console information, and company information. Unfortunately, this data does not have genre information. &lt;/p&gt;

&lt;p&gt;This data will be crucial for the second and third parts. I will show you how this data is clean in the second part. We only need the review data for the current part.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Analysis - Building a System&lt;/strong&gt;
&lt;/h2&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Train-test-split&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The data is split for validation purpose.&lt;/p&gt;

&lt;p&gt;Python has a convenient library called "surprise". This library is designed specifically for the recommender system. Surprise already has a function to do train-test-split, but the data format was complicated to play with. I have used both scikit-learn and surprise to split and format the data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# selecting X and y
X = df[df.columns[:2]] #item_id, user_id
y = df[df.columns[-1]] #rating

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test 
= train_test_split(X, y, test_size=0.33, random_state=0)

from surprise import Reader, Dataset
# read in values as Surprise dataset 
reader = Reader()
# train data
# Loading the data again for the Surprise library
train = Dataset.load_from_df(pd.concat([X_train, y_train], 
                                       axis = 1), reader)
# test data
# Loading the data again for the Surprise library
test = Dataset.load_from_df(pd.concat([X_test, y_test], 
                                      axis = 1), reader)
# whole data for comparison
data = Dataset.load_from_df(df, reader)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Collaborative Filtering&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The Surprise library uses a matrix factorization to predict ratings on items. This is a supervised learning technique because the rating information is treated as a continuous variable. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3OiQQyaM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7bkyt5pmxf3a49i2zwc7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3OiQQyaM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7bkyt5pmxf3a49i2zwc7.png" alt="col_filtering" width="535" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The table above shows 5 items and 4 users as an example. Users do not rate all items. The system predicts ratings that can be replaced with missing ratings. For example, user 4 would have 4 missing ratings replaced with predicted ratings. Then, the games will be recommended to the user based on the highest predicted rating.&lt;/p&gt;

&lt;p&gt;The codes below calculate the RMSE values that can be compared with the RMSE values from various scikit-learn regressors, and the Surprise library has the best RMSE.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from surprise.model_selection import cross_validate
from surprise.prediction_algorithms import SVD
import numpy as np

svd = SVD(random_state = 0)
val_svd = cross_validate(svd, train, measures=['RMSE', 'MAE'], cv=3)
print("Mean RMSE for the baseline model validation:")
np.mean(val_svd['test_rmse'])

svd = SVD(random_state = 0).fit(train_set)

pred = []
for i in range(len(X_test)):
    pred.append(svd.predict(X_test.iloc[i].values[0], X_test.iloc[i].values[1])[3])

from sklearn.metrics import mean_squared_error
print("RMSE for the baseline model on test data:")
print(mean_squared_error(y_test, pred, squared=False))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Mean RMSE for the baseline model validation: 1.2980&lt;/li&gt;
&lt;li&gt;RMSE for the baseline model on test data: 1.2827&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The RMSE value is not so great. A tuned model shows better RMSE values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;svd = SVD(random_state = 0, 
          n_factors= 100, 
          reg_all = 0.07, 
          n_epochs = 150)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Mean RMSE for the tuned model validation: 1.2850&lt;/li&gt;
&lt;li&gt;RMSE for the tuned model on test data: 1.2660&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;RMSE is not improved significantly. I hope for a value of less than 1, this is the best I have. This can be improved with more data cleaning. For example, I can try to find and remove outliers and/or customers with a low number of ratings. I might add the fourth part for the update.&lt;/p&gt;

&lt;p&gt;The graph below shows an example of how a selected customer is recommended the video games assigned with predicted ratings.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uErUMaQn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x87n3jvmhdauv443whsy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uErUMaQn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x87n3jvmhdauv443whsy.png" alt="many rating 5" width="540" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is easy to see this customer would be overwhelmed by a huge list of recommended video games. I will talk about how this can be improved, but it would have more worth talking first about if this system (the tuned model) is useful.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ddjh20482/recommender_system_amazon"&gt;Project GitHub Link&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/ddjh20482/a-new-way-to-recommend-video-games-at-amazon-part-2-2lbe"&gt;Part 2&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/ddjh20482/a-new-way-to-recommend-video-games-at-amazon-part-3-1o8"&gt;Part 3&lt;/a&gt;&lt;/p&gt;

</description>
      <category>recommender</category>
      <category>amazon</category>
      <category>videogames</category>
      <category>python</category>
    </item>
    <item>
      <title>How to use GPU for Deep Learning</title>
      <dc:creator>Jinhoon Chung</dc:creator>
      <pubDate>Fri, 26 Aug 2022 13:49:44 +0000</pubDate>
      <link>https://dev.to/ddjh20482/how-to-use-gpu-for-deep-learning-41cm</link>
      <guid>https://dev.to/ddjh20482/how-to-use-gpu-for-deep-learning-41cm</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Intro&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;My data science Bootcamp introduced me Deep Learning a few months ago. While reading materials, I was so surprised to know my RTX 3090 can be used for Deep Learning! I thought GPUs were only for gaming. Now, I have one more excuse to buy the high-end GPU for the next time I build a new desktop.&lt;/p&gt;

&lt;p&gt;However, the excitement didn't last long as it was not easy to set up a new environment for Deep Learning using GPU on Anaconda or Git Bash. I have done some research, and the steps were pretty straightforward, but they were mostly at least a year old, and no information was related to Git Bash. &lt;/p&gt;

&lt;p&gt;In this article, I like to show you how to incorporate Git Bash to use GPU Deep Learning on Jupyter notebook. Let me talk through how we can set up an environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Benefit of Using GPU&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let me talk briefly about the benefit of using GPU for Deep Learning. It is much faster.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BLUveECC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t9bmzsus912g4qhpvn3k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BLUveECC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t9bmzsus912g4qhpvn3k.png" alt="gpuvscpu" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Based on the image above from &lt;a href="https://deci.ai/blog/close-gap-cpu-performance-gpu-deep-learning-models/"&gt;this link&lt;/a&gt;, GPU is generally 3 times faster than CPU. A better GPU can give you much a better performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Set-up&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 0
&lt;/h3&gt;

&lt;p&gt;Before starting, please make sure Anaconda and Git Bash are installed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1 - Anaconda
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Iv4lTFl7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rgalrx3eebf2e3cdnir8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Iv4lTFl7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rgalrx3eebf2e3cdnir8.png" alt="anaconda1" width="490" height="382"&gt;&lt;/a&gt;&lt;br&gt;
After opening Anaconda, click "Environment" on the menu. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IeWnTB6d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8x8avv5br5rw1yl9qnai.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IeWnTB6d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8x8avv5br5rw1yl9qnai.png" alt="anaconda2" width="307" height="653"&gt;&lt;/a&gt;&lt;br&gt;
Click "Create" at the bottom of the list of environments. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5FJ8uqsi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lubt71rht58wfbgppyh0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5FJ8uqsi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lubt71rht58wfbgppyh0.png" alt="anaconda3" width="459" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A small window should pop up. Name the environment. I previously named the environment "gpu". The next step is to choose a version. The walkthrough I read showed me to choose version 3.6, but I was able to make mine work with version 3.7. So, I recommend 3.7, but you can try a newer version and see if it works or not.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6VlKQD-k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8wll4kn3r70qvosawa6m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6VlKQD-k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8wll4kn3r70qvosawa6m.png" alt="anaconda4" width="518" height="219"&gt;&lt;/a&gt;&lt;br&gt;
Select the environment you just created. Choose "Not Installed" from the drop-down menu. On the "Search Packages" box, type in "tensorflow" and hit "Enter".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--soJGxGO---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/em8bdzmky9fxu3libo1s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--soJGxGO---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/em8bdzmky9fxu3libo1s.png" alt="anaconda5" width="880" height="253"&gt;&lt;/a&gt;&lt;br&gt;
You should see some results like what you see in the picture above. Check "keras-gpu" and "tensorflowo-gpu" then click "Apply". This should take some time to get things ready to install the packages. If Anaconda shows you they can't be installed, then this is where you should try again with a different version mentioned earlier in this article.&lt;/p&gt;

&lt;p&gt;Once the packages are installed, we are ready for Git Bash.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2 - Git Bash
&lt;/h3&gt;

&lt;p&gt;This step is pretty simple and quick. We only need to change the environment. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wI1Jdl5t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ikip59wrbkq8d73szej.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wI1Jdl5t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ikip59wrbkq8d73szej.png" alt="gitbash" width="369" height="169"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just type "conda activate gpu", then hit "enter".&lt;/p&gt;

&lt;p&gt;Now type "jupyter notebook", then hit "enter" to open the notebook.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 3 - Test on Jupyter Notebook
&lt;/h3&gt;

&lt;p&gt;Run the codes below. I have attached an output below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import tensorflow as tf
from tensorflow import keras
print(len(tf.config.experimental.list_physical_devices('GPU')))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tf.test.is_gpu_available()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tf.test.is_built_with_cuda()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lrtL1_Zh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wvirvup9zrcprb3aaf6j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lrtL1_Zh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wvirvup9zrcprb3aaf6j.png" alt="test1" width="774" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also check Git Bash logs after running the codes above.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xmqq9oFg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wbzt6sfb15bfgmvq9nxf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xmqq9oFg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wbzt6sfb15bfgmvq9nxf.png" alt="test2" width="880" height="52"&gt;&lt;/a&gt;&lt;br&gt;
The logs mention my RTX 3090 with the size of memory. It should print out your GPU.&lt;/p&gt;

&lt;p&gt;The images below show the GPU memory usage difference when using GPU or not. Please pay attention to "Dedicated GPU memory".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---SmCdDdQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/09uoxtdao5ii6r6mz8tz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---SmCdDdQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/09uoxtdao5ii6r6mz8tz.png" alt="test3" width="880" height="586"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hm2XIBXY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uicdaghbc0zuoc90pqwa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hm2XIBXY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uicdaghbc0zuoc90pqwa.png" alt="test4" width="880" height="589"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gpu</category>
      <category>deeplearning</category>
      <category>cuda</category>
    </item>
    <item>
      <title>Attributes from Python Pipeline</title>
      <dc:creator>Jinhoon Chung</dc:creator>
      <pubDate>Tue, 21 Jun 2022 14:26:48 +0000</pubDate>
      <link>https://dev.to/ddjh20482/attributes-from-python-pipeline-4dem</link>
      <guid>https://dev.to/ddjh20482/attributes-from-python-pipeline-4dem</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Intro&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I have recently learned python pipeline. It is very useful especially for the readability of the technical notebook and for the overall coding. However, I have encountered a big trouble that is bringing out the attributes of elements included in the pipeline.&lt;/p&gt;

&lt;p&gt;With aid from my instructor and googling, the trouble turned into a valuable experience of learning something new.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Data&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let me briefly go over what data has been used for this post. The data is from &lt;a href="https://www.drivendata.org/competitions/66/flu-shot-learning/page/211/"&gt;National 2009 H1N1 Flu Survey&lt;/a&gt;. The link will direct you to the page where you can see variable names. The purpose of the survey is to study the H1N1 flu vaccination rate and the categories of respondents. This is just to help you to understand the output of the pipeline later in this post.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Elements in the Pipeline&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The elements are actually called "steps" in the pipeline. Each step can be an encoder, sampling, or any machine learning (classification, regression, etc.). In the steps, &lt;a href="https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html"&gt;OneHotEncoder&lt;/a&gt; as an encoder and &lt;a href="https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html"&gt;RandomForestClassifier&lt;/a&gt; as a classifier are used.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Attributes&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;OneHotEncoder&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Below is the python code to instantiate the encoder. Results will be put all together at the end of the post for a better organization.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# import libraries for columns transformation
from sklearn.preprocessing import OneHotEncoder
from sklearn.compose import ColumnTransformer

# instantiate encoders
ohe = OneHotEncoder(sparse=False, handle_unknown='ignore')

# apply encoding to just one column in the data
# to reduce complexity in the results
ct = ColumnTransformer([('age', ohe, ['age_group'])],
                       remainder='passthrough')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please remember &lt;strong&gt;ct&lt;/strong&gt; as it will be back soon.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;RandomForestClassifier&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Another python code for the classifier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from sklearn.ensemble import RandomForestClassifier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is it for this section! The further steps of coding will come soon.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Results&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;OneHotEncoder&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;One of the useful features or attributes of the encoders is &lt;strong&gt;get_feature_names()&lt;/strong&gt;. This will bring all of the variable names associated with the encoding. Let's take a look at the code and the output. Remember that &lt;strong&gt;ct&lt;/strong&gt; from above is back.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ct.get_feature_names()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TpCnNzks--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rymfj3yahog70bfb6kpa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TpCnNzks--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rymfj3yahog70bfb6kpa.png" alt="getfeaturenames" width="317" height="736"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The age column is successfully encoded. What if we use the pipeline? Let's instantiate the pipeline first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# import library
from imblearn.pipeline import Pipeline

# instantiate pipeline using column transformer and 
# model from classifier
pipe2 = Pipeline(steps=[('ct', ct),
                        ('rfc', RandomForestClassifier(random_state=1, 
                                                       max_depth = 9))
                       ]
                )
pipe2.fit(X_train_labeled, y_train)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please pay attention to the pipeline model, &lt;strong&gt;pipe2&lt;/strong&gt; as it will be back several times in this post. Here is the magic code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipe2.steps[0][1].get_feature_names()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vZtvyauW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9tbnug4neoviry6zrjh2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vZtvyauW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9tbnug4neoviry6zrjh2.png" alt="gfn_pipe" width="374" height="732"&gt;&lt;/a&gt;&lt;br&gt;
What just happened? A pipeline can show you what steps are taken, and it lets you use attributes of each step after it is called.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pxilBziC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mdi8v1w00c3doi4mtj7v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pxilBziC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mdi8v1w00c3doi4mtj7v.png" alt="pipeline_steps" width="731" height="209"&gt;&lt;/a&gt;&lt;br&gt;
As you can see from the image above, pipeline steps are saved as a list of tuples. Each step can be called like the image shown below.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dLBfD22h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9jlq5ely10axnm4qxm51.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dLBfD22h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9jlq5ely10axnm4qxm51.png" alt="call_step" width="700" height="169"&gt;&lt;/a&gt;&lt;br&gt;
Then, you can use any available attributes to get the information you need.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;RancomForestClassifier&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let me repeat with the classifier. Let's begin one without the pipeline.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rfc=RandomForestClassifier(random_state=1, max_depth = 9)
X_train_labeled_ct = ct.fit_transform(X_train_labeled)
rfc.fit(X_train_labeled_ct, y_train)
rfc.feature_importances_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BnCbp6OY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/22jpuxd1jbi8h0fz4k7y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BnCbp6OY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/22jpuxd1jbi8h0fz4k7y.png" alt="rfc_fi" width="653" height="259"&gt;&lt;/a&gt;&lt;br&gt;
Here is the one with the pipeline.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rF6jM6R3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/72brxiocfkxm334puedx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rF6jM6R3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/72brxiocfkxm334puedx.png" alt="rfc_fi_pipe" width="655" height="210"&gt;&lt;/a&gt;&lt;br&gt;
It can be seen that once a pipeline is declared, the coding gets simplified.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Application&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Using the above results, we can do something like the below!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# graph of the features sorted by the impact level on the analysis
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

# extract feature importance scores and feature names
# then merge them
feat_impt = pd.concat([pd.DataFrame(pipe2.steps[1][1].feature_importances_, 
                                    columns = ['FI_score']),
                       pd.DataFrame(pipe2.steps[0][1].get_feature_names(), 
                                    columns = ['Features'])],
                      axis = 1
                     )

# sort descending by importance
feat_impt.sort_values(by = 'FI_score', inplace=True)

# print graph of the top 20 important features
plt.figure(figsize=(8,9))
plt.barh(range(20), feat_impt.FI_score[-20:], align='center') 
plt.yticks(np.arange(20), feat_impt.Features[-20:]) 
plt.xlabel('Feature importance')
plt.ylabel('Feature');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zFZHUkVl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j6gvh0xsb4lx78qeow5c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zFZHUkVl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j6gvh0xsb4lx78qeow5c.png" alt="graph" width="629" height="534"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>datascience</category>
      <category>python</category>
      <category>pipeline</category>
    </item>
    <item>
      <title>Magic of Transformation in Linear Regression</title>
      <dc:creator>Jinhoon Chung</dc:creator>
      <pubDate>Fri, 13 May 2022 12:26:00 +0000</pubDate>
      <link>https://dev.to/ddjh20482/magic-of-transformation-in-linear-regression-584f</link>
      <guid>https://dev.to/ddjh20482/magic-of-transformation-in-linear-regression-584f</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Intro&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Recently I completed a project from data science boot camp and learned how the transformation of numerical information is helpful in finding a regression model. On this page, I like to focus on how the transformation of numerical data can give better validation to the model instead of focusing on how the model looks and can be used to predict a value.&lt;/p&gt;

&lt;p&gt;I will go over the data source and data structure briefly and give a quick explanation of what methods are used in this post. I will also include some python code and mathematical formulas to aid understanding.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Data&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I am using data from the project I had completed, but the data is from a real-life and contains information on house sales data in King County, Washington. The information includes house prices and multiple house features. Below is the list of variables used in the analysis.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dependent Variable
&lt;/h3&gt;

&lt;p&gt;House Price&lt;/p&gt;

&lt;h3&gt;
  
  
  Independent Variables
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Numerical
&lt;/h4&gt;

&lt;p&gt;Living space in squared-feet&lt;br&gt;
Lot size in squared-feet&lt;br&gt;
Year built&lt;br&gt;
The number of floors*&lt;/p&gt;

&lt;p&gt;* A separate explanation of why I defined it as numerical is at the end of the post.&lt;/p&gt;
&lt;h4&gt;
  
  
  Categorical
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Binaries
&lt;/h5&gt;

&lt;p&gt;Waterfront&lt;br&gt;
View presence&lt;br&gt;
Renovation condition&lt;br&gt;
Basement presence&lt;/p&gt;
&lt;h5&gt;
  
  
  Multi-categorical
&lt;/h5&gt;

&lt;p&gt;Maintenance condition&lt;br&gt;
House grade&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Methods&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This section is just to give you an idea of what I have done for the results. If these look familiar to you or don't interest you, then you can just skip to the result section. Checking the results before reading this section might give you an idea more easily of why I am posting this.&lt;/p&gt;
&lt;h3&gt;
  
  
  Assumptions
&lt;/h3&gt;

&lt;p&gt;There are several ways to validate the model, and I like to go over the four major assumptions to validate the model. The assumptions are linearity, normality, homoscedasticity, and multicollinearity. I chose this method because it can be explained visually, and visualization is more helpful in explaining the concept than just lots of words and numbers.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Linearity
&lt;/h4&gt;

&lt;p&gt;It is important to check the linearity assumption in the linear regression analysis. As polynomial transformation has not been applied in this analysis, the expected house price (dependent variable) will be compared to the raw value of the house price.&lt;/p&gt;

&lt;p&gt;Below is the python code I used. The purpose of sharing the code is to give some idea of how the graph is created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# split whole data to training and test data
from sklearn.model_selection import train_test_split

X = independent_variables
y = house_price_column

X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)

# find the model fit
from sklearn.linear_model import LinearRegression
model = LinearRegression()

model.fit(X_train, y_train)

# Calculate predicted price using test data
y_pred = model.predict(X_test)

# Graphing part
import matplotlib.pyplot as plt

fig, ax = plt.subplots()

perfect_line = np.arange(y_test.min(), y_test.max())
ax.plot(perfect_line, linestyle="--", color="orange", label="Perfect Fit")
ax.scatter(y_test, y_pred, alpha=0.5)
ax.set_xlabel("Actual Price")
ax.set_ylabel("Predicted Price")
ax.legend();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Normality
&lt;/h4&gt;

&lt;p&gt;The normality assumption is related to the normality of model residuals. This is checked using a QQ plot.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import scipy.stats as stats
residuals = y_test - y_pred
sm.graphics.qqplot(residuals, dist=stats.norm, line='45', fit=True);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Homoscedasticity
&lt;/h4&gt;

&lt;p&gt;The assumption of homoscedasticity checks the dependent variables against the dependent variables and sees if values are dispersed without any pattern. This assumption is also related to the residuals.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fig, ax = plt.subplots()

residuals = y_test - y_pred

ax.scatter(y_pred, residuals, alpha=0.5)
ax.plot(y_pred, [0 for i in range(len(X_test))])
ax.set_xlabel("Predicted Value")
ax.set_ylabel("Actual - Predicted Value");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Multicollinearity
&lt;/h4&gt;

&lt;p&gt;The assumption of multicollinearity checks dependency between independent variables. It is best to have independent variables independent of one another as much as possible.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from statsmodels.stats.outliers_influence import variance_inflation_factor
vif = [variance_inflation_factor(X_train.values, i) for i in range(X_train.shape[1])]
pd.Series(vif, index=X_train.columns, name="Variance Inflation Factor")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Transformations of numerical variables
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Log transformation
&lt;/h4&gt;

&lt;p&gt;This part is simple. All values in the numerical columns are natural-logged.&lt;/p&gt;

&lt;h4&gt;
  
  
  Normalization
&lt;/h4&gt;

&lt;p&gt;The below formula shows a value in a numerical variable is subtracted by the mean of the variable, and then the subtracted value is divided by the standard deviation of the variable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dp_SFhdK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ub8w0hn6dpr5ybmh61jm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dp_SFhdK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ub8w0hn6dpr5ybmh61jm.png" alt="Normalization Formula" width="140" height="68"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Results&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Here is the fun part. You can just relax and see how graphs and scores change.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Raw Data - no transformation
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Linearity
&lt;/h4&gt;

&lt;p&gt;I see several outliers. Some linearity is observed only on the left side.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0yIqs5XX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qasegenxzfw0ei3i1mlf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0yIqs5XX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qasegenxzfw0ei3i1mlf.png" alt="Linearity1" width="376" height="273"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  2. Normality
&lt;/h4&gt;

&lt;p&gt;Only 1/3 of the dots are on the red line.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---RnNXD36--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t1zmy5qnoj7ws0p5h120.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---RnNXD36--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t1zmy5qnoj7ws0p5h120.png" alt="Normality1" width="384" height="262"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  3. Homoscedasticity
&lt;/h4&gt;

&lt;p&gt;A clear pattern is observed.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--itPua-mQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/drwyaxebgsh3dxaj0r4q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--itPua-mQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/drwyaxebgsh3dxaj0r4q.png" alt="Homoscedasticity1" width="384" height="273"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  4. Multicollinearity
&lt;/h4&gt;

&lt;p&gt;Only scores below 5 are accepted. About half of the scores are not acceptable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sqft_living            8483.406359
sqft_lot                  1.200729
floors                   14.106084
waterfront                1.085728
view                      1.344477
yr_built                 72.300842
is_renovated              1.157421
has_basement              2.175980
condition_Fair            1.038721
condition_Good            1.668386
condition_Very Good       1.295097
grade_11 Excellent        1.530655
grade_6 Low Average       5.129509
grade_7 Average          14.142031
grade_8 Good              8.261598
grade_9 Better            3.446987
interaction            8460.117213
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Log Transformation
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Linearity
&lt;/h4&gt;

&lt;p&gt;It shows much better linearity. The linearity of the dots have a slightly lower slope than the perfect line.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S2PE23O6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oqedfwym29urzltldiai.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S2PE23O6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oqedfwym29urzltldiai.png" alt="Linearity logged" width="395" height="265"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  2. Normality
&lt;/h4&gt;

&lt;p&gt;There is a small kurtosis, but the majority of the dots are on the red line.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---u6O2tNe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v5wm6tkf8ykk8demyeru.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---u6O2tNe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v5wm6tkf8ykk8demyeru.png" alt="Normality logged" width="384" height="262"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  3. Homoscedasticity
&lt;/h4&gt;

&lt;p&gt;This looks better, too. A slight pattern is observed on the right side.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---Lgbl7Zp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9uz8cb5njvb1kfnqgxi3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---Lgbl7Zp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9uz8cb5njvb1kfnqgxi3.png" alt="Homoscedasticity logged" width="394" height="263"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  4. Multicollinearity
&lt;/h4&gt;

&lt;p&gt;Several scores are still too high.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sqft_living            471370.972327
sqft_lot                  155.772190
floors                      4.052275
yr_built                  922.928871
waterfront                  1.086052
view                        1.337069
is_renovated                1.146855
has_basement                2.438983
condition_Fair              1.042784
condition_Good              1.668688
condition_Very Good         1.283740
grade_11 Excellent          1.468962
grade_6 Low Average         5.221791
grade_7 Average            12.895007
grade_8 Good                7.519577
grade_9 Better              3.355969
interaction            469074.416388
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Log Transformation and Normalization
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Linearity
&lt;/h4&gt;

&lt;p&gt;The slope is slightly better and closer to the perfect line.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LpTk_BDh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fcihxao8f2pk7msnw1io.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LpTk_BDh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fcihxao8f2pk7msnw1io.png" alt="Linearity Final" width="384" height="263"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  2. Normality
&lt;/h4&gt;

&lt;p&gt;I don't see much difference from the previous graph.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2hQp2JYF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j4wborx65ct49jxdp6jg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2hQp2JYF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j4wborx65ct49jxdp6jg.png" alt="Normality Final" width="384" height="262"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  3. Homoscedasticity
&lt;/h4&gt;

&lt;p&gt;I don't see much difference from the previous graph.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p0Sjj5hF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fy2p0l5lh6c79ru8c64z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p0Sjj5hF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fy2p0l5lh6c79ru8c64z.png" alt="Homoscedasticity Final" width="384" height="262"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  4. Multicollinearity
&lt;/h4&gt;

&lt;p&gt;All of the scores are now acceptable. This is a huge difference!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sqft_living            3.001670
sqft_lot               1.552016
floors                 2.046914
yr_built               1.758294
waterfront             1.086293
view                   1.313341
is_renovated           1.148279
has_basement           2.441147
condition_Fair         1.042169
condition_Good         1.647135
condition_Very Good    1.281906
grade_11 Excellent     1.278034
grade_6 Low Average    1.939542
grade_7 Average        2.077564
grade_8 Good           1.609822
grade_9 Better         1.440610
interaction            1.374175
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Transformations helped to keep (i.e. not reject) the four assumptions. Visualizations seem clear enough to guide you to study what was improving.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Extra&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The number of floors
&lt;/h3&gt;

&lt;p&gt;This is kind of out of the major topic in this post, but this decision can be crucial to the overall regression analysis. Let me begin with the value counts of the floor information.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1.0    10673
2.0     8235
1.5     1910
3.0      611
2.5      161
3.5        7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The left column shows the data has a range of the floor counts from 1 through 3.5. The model might make more sense to treat this variable as a categorical variable. However, what if one likes to predict a house price that has 4 floors? This question or problem can be solved if this information is treated as numerical. I think this is a matter of the goal of the analysis.&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>machinelearning</category>
      <category>regression</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to make money out of a movie?</title>
      <dc:creator>Jinhoon Chung</dc:creator>
      <pubDate>Wed, 23 Mar 2022 21:30:03 +0000</pubDate>
      <link>https://dev.to/ddjh20482/best-way-to-make-money-out-of-a-movie-4nbc</link>
      <guid>https://dev.to/ddjh20482/best-way-to-make-money-out-of-a-movie-4nbc</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;Are you interested in making a new movie? Do you need some ideas about what kind of movie will help you to make a profit? Then, this post might give you a direction or two on where to begin.&lt;/p&gt;

&lt;h2&gt;
  
  
  Movie Information
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Budget and Profit
&lt;/h4&gt;

&lt;p&gt;To make a profit, we need to get profit information. &lt;a href="https://www.the-numbers.com/"&gt;The Numbers&lt;/a&gt; is a good source for the information.&lt;/p&gt;

&lt;p&gt;The below table is a part of the data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;production_budget    worldwide_gross
$425,000,000         $2,776,345,279
$300,000,000         $2,048,134,200
$306,000,000         $2,053,311,220
$215,000,000         $1,648,854,864
$190,000,000         $1,518,722,794
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unfortunately, the data does not include profit, but it can easily be calculated by subtracting the budget from the gross.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;production_budget    worldwide_gross    profit
$425,000,000         $2,776,345,279     2351.35
$300,000,000         $2,048,134,200     1748.13
$306,000,000         $2,053,311,220     1747.31
$215,000,000         $1,648,854,864     1433.85
$190,000,000         $1,518,722,794     1328.72
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The profit is formatted to be in millions. Now we have information for budget and profit. Let's look at a graph and see if there is any relationship between budget and profit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hG820EHk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bwbvv7rv81dm98d5gttw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hG820EHk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bwbvv7rv81dm98d5gttw.png" alt="budget vs profit" width="653" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I would go for a scatter plot, but this graph looks less intimidating. There are five blue boxes. Each box represents the median value of each profit range. Profit ranges help to make analysis look more organized. The profit range at the left shows below zero which means it has a negative profit. There are two lines above and below the blue boxes. They represent the fluctuation of the data. A range of the data sometimes can be handier than just one number, the median.&lt;/p&gt;

&lt;p&gt;What we can see from the above graph is that the more money spent on a movie returns more profit. Now that sounds infinite. This can be overwhelming for someone with a new experience. Let's dive into other aspects of the movies.&lt;/p&gt;

&lt;h4&gt;
  
  
  Genre
&lt;/h4&gt;

&lt;p&gt;I think everyone has a favorite movie genre or two. There are drama, action, fantasy, etc. Try naming them all. We can get good data from &lt;a href="https://www.themoviedb.org/"&gt;TMDB&lt;/a&gt;. While TMDB has good information on the movie genres, the profit data is not included. This is handled by combining data from TMDB with data from The Numbers mentioned above.&lt;/p&gt;

&lt;p&gt;Let's check how genres are distributed before relating genres to profit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d1xkndVB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b3ptg400jqddsqlcv75g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d1xkndVB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b3ptg400jqddsqlcv75g.png" alt="genre distribution" width="704" height="523"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Wow! Look at drama. It is overwhelmingly at the top. We also can see comedy, thriller, and action at the top. It is might be a good idea to avoid those genres to avoid too much competition.&lt;/p&gt;

&lt;p&gt;It is time to check how genres can be related to profit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2L0Vg5p6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ttfgyrstpf7fx9v1qwu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2L0Vg5p6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ttfgyrstpf7fx9v1qwu.png" alt="genre vs profit" width="728" height="523"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The elements in this graph are the same as the graph for budget and profit. This graph is just that the bars are in the horizontal direction. The blue box again shows the median while two lines show the fluctuation. Now, drama is at the bottom half. The most profitable genres are animation, adventure, fantasy, family, science fiction, and action. I have picked six instead of five. The reason is that the fluctuation of those six stays above zero profit. &lt;/p&gt;

&lt;p&gt;This part does not sound infinite. I guess the animation genre should be taken into the account.&lt;/p&gt;

&lt;p&gt;Why don't we look at another aspect that is movie runtime?&lt;/p&gt;

&lt;h4&gt;
  
  
  Movie Runtime
&lt;/h4&gt;

&lt;p&gt;Runtime data is obtained from &lt;a href="https://www.imdb.com/"&gt;IMDb&lt;/a&gt;. Since IMDb does not have profit information, the data is combined with data from The Numbers.&lt;/p&gt;

&lt;p&gt;Let's go straight into the result.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oh-Iqw-h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6lefup0ao3qrkl2yq55x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oh-Iqw-h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6lefup0ao3qrkl2yq55x.png" alt="runtime vs profit" width="541" height="414"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The runtime between 80 to 100 minutes has the lowest profit while movies above 120 have the highest profit. Surprisingly movies with less than 60 minutes long have more profit than movies with 80 to 100 minutes long. If a new movie with a length of more than 2 hours is not affordable, why don't we target the movie length of fewer than 60 minutes?&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This analysis should give you some ideas about where to begin before filming a new movie. We looked at information on budget, genre, and runtime. If you gained curiosity about other aspects of the movies, then it means this analysis did something right.&lt;/p&gt;

</description>
      <category>movie</category>
    </item>
  </channel>
</rss>
