<?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 Panwar Abhash Anil on Medium]]></title>
        <description><![CDATA[Stories by Panwar Abhash Anil on Medium]]></description>
        <link>https://medium.com/@abhashpanwar?source=rss-7571d881a77d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*on78CyvIihoOCZ2Nvd5zyg.jpeg</url>
            <title>Stories by Panwar Abhash Anil on Medium</title>
            <link>https://medium.com/@abhashpanwar?source=rss-7571d881a77d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 22:13:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abhashpanwar/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[Most frequent doubts of data science aspirants regarding A/B testing]]></title>
            <link>https://medium.com/analytics-vidhya/most-frequent-doubts-of-data-science-aspirants-regarding-a-b-testing-f5bc7a6fe98f?source=rss-7571d881a77d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5bc7a6fe98f</guid>
            <category><![CDATA[fintech]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[a-b-testing]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Panwar Abhash Anil]]></dc:creator>
            <pubDate>Wed, 10 Nov 2021 04:54:17 GMT</pubDate>
            <atom:updated>2021-11-10T04:54:17.599Z</atom:updated>
            <content:encoded><![CDATA[<h3>Data science aspirants doubts regarding A/B testing</h3><p>Step-by-step, beginner-friendly tutorial on A/B testing for Data Science aspirants.</p><blockquote>In this article, we are going to discuss what is A/B testing?, Where you can implement and more key concepts of A/B testing in data science.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*Sl213yQeRrhMYbeB7eKZfw.jpeg" /></figure><p>In the last decade, data science has become a popular and effective technique to solve business problems. One of the business problems is “Will the user like the new version or not?” For example, if you build the app for users and later you want to integrate a new feature into the app but you are not sure about this so you want to make a decision whether to roll out the feature or not. Here you can take the user’s input whether they want a new feature or not so that you will gain more traffic.</p><p>Now this problem can be solved by conducting an experiment/test and that test is known as <a href="https://en.wikipedia.org/wiki/A/B_testing">A/B testing</a>. Let’s start.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*wMT6o6KvcuECmL9-.jpg" /><figcaption><a href="https://www.linkedin.com/in/panwar-abhash-anil/">Image Author: Panwar Abhash Anil</a></figcaption></figure><h3>What is A/B testing?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*isq6rXuh87-6cIiS.png" /><figcaption><a href="https://miro.medium.com/max/3568/1*aPUSwnuyUsxF_ACHuxiDlA.png">Image Source: Google</a></figcaption></figure><p>A/B testing is a randomized experiment where it aims to compare two variants/versions (A vs B) of something (webpage, images, etc.) to determine which variation performs better for a given conversion goal based on user experience.</p><p>It is also known as split testing where you randomly split the users into a control group and treatment/variation group in which one version is shown/given to one group and another version to another group then based on user input, you determine which version is better or performing well.</p><p>In statistics, an A/B test is an example of statistical <a href="https://en.wikipedia.org/wiki/Statistical_hypothesis_testing">hypothesis testing</a>, a process whereby a hypothesis is made about the relationship between two data sets and those data sets are then compared against each other to determine if there is a statistically significant relationship or not.</p><h3>Variants of A/B testing:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*f5J1YVC7j8O1OE4q.jpg" /><figcaption><a href="https://www.convert.com/wp-content/uploads/2020/10/A_B-Testing-Ultimate-Guide-3.jpg">Image Source: Google</a></figcaption></figure><p>A/B testing is comparing two versions, but what if you want to compare more than two versions.</p><p>But as a data scientist, sometimes we have to test more than two versions. If you are testing three versions then the testing will be named A/B/C testing. In general, for n versions, it will be A/B/n testing. The procedure will be the same as A/B testing.</p><h3>Where A/B testing is used?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/0*1Ul_tQQj-YhlZKB6.jpg" /><figcaption><a href="https://cdn-s.omniconvert.com/upload/content/images/2014-05-14_1145.jpg">Image Source: Google</a></figcaption></figure><p>For A/B testing, the experimenter needs the user’s input to do the experiment and the <a href="https://en.wikipedia.org/wiki/Web_page">web page</a> is the online way to do it. You might be thinking, you can also go to an individual user to get the input, yes you can do but through this, your sample size will be too small. Hence your sample can’t be equal to the true population.</p><p>It helps in making decisions because it estimates population parameters based on sample statistics.</p><h3>Why data scientists do A/B testing?</h3><p>A/B testing helps organizations to avoid unnecessary risks by allowing them to target their resources for maximum effect and efficiency. Also, it helps them to select the best version of products (best webpage, best images, best marketing promotional content, etc.)</p><h3>How long should you run an A/B test?</h3><p>To get representative sample data and for your data to be accurate, experts recommend running the A/B test for a minimum of one to two weeks.</p><h3>When not to run A/B testing?</h3><ol><li>When the sample size is small: When you don’t have enough meaningful traffic.</li><li>If you don’t yet have an informed hypothesis: Identify your problem. Define a hypothesis. Then test to see if you’re right. For example, the Problem Statement: Current promotional content is not doing well. Hypothesis:- If I add some more visuals then more people will look into it.</li><li>If you can’t spend time: Suppose you can do the experiment but if you can’t spend time on analyzing the data or testing the hypothesis, doing A/B is useless.</li></ol><h3>When to run A/B testing?</h3><ol><li>When the sample size is large.</li><li>You can do A/B testing when you want the user’s input to fulfill your goal.</li></ol><h3>Advantages of A/B testing?</h3><ol><li>Help in decision making: If you have two versions of the same product then A/B testing will help you to select the best one.</li><li>Reduces risk: You can avoid/reduce the risk. Let me explain to you through an example: Suppose you made some major changes on a web page and before rolling out for all the users, you can check whether the new changes will be liked by the users or not.</li></ol><h3>How to Conduct A/B Testing?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lI_-ARsfuHW05usc.png" /><figcaption><a href="https://www.linkedin.com/in/panwar-abhash-anil/">Image Author: Panwar Abhash Anil</a></figcaption></figure><p>If you are a data scientist and wants to conduct A/B testing for your organization then follow the below steps:-</p><h4><strong>Step 1) Collect data:</strong></h4><p>Before comparing two versions, you must data for the 1st version or both.</p><p>Suppose you want to compare two versions of a webpage then you must have data for the first webpage then through testing you will collect data for the 2nd version.</p><p>Suppose you want to compare two promotional campaigns, then obviously you don’t have the data for the 1st version also. In that case, you will collect data for both the version through A/B testing.</p><h4><strong>Step 2) Identify goal:</strong></h4><p>Identify the problem. Define the hypothesis then test to see if you’re right. Defining the goal will help in understanding what the objective is.</p><h4><strong>Step 3) Generate hypothesis:</strong></h4><p>Once the goal is set for the A/B test. The next step is generating the <a href="https://en.wikipedia.org/wiki/Hypothesis">hypothesis </a>i.e how to improve the original version and how to make it better than the current version.</p><p><strong>For example,</strong> You work at an e-commerce company, you think that displaying the checkout button on the product page can increase the checkout rate.</p><h4><strong>Step 4) Determine sample size:</strong></h4><p>To do the A/B test, you need to know in advance how many users have to visit the page so that the test results are statistically significant.</p><p>Based on this, it will be decided how long you have to run the A/B test to collect the data from users.</p><h4><strong>Step 5) Run the experiment:</strong></h4><p>The next step is to run the A/B testing. Once the sample size is defined you have to split your versions equally and randomly.</p><p><strong><em>Example:</em></strong> You have defined a sample size of 20,000 users and have to compare two versions of the web page. Next, you have to split equally &amp; randomly your 20k users into two groups such that each version will be shown to 10k users.</p><h4><strong>Step 6) Analyze the data:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*3_ah4ftGpXmIwFsD.png" /><figcaption><a href="https://yoast.com/app/uploads/2015/07/Convert_Experiments.png">Image Source: Google</a></figcaption></figure><p>Once this experiment is complete, as a data scientist the next step is to analyze the results. The data collected from the experiment and will tell you the difference between the performance and efficiency of different versions of the same product. It will also show whether there is a significant difference between the variables using statistical data. This will help you to make decisions such that you have to go with version 1 or 2.</p><h3>Practical example:</h3><p>Suppose you are a data scientist at <a href="http://towardsdatascience.com/"><strong><em>Towards Data Science</em></strong></a> and a company released the <a href="https://en.wikipedia.org/wiki/Boot_camp">Bootcamp</a> for the data science aspirants and later on you identified key features that to be added in <a href="https://en.wikipedia.org/wiki/Boot_camp">Bootcamp</a> and you have come up with two versions as follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pDZNpe7DsfjTSbuB.png" /><figcaption><a href="https://www.linkedin.com/in/panwar-abhash-anil/">Image Author: Panwar Abhash Anil</a></figcaption></figure><p><strong>Hypothesis:</strong> If we give the guaranteed job and paid internships then more data science aspirants will join the Bootcamp.</p><p><strong>Determine sample size: </strong>Suppose weekly visitors at <em>Towards Data Science</em> are nearly 50k and you have decided to split both the versions equally to 20k users.</p><p><strong>Run the experiment: </strong>You run the experiment for two weeks and collected the data like total visitors, out of total visitors who saw the content than out of them who enrolled into Bootcamp.</p><p><strong>Analyze the data: </strong>Once the experiment is completed, you start analyzing the data based on user experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*najAa3M8ugYLmFvQJWCAUQ.png" /><figcaption><a href="https://www.linkedin.com/in/panwar-abhash-anil/">Image Author: Panwar Abhash Anil</a></figcaption></figure><p>You have received the above data after running the A/B testing.</p><p>Total 8k users went through the <em>Bootcamp </em>page of version A and out of them only 1000 students enrolled in the Bootcamp.</p><p>Total 5k users went through the <em>Bootcamp </em>page of version B and out of them, 2000 students enrolled in the Bootcamp</p><p>Since fewer users saw version B but 40% of users are enrolled in the Bootcamp.</p><p>Hence, after A/B testing <strong><em>Towards Data Science</em></strong> can make the decision whether to addon new features or not.</p><blockquote>Thanks for reading. I hope this helped you to understand the core concepts of A/B testing in data science.<br>As always, I welcome feedback and can be reached on <a href="https://www.linkedin.com/in/panwar-abhash-anil/">Linkedin</a>.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5bc7a6fe98f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/most-frequent-doubts-of-data-science-aspirants-regarding-a-b-testing-f5bc7a6fe98f">Most frequent doubts of data science aspirants regarding A/B testing</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[Introduction to Time Series Analysis and key concepts]]></title>
            <link>https://medium.com/analytics-vidhya/introduction-to-time-series-analysis-and-key-concepts-dbf6c394984f?source=rss-7571d881a77d------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbf6c394984f</guid>
            <category><![CDATA[time-series-analysis]]></category>
            <category><![CDATA[time-series-model]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[time-series-forecasting]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Panwar Abhash Anil]]></dc:creator>
            <pubDate>Sun, 17 Jan 2021 12:06:27 GMT</pubDate>
            <atom:updated>2021-01-20T16:39:13.350Z</atom:updated>
            <content:encoded><![CDATA[<p>Stationarity, Random walk, White noise, Time Series models and Evaluation of models.</p><blockquote>In this article, we are going to examine what is time series analysis?, its scope in the future? and key concepts of time series analysis.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bGe68vnnA-A01jWuz_lahQ.png" /><figcaption>Photo by <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a></figcaption></figure><h3><strong>Table of Contents:</strong></h3><ol><li>Introduction: What is time series analysis and its importance?</li><li>What is stationarity in time series and its types?</li><li>White Noise &amp; Random Walk</li><li>AutoCorrelation Function(ACF) &amp; Partial auto correlation function(PACF)</li><li>Models: AutoRegression(AR), Moving Average(MA), AutoRegression-Moving Average(ARMA) , Autoregressive–moving-average model with exogenous inputs (ARMAX) and Auto Regressive Integrated Moving Average(ARIMA)</li><li>Identifying the order of models</li><li>Model diagnostics</li><li>Box-Jenkins method</li></ol><h3>1] Introduction:</h3><p>Time series analysis is a statistical technique that deals with <strong>time series data</strong>, or trend analysis. In Time series,data is in a series of particular time periods or intervals.</p><p><a href="https://en.wikipedia.org/wiki/Time_series"><strong>Time series analysis</strong></a> is used for various applications such as stock market analysis, pattern recognition, earthquake prediction, economic forecasting, census analysis and so on.</p><p>A time series consists of the following components:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OnatazqQmO-I1hZ0o2MvqQ.png" /><figcaption>Image showing Trend, Seasonality and Cyclicality (Photo by <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a> )</figcaption></figure><ul><li><a href="https://en.wikipedia.org/wiki/Trend"><strong>Trend</strong></a><strong>:</strong> The trend shows the general tendency of the data to increase or decrease during a long period of time. A trend is a smooth, general, long-term, average tendency. It is not always necessary that the increase or decrease is in the same direction throughout the given period of time.</li><li><a href="https://en.wikipedia.org/wiki/Seasonality"><strong>Seasonality</strong></a><strong>:</strong> Patterns that repeats frequently at regular intervals. For example: high sales every weekend.</li><li><a href="https://en.wikipedia.org/wiki/Cyclical_history"><strong>Cyclicality</strong></a><strong>:</strong> Cyclicality is where there is a repeating pattern but no fixed period.</li></ul><p>Scope of the Time Series Analysis:</p><ul><li>Stock Market Analysis</li><li>Economic Forecasting</li><li>Inventory studies</li><li>Demand Forecasting</li><li>Sales Forecasting and more</li></ul><h3>2] Stationarity:</h3><p><a href="https://en.wikipedia.org/wiki/Stationary_process">Stationary</a> means that the distribution of the data does not change with time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*O7h-a8yGieRiFZUZg6ERow.png" /><figcaption>Stationary v/s Non-Stationary (Photo by <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><ul><li>No Trend: It is not growing or shrinking.</li><li>Mean &amp; Variance constant: The average distance of the data points from the zero line is not changing.</li><li>AutoCorrelation Constant: How each value in time series is related to its neighbors stays the same.</li></ul><h4>◦ Types of stationary:</h4><ul><li>Strong stationary: Entire distribution of data is time-invariant.</li><li>Weak stationary: mean, variance and autocorrelation are time-invariant (i.e., for autocorrelation, corr[(X(t) , X(t−τ )] is only a function of τ )</li></ul><h4>◦ Test for stationarity: <a href="https://en.wikipedia.org/wiki/Dickey%E2%80%93Fuller_test">Augmented Dicky Fuller test</a></h4><ul><li>Null hypothesis is that the time series is non-stationary.</li><li>Alternate hypothesis is that the time series is non-stationary.</li><li>Dicky-Fuller test only used to test trend.</li></ul><h4>◦ Making time series stationary:</h4><p>Identifying whether a time series is stationary or not is very important. If it is stationary then we can use models that take assumptions that time series need to be stationary to predict the next values of the time series using historical data. If it is non-stationary then make it stationary on applying below transformations then use a model.</p><ul><li>Stationarity through differencing time series</li><li>Taking log of time series</li><li>Taking Square root of time series</li><li>Taking the proportional change (df.shift(1)/df)</li></ul><h3>3] White noise and random walk:</h3><p><a href="https://en.wikipedia.org/wiki/White_noise"><strong>White Noise</strong></a><strong>:</strong> A time series is <strong>white noise</strong> when sequence of uncorrelated random variables that are identically distributed. Stock returns are often modeled as white noise. Unfortunately, for white noise, we cannot forecast future observations based on the past — autocorrelations at all lags are zero.</p><h4><strong>White Noise is a series with:</strong></h4><ul><li>Constant mean</li><li>Constant variance</li><li>Zero autocorrelations at all lags</li></ul><p>Special Case: if data has normal distribution, then white noise is termed as gaussian white noise.</p><p><a href="https://en.wikipedia.org/wiki/Random_walk"><strong>Random Walk</strong></a><strong>:</strong> A <strong>random walk</strong> is another <strong>time series</strong> model where the current observation is equal to the previous observation with a <strong>noise.</strong></p><ul><li>In a random walk, today’s price is equal to yesterday’s price plus some noise.</li><li>Can’t forecast a random walk</li><li>Incidentally, if prices are in logs, the difference in log price is one way to measure return.</li><li>To test whether the time series is random walk, you can regress current values on lagged values. If the slope coefficient (beta) is not significantly different from one then we cannot reject the null hypothesis that the series is a random walk. However if the slope is less than one we can reject the null hypothesis.</li></ul><h3>4] AutoCorrelation Function &amp; Partial auto correlation Function:</h3><p><a href="https://en.wikipedia.org/wiki/Autocorrelation#:~:text=Autocorrelation%2C%20also%20known%20as%20serial,the%20time%20lag%20between%20them."><strong>Autocorrelation</strong></a><strong>:</strong> Autocorrelation is the correlation of a single time series with a lagged copy of itself. It is also called single correlation</p><p><a href="https://en.wikipedia.org/wiki/Autocorrelation"><strong><em>ACF</em></strong></a> is a complete auto-correlation function which gives us values of auto-correlation of any series with its lagged values. We plot these values along with the confidence interval. In simple terms, it describes how well the present value of the series is related with its past values. A time series can have components like trend, seasonality, cyclic and residual. ACF considers all these components while finding correlations hence it’s a ‘complete auto-correlation plot’.</p><p>ACF shows not only at one lag autocorrelation, but the entire autocorrelation function for different lags.</p><p><a href="https://en.wikipedia.org/wiki/Partial_autocorrelation_function"><strong><em>PACF</em></strong></a> is a partial auto-correlation function. PACF is a conditional correlation which gives the partial correlation of a stationary time series with its own lagged values, regressing the values of the time series at all shorter lags. It contrasts with the autocorrelation function, which does not control for other lags.</p><h3>5] Models:</h3><p>Time series models look at past patterns of data and attempt to predict the future based upon the underlying patterns contained within those data.</p><h4>5.1) AR model:</h4><p>In an <a href="https://en.wikipedia.org/wiki/Autoregressive_model"><em>autoregressive model</em></a>, we regress the values of the time series against previous values of the same time series.</p><p>An <strong>autoregressive</strong> <strong>model</strong> predicts future behavior based on past behavior. It’s used for forecasting when there is some correlation between values in a time series and the values that precede and succeed them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*Cvtpt5kOyC2E8f2m4KbXCw.png" /><figcaption>Image showing AR models (Photo by <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p>The order of the model is the number of times lags (p) used. and for stationary, -1&lt;a1,a2,..,ap&lt;1. If AR parameter (p) is 0, then the process is white noise.</p><h4>5.2] MA Model:</h4><p>In the <a href="https://en.wikipedia.org/wiki/Moving-average_model"><em>MA model</em></a>, we regress the values of the time series against the previous shocks/residual values of time series.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*lVfcmEVj3sIzv4yf43hOlA.png" /><figcaption>Image showing MA models (Photo by <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p>The order of the model is the number of times lags (q) used. and for stationary, -1&lt;m1,m2,..,mq&lt;1. If MA parameter (p) is 0, then the process is white noise.</p><h4>5.3] ARMA Model:</h4><p>An <a href="https://en.wikipedia.org/wiki/Autoregressive%E2%80%93moving-average_model"><em>ARMA model</em></a> is a combination of AR and MA models. The time series is regressed on the previous values and the previous shock term.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*NmMMBHLGmIyfx860HTzhtw.png" /><figcaption>Image showing ARMA models (Photo by <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><h4>5.4) ARMAX model:</h4><p>An <a href="https://en.wikipedia.org/wiki/Autoregressive%E2%80%93moving-average_model#Autoregressive%E2%80%93moving-average_model_with_exogenous_inputs_model_(ARMAX_model)"><strong><em>ARMAX</em></strong></a> is a <strong>model</strong> of lagged dependent variable and lagged independent variable(s). One possible extension to the ARMA model is to use exogenous. This means that we model the time series using other independent variables as well as the time series itself.</p><p>This is like a combination between an ARMA model and a normal linear regression model.</p><ul><li>Exogenous ARMA</li><li>Use external variables as well as time series</li><li>ARMAX =ARMA + linear regression</li></ul><p>In principle, an ARMAX model is a linear regression model that uses an ARMA-type process [i.e. w(t)] to model residuals:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*npy7X7w-H9Tt5P4i6yymdg.png" /><figcaption>Equation of ARMAX (Photo by <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><h4>5.5) ARIMA model:</h4><p><a href="https://en.wikipedia.org/wiki/Autoregressive_integrated_moving_average"><em>ARIMA model</em></a><em> </em>is actually a class of models that ‘explains’ a given time series based on its own past values, that is, its own lags and the lagged forecast errors, so that equation can be used to forecast future values.</p><p>We cannot apply the ARMA model to non-stationary times series. We need to take the difference of the time series to make it stationary. Only then can we model it.</p><p>However, when we do this, we have a modal which is trained to predict the value of the difference of the time series. What we really want to predict is not the difference, but the actual value of the time series.</p><p>An ARIMA model is characterized by 3 terms: p, d, q</p><p>where,</p><ul><li>p is the order of the AR term</li><li>q is the order of the MA term</li><li>d is the number of differencing required to make the time series stationary</li></ul><h3>6] Identifying the Order of models:</h3><p><strong>6.1) Using ACF and PACF to choose model order: </strong>By looking at the autocorrelation function<strong> (ACF) </strong>and partial autocorrelation <strong>(PACF)</strong> plots of the differenced series, you can tentatively identify the numbers of AR and/or MA terms i.e p,q that are needed.</p><p>ACF is used to identify order of MA term, and PACF for AR. There is a thumb rule that for MA, the lag where ACF shuts off suddenly is the order of MA and similarly for PACF and AR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*fBzZ2vXZxvIieyhR6V7ovg.png" /><figcaption>AR conditions (Photo by <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p>If the amplitude of the ACF tails off with increasing lag and PACF cuts off after some lag p, then we have an AR(p) model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*Cu-8zVo9bAPg9-_CO4R7sg.png" /><figcaption>MA conditions (Photo by <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p>If the amplitude of the ACF cuts off after some lag q and the<br>amplitude of the PACF tails off then we have a MA(q)<br>model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lFC5LMD95FKrI32N2r0-8Q.png" /><figcaption>Example of AR &amp; MA (Photo by <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p><strong>6.2) Information cretiaria:</strong> Two popular adjusted goodness-of-fit measures</p><p><strong>6.2.1) Akaike Information Criterion (</strong><a href="https://en.wikipedia.org/wiki/Akaike_information_criterion"><strong><em>AIC</em></strong></a><strong>) :</strong></p><ul><li>The AIC is a matrix which tells us how good a model is. A model which makes better predictions is given a lower AIC score.</li><li>AIC also penalizes models which have lots of parameters. This means if we set the order too high compared to the data, we will get a high IC value. This stops us overfitting to the training data.</li></ul><p><strong>6.2.2) Bayesian Information Criterion (</strong><a href="https://en.wikipedia.org/wiki/Bayesian_information_criterion"><strong><em>BIC</em></strong></a><strong>):</strong></p><ul><li>BIC is similar to the AIC, models which fit the data better have lower BICs and the BIC penalizes overly complex models.</li><li>The BIC penalizes additional model orders more than AIC and so the BIC will sometimes suggest a simpler model. (BIC favors simpler models)</li></ul><h3>7] Model diagnostics:</h3><p>Model diagnostics to confirm our model is behaving well. To diagnose our model we focus on the residuals to the training data.</p><p>The residuals are the difference between our model’s one-step-ahead predictions and the real values of the time series.</p><p><strong>7.1) Mean Absolute Error:<br></strong>How large the residuals are and so how far our predictions are from the true values. Then calculate mae of the residuals<br>If the model fits well the residuals will be white gaussian centered on zero.</p><p><strong>7.2) Plot Diagnostics:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*5zYmaPkj-GDuCEK3VU1d5A.png" /><figcaption>Different plots (Photo by <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p><strong>7.2.1) Residuals plot:</strong> One of the four plots shows the one-step-ahead standardized residuals. If our model is working correctly, there should be no obvious structure in the residuals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*9aj6O0jHpDJ1-JGOjLwmNA.png" /><figcaption>Standardized Plot (Photo by <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p><strong>7.2.2) Histogram plus estimated density: </strong>It shows the distribution of the residuals. Histogram shows us the measured distribution. Green lines show smoothed versions and orange lines show normal distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*NdGrYwCY7DqLVu2ENSTksg.png" /><figcaption>Histogram of residuals (Photo by <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p><strong>7.2.3) Normal Q-Q:</strong> The normal Q-Q plot is another way to show how the distribution of the model residuals compares to the normal distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*aBMTTcKU32IDg3HdLw05dQ.png" /><figcaption>Normal Q-Q plot (Photo by <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p>If our residuals are normally distributed then all the points should lie along the red line, except perhaps some values at either end.</p><p><strong>7.2.4) Correlogram:</strong> The last plot is the correlogram, which is just an ACF plot of the residuals rather than the data. 95% of the correlations for lag greater than zero should not be significant. If there is significant correlation in the residuals, it means that there is information in the data that our model hasn’t captured. The residuals are correlated. You should increase p or q.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*C_O8ylTGpRA30nhLf430yg.png" /><figcaption>Correlogram plot (Photo by <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p><strong>7.2.5) Summary statistics:</strong></p><ul><li>Prob(Q) is the p-values associated with the null hypothesis that the residuals have no correlation structure.</li><li>Prob(JB) is the p-values associated with the null hypothesis that the residuals are Gaussian normally distributed.</li><li>If either p-value is less than 0.05, we reject the null hypothesis.</li></ul><h3>8] Box-Jenkins method:</h3><p>The <a href="https://en.wikipedia.org/wiki/Box%E2%80%93Jenkins_method"><em>Box-Jenkins method</em></a> is a kind of checklist for you to go from raw data to a model ready for production. The three main steps that stand between you and a production ready model are identification, estimation and model diagnostics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*crr0bekNHJB3xk0ewxYOwQ.png" /><figcaption>Image by Panwar Abhash Anil</figcaption></figure><ul><li><strong>Identication</strong><br>In this step, we explore and characterize the data to find some form of it which is appropriate to modeling.<br>• Is the time series stationary?<br>• What differencing will make it stationary?<br>• What transforms will make it stationary?<br>• What values of p and q are most promising?</li><li><strong>Identication tools<br></strong>• Plot the time series df.plot()<br>• Use augmented Dicky-Fuller test adfuller()<br>• Use transforms and/or differencing df.diff() , np.log() , np.sqrt()<br>• Plot ACF/PACF plot_acf() , plot_pacf()</li><li><strong>Estimation<br></strong>This involves using numerical methods to estimate the AR and MA coefficients of the data.<br>This is automatically done for us when we call the models.fit() method.<br>• Use the data to train the model coefficients<br>• Done for us using model.fit()<br>• Choose between models using AIC and BIC: results.aic , results.bic</li><li><strong>Model Diagnostics:</strong> In this step, we evaluate the quality of the best fitting model.<br>• Are the residuals uncorrelated.<br>• Are residuals normally distributed.</li><li><strong>Decision</strong><br>Using the information gathered from statistical tests and plot during the diagnostic step, we need to make a decision. Is the model good enough or do we need to go back and rework.<br>If the residuals are not as they should be we will go back and rethink our choices in the earlier steps. If the residuals are okay then we can go ahead and make forecasts.</li></ul><h3>Conclusion:</h3><p>In this article, we got introduced to time series analysis,stationary,white noise, ACF, PACF, models used in time series forecasting, different ways to identify order of models and how to evaluate models?</p><p>Thanks for reading. I hope this helped you understanding core concepts of time series analysis.</p><p>Follow me up at <a href="https://medium.com/@abhashpanwar"><strong>Medium</strong></a>. As always, I welcome feedback and can be reached on <a href="https://www.linkedin.com/in/abhash-panwar-85126976/"><strong>Linkedin</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbf6c394984f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/introduction-to-time-series-analysis-and-key-concepts-dbf6c394984f">Introduction to Time Series Analysis and key concepts</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[Feature Engineering for Machine Learning]]></title>
            <link>https://medium.com/analytics-vidhya/feature-engineering-for-machine-learning-e3c34d6c8055?source=rss-7571d881a77d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3c34d6c8055</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[feature-engineering]]></category>
            <dc:creator><![CDATA[Panwar Abhash Anil]]></dc:creator>
            <pubDate>Tue, 20 Oct 2020 06:34:36 GMT</pubDate>
            <atom:updated>2021-01-19T04:18:06.049Z</atom:updated>
            <content:encoded><![CDATA[<h3>Feature Engineering in Machine Learning</h3><p>Handling missing values, Encoding techniques, Handle outliers, Transformation techniques, Feature selection techniques, ETC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Zzxc_RXzuvMt7xnn4MyFWA.png" /><figcaption>Photo By Google</figcaption></figure><blockquote>In this article, I will discuss about the feature engineering and their techniques. The codes related to this is in my <a href="https://github.com/abhashpanwar/machine-learning/tree/master/Feature%20Engineering">GitHub</a>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Xe4mAYAwov43LOqBIdJaXA.jpeg" /></figure><p>Feature engineering is the process in machine learning in which using domain knowledge we extract features from raw data. These features can be used to improve the performance of machine learning algorithms. Feature engineering includes data cleaning, feature extraction, feature selection, preprocessing, etc.</p><p>Here in this article, I will discuss some feature engineering techniques in-depth and some brief introduction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kKE4AuDsOgna-41ikUjByg.jpeg" /></figure><h3>Why Feature Engineering:</h3><ol><li>The features/columns in data will directly influence the predictive models you use and the results you can achieve.</li><li>Improve model performance.</li><li>The model can’t be performed on raw data, so data cleaning is required.</li></ol><h3>Major Feature Engineering Include:</h3><ol><li>Handling Missing Values (Find the relationship between missing values and target variables before handling them)</li><li>Encode Categorical Variables</li><li>Handle outliers</li><li>Handle Imbalanced Dataset</li><li>Transformation (Like Standardization or Normalization)</li><li>Feature Selection Techniques</li></ol><h3>1) Handling Missing Values</h3><h4>1.1) Mean/Median/Mode replacement:</h4><ul><li>If a feature has lots of <strong><em>NaN</em></strong> values, replace with median or mean iff that feature has a relationship with the target variable or when data are missing completely at random (<a href="https://en.wikipedia.org/wiki/Missing_data#Missing_completely_at_random"><em>MCAR</em></a>).</li><li>Impute <strong><em>mode</em></strong> in case of the categorical variable.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*xnV-pXsnxvyftGuXgw-DPA.png" /><figcaption><a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Image by Panwar Abhash Anil</a></figcaption></figure><p>The blue line(original data) is different from the red line (imputed data) so, we can conclude that the distribution of data is not the same.</p><h4><strong><em>Advantages:</em></strong></h4><ul><li>Easy to implement (Robust to outliers).</li><li>The faster way to obtain the complete dataset.</li></ul><h4>Disadvantages:</h4><ul><li>Change or Distortion in the original variance.</li><li>Impacts Correlation.</li></ul><h4>1.2) Random Sample Imputation:</h4><ul><li>Random sample imputation consists of taking random observation from the dataset and we use this observation to replace the NaN values.</li><li>When should we use? It assumes that the data are missing completely at random(MCAR).</li><li>Both for numerical and categorical features.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*NebBBQvRagqUygsiyksfIg.png" /><figcaption><a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Image by Panwar Abhash Anil</a></figcaption></figure><p>The original data (blue line) is overlap with the imputed data (green line). Distribution before and after imputation is the same.</p><h4>Advantages</h4><ul><li>Easy To implement.</li><li>There is less distortion invariance.</li></ul><h4>Disadvantage</h4><ul><li>On every situation, randomness won&#39;t work.</li></ul><h4>1.3) Capturing NAN values with a new feature:</h4><ul><li>It works well if the data are not missing completely at random (<a href="https://en.wikipedia.org/wiki/Missing_data#Missing_not_at_random"><em>MAR</em></a>) and when there is more number of NaN values.</li><li>It captures the importance of NaN values.</li><li>Majorly for categorical features.</li></ul><blockquote>df[‘feature_NAN’]=np.where(df[‘feature’].isnull(),1,0)</blockquote><h4>Advantages</h4><ul><li>Easy to implement.</li><li>Captures the importance of missing values.</li></ul><h4>Disadvantages</h4><ul><li>Creating Additional Features(Curse of Dimensionality).</li></ul><h3>1.4) End of distribution imputation:</h3><ul><li>When the missing value is not at random then capturing that information is important.</li><li>We take the values that are after 3rd std.</li><li>Used for numerical features.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vH1cL27tgvDAwC_usXj4TA.jpeg" /><figcaption><a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Image by Panwar Abhash Anil</a></figcaption></figure><h4>Advantages</h4><ul><li>It is quick.</li><li>Captures the importance of missing values (if one suspects the missing data is valuable).</li></ul><h4>Disadvantages</h4><ul><li>Distort the variable.</li><li>Mask predictive power if missingness is not important.</li><li>Hide true outliers if the missing data is large.</li></ul><h4>1.5) Arbitrary Value Imputation:</h4><ul><li>This technique was derived from Kaggle competition. It consists of replacing NAN by an arbitrary value.</li><li>For numerical features.</li></ul><h4>Advantages</h4><ul><li>Easy to implement.</li><li>Captures the importance of missingness if there is one.</li></ul><h4>Disadvantages</h4><ul><li>Distorts the original distribution of the variable.</li><li>If missingness is not important, it may mask the predictive power of the original variable by distorting its distribution.</li><li>Hard to decide which value to use.</li></ul><h4>1.6)Frequent Category Imputation:</h4><p>The categorical features are imputed by the frequency of the categories of the feature.</p><h4>Advantages</h4><ul><li>Easy To implement.</li></ul><h4>Disadvantages</h4><ul><li>Since we are using the more frequent labels, it may use them in an over-represented way, if there are many nan’s.</li><li>It distorts the relation of the most frequent label.</li></ul><h4>1.7) Treat NaN value of categorical as new category:</h4><ul><li>This technique will be helpful when the test dataset does contain a category that does not exist on the training dataset. So the unknown category is treated as a new category.</li><li>For categorical features.</li></ul><h3>2) Types of encoding techniques</h3><p>Before giving the data to the model the <strong>categorical variables </strong>must be <strong>converted</strong> into the numerical because the model does the mathematical computations so numerical values are required.</p><h4>2.1) Nominal Encoding:</h4><p><strong>Nominal data</strong> is defined as <strong>data</strong> that is used for naming or labelling variables, without any quantitative value.</p><h4>2.1.1) One Hot Encoding (like gender):</h4><p>This technique creates a binary column for each category and returns a sparse matrix or dense array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*rui9YMnsBYhYoydK4Ajkfg.jpeg" /><figcaption><a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Image by Panwar Abhash Anil</a></figcaption></figure><h4>2.1.2) One Hot Encoding with many categorical (like Pincode):</h4><ul><li>Suppose there are more than 20 categories of a variable then we can’t apply direct One Hot Encoding</li><li>Find most top k categories repeating most frequent</li><li>Then take that k category and create k new features.</li></ul><h4>2.1.2)Mean Encoding:</h4><p>The categories of categorical features are replaced by their mean value.</p><h4><strong>Advantages:</strong></h4><ul><li>Capture information within the label, therefore rendering more predictive features</li><li>Creates a monotonic relationship between the variable and the target</li></ul><h4><strong>Disadvantages:</strong></h4><ul><li>It may cause over-fitting in the model.</li></ul><h4>2.2)Ordinal Encoding:</h4><p><strong>Ordinal data</strong> is a categorical <strong>data</strong> type where the variables have natural, ordered categories and the distances between the categories are not known. Example: Rating, rank, etc.</p><h4>2.2.1)Label Encoding:</h4><p><strong>Label encoding</strong> is simply converting each value in a column to a number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*hCjA5jC0B29IuhvvLUo80w.jpeg" /><figcaption><a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Image by Panwar Abhash Anil</a></figcaption></figure><p>Naturally, education order is as follow: BE-&gt;BSc-&gt;Phd</p><p>So label encoding will be as :(BE-&gt;0,BSs-&gt;1,Phd-&gt;2).</p><h4>2.2.2)Target guided Ordinal Encoding:</h4><ul><li>Labels are given on the bases of the mean. Highest the mean, highest the label</li><li>Ordering the labels according to the target variable.</li><li>Replace the labels by the joint probability.</li></ul><h4>2.3) Count Encoding:</h4><ul><li>Replace the categories with there count.</li><li>It is used when are lots of categories of a variable</li><li>It does not create a new feature.</li><li>Disadvantage: If the same labels have the same count then replaced by the same count and we will lose some valuable information.</li></ul><h3>3)Outliers:</h3><h4>3.1) If the feature is Normally Distributed we use this:</h4><pre>uppper_boundary=df[&#39;Age&#39;].mean() + 3* df[&#39;Age&#39;].std() <br>lower_boundary=df[&#39;Age&#39;].mean() - 3* df[&#39;Age&#39;].std()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*xGV7qxaDySY_c1NYzDW0VQ.png" /><figcaption><a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Image by Panwar Abhash Anil</a></figcaption></figure><h4>3.2) If the features are skewed we use the below technique:</h4><pre>IQR=df.Fare.quantile(0.75)-df.Fare.quantile(0.25) <br>lower_bridge=df[&#39;Fare&#39;].quantile(0.25)-(IQR*1.5) <br>upper_bridge=df[&#39;Fare&#39;].quantile(0.75)+(IQR*1.5)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*w4-sjkrfS-XihYaFypVSqA.png" /><figcaption><a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Image by Panwar Abhash Anil</a></figcaption></figure><h3>4) Handling Imbalanced Dataset:</h3><ol><li>Increase class weight</li><li>Under Sampling — reduce the points of the max labels</li><li>Over Sampling</li><li>SMOTETomek: Combine over- and under-sampling using SMOTE and Tomek links.</li><li>Ensemble Techniques <a href="https://en.wikipedia.org/wiki/Oversampling_and_undersampling_in_data_analysis">More Details</a></li></ol><h3>5) Transformation of Features:</h3><h4>Why Feature Scaling</h4><ul><li>Scaling down the feature it easy to run and calculations become easy.</li><li>All tree-based models do not require scaling.</li></ul><ol><li>Normalization And Standardization</li><li>Gaussian Transformation: Logarithmic Transformation [log(x)], Reciprocal Transformation [1/x] and Square Root Transformation [sqrt(x)].</li><li>Exponential Transformation (e^x )</li><li>Box-Cox Transformation: It is used to modify the distributional shape of a set of data to be more normally distributed. <a href="https://www.statisticshowto.com/box-cox-transformation/#:~:text=A%20Box%20Cox%20transformation%20is,a%20broader%20number%20of%20tests.">More Details</a></li></ol><h3>6) <strong>Feature Selection Techniques:</strong></h3><ol><li>Univariate Selection:<br>Univariate feature selection works by selecting the best features based on univariate statistical tests. We compare each feature to the target variable, to see whether there is any statistically significant relationship between them.</li><li>Feature Importance<br>This technique gives you a score for each feature of your data, the higher the score more relevant it is.</li><li>Correlation: For numerical features</li></ol><h3>Important Points:</h3><ol><li>Remove high cardinality of categorical variables.</li><li>Bar Plot is for discrete values.</li><li>The histogram is for continuous values.</li><li>If numerical variables are skewed then perform log-normal distribution.</li></ol><p>Thanks for reading. I hope this helps you understanding feature engineering.</p><p>Follow me up at <a href="https://medium.com/@abhashpanwar"><strong>Medium</strong></a>. As always, I welcome feedback and can be reached on <a href="https://www.linkedin.com/in/abhash-panwar-85126976/"><strong>Linkedin</strong></a>.</p><h3><strong>Reference:</strong></h3><p>I learnt most of the things from the below youtube playlist.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPLZoTAELRMXVPwYGE2PXD3x0bfKnR0cJjN&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fplaylist%3Flist%3DPLZoTAELRMXVPwYGE2PXD3x0bfKnR0cJjN&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F6WDFfaYtN6s%2Fhqdefault.jpg%3Fsqp%3D-oaymwEWCKgBEF5IWvKriqkDCQgBFQAAiEIYAQ%3D%3D%26rs%3DAOn4CLDI9XsvGV6LmuGnkMxr6VkUurtprw%26days_since_epoch%3D18554&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="853" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc2573f577c0ea43a411f8a5d65747bf/href">https://medium.com/media/cc2573f577c0ea43a411f8a5d65747bf/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3c34d6c8055" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/feature-engineering-for-machine-learning-e3c34d6c8055">Feature Engineering for Machine Learning</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[Web Scraping and Analysis of extracted data using Python]]></title>
            <link>https://medium.com/analytics-vidhya/web-scraping-and-analysis-of-extracted-data-fe4ee855da06?source=rss-7571d881a77d------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe4ee855da06</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[youtube]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Panwar Abhash Anil]]></dc:creator>
            <pubDate>Tue, 11 Aug 2020 12:10:21 GMT</pubDate>
            <atom:updated>2020-08-12T12:30:05.128Z</atom:updated>
            <content:encoded><![CDATA[<h4>Web scraping by Beautiful Soup from three different Youtube Videos and Analysis of these Videos.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SIymDKetr0Q0wIX8fT6Zgw.jpeg" /></figure><p>In this project, I have extracted the required data (title, likes, dislikes, comments) of videos from youtube.com and re-arranged properly to analyze these videos and get some insight from the data. You can reach Python scripts relative to this project on this given link <a href="https://github.com/abhashpanwar/webscraping"><em>GitHub Repository</em></a><em>.</em></p><blockquote><a href="https://en.wikipedia.org/wiki/Web_scraping"><strong>Web scraping</strong></a> (or Screen Scraping or Web Data Extraction or Web Harvesting) is basically a process of extracting data from a website using some scripts or automaton tools/software. Web scraping, also known as web data extraction, is the process of retrieving or “scraping” data from a website.</blockquote><h4>Tool Used:</h4><ol><li><a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#"><em>BeautifulSoup</em></a>: <em>BeautifulSoup</em> is a Python library for pulling data out of HTML and XML files. It works with your favourite parser to provide idiomatic ways of navigating, searching, and modifying the parse tree.</li></ol><p><em>BeautifulSoup</em> parses anything you give it and does the tree traversal stuff for you. You can tell it “Find all the links”, or “Find all the links of class external Link”, or “Find all the links whose URLs match “foo.com”, or “Find the table heading that’s got bold text, then give me that text.”</p><p>2. <a href="https://textblob.readthedocs.io/en/dev/"><em>TextBlob</em></a>: <a href="https://pypi.org/project/textblob/">TextBlob</a> is a Python (2 and 3) library for processing textual data. It provides a simple API for diving into common <a href="https://en.wikipedia.org/wiki/Natural_language_processing">Natural Language Processing (NLP)</a> tasks such as part-of-speech tagging, noun phrase extraction, sentiment analysis, classification, translation, and more.</p><h4>Basic Steps to Extract Data:</h4><ol><li>Input HTML page.</li><li>Convert it to your favourite parser to provide idiomatic ways of navigating, searching, and modifying the parse tree.</li><li>Identify the required data.</li><li>Find the data.</li><li>Store the data in a specific format.</li></ol><h3>Part 1: Web Scraping</h3><h4>Step 1: Include the required libraries</h4><h4>Step 2: Define the HTML page links</h4><p>I have already downloaded the HTML pages and in other cases, if we want HTML pages online then define the URLs.</p><h4>Step 3: I have created a function for each task.</h4><p><strong>Step 3.1: convertToNumber()</strong></p><p>This function will convert the text data into a numeric format.</p><p>Example: “151,641,939 views” into “151641939”</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e3302063a2668c028c1fe775e26fd93/href">https://medium.com/media/7e3302063a2668c028c1fe775e26fd93/href</a></iframe><p><strong>Step 3.2: generateData()</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/957983203222420caddfd2f9c00d4b93/href">https://medium.com/media/957983203222420caddfd2f9c00d4b93/href</a></iframe><p>This function will collect data from the HTML page using BeautifulSoup and stored in videoData series.</p><p><strong>Step 3.3: generateDataframe()</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e980545eccfe3a18a501523bab677533/href">https://medium.com/media/e980545eccfe3a18a501523bab677533/href</a></iframe><p>The above function will create a data frame of extracted data into rows and columns.</p><p><strong>Step 3.4: generatepolarity()</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b19b479f6f251f45bdcd53ecb0f327c/href">https://medium.com/media/6b19b479f6f251f45bdcd53ecb0f327c/href</a></iframe><p>The above function will generate polarity of each comment i.e. a comment is good, bad, or neutral.</p><p><strong>Step 3.5: At last all functions are called and final output/data is generated.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e575db1e5d8f6aea08662229a472ba58/href">https://medium.com/media/e575db1e5d8f6aea08662229a472ba58/href</a></iframe><h4>Final Output:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*_odEQ_FfKjHLyWcvBUXxQA.png" /><figcaption>Final output after extraction of data and concatenation of all CSV files</figcaption></figure><h3>Part 2: Data Visualization/Analysing Data</h3><p>Note: Code of each graph is in mainFile.ipynb file</p><h4>1) Analyzing Views:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wseHmtVKzUWx9Bm79ZxosA.jpeg" /></figure><p>From the above graph, we can say that “Rewind 2016” got max views out of three videos.</p><h4>2) Analyzing Polarity:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XHcBAeh0fKyZ1E0O-OuiUw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NeK5PW-UMoke3tLBBMCJHQ.jpeg" /><figcaption>Stacket Bar Plot</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VQPR6dMv53F6z-rFoWAFAg.jpeg" /><figcaption>Pie Plot showing no. of comments below polarity class for each video</figcaption></figure><p>From the above graphs,</p><ul><li>Rewind 2015 has max positive comments and the other two videos have nearly equal positive comments.</li><li>Rewind 2016 has max neutral comments.</li><li>Rewind 2019 has max negative comments. This video got more negativity.</li></ul><p>In this project, I had taken a sample to 200 comments, so generalization to a population that</p><p>“Rewind 2015” gets more positivity reviews and “Rewind 2019” gets more negative reviews.</p><h4>3)Analyzing Likes / Dislikes:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hCmsXsEhiicsYwTe61kYBw.jpeg" /><figcaption>Bar plot of Likes and Dislikes</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_pRg816YjfVerHmbud_oeQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0tFQKOlIXEpqGBV6HR3Uhw.jpeg" /><figcaption>Stacked Relative Plot</figcaption></figure><p>From the above figures, we can say that</p><ul><li>“Rewind 2016” has max likes or users enjoying this video and overall, all three videos have nearly equal likes.</li><li>“Rewind 2019” got a high number of dislikes which means this video getting negativity or the content of the video is not liked by users.</li></ul><h3>Conclusion:</h3><ol><li>Rewind 2015 and Rewind 2016 are better as compared to dislikes.</li><li>Rewind 2016 is performing well as it has good likes and positive comments.</li><li>Rewind 2019 performing badly because it got a high number of dislikes and negative comments.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe4ee855da06" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/web-scraping-and-analysis-of-extracted-data-fe4ee855da06">Web Scraping and Analysis of extracted data using Python</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[Used Car Price Prediction using Machine Learning]]></title>
            <link>https://medium.com/data-science/used-car-price-prediction-using-machine-learning-e3be02d977b2?source=rss-7571d881a77d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3be02d977b2</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Panwar Abhash Anil]]></dc:creator>
            <pubDate>Mon, 03 Aug 2020 10:01:01 GMT</pubDate>
            <atom:updated>2021-04-26T17:17:18.539Z</atom:updated>
            <content:encoded><![CDATA[<h4>Data Cleaning, Data Preprocessing, 8 Different ML Models and Some Insights from Data</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*ZOcUPrSXLYucFxppoI-dYg.png" /><figcaption>Image By Panwar Abhash Anil</figcaption></figure><blockquote><em>You can reach all Python scripts relative to this on my </em><a href="https://github.com/abhashpanwar/used-car-price-prediction">GitHub page</a><em>. If you are interested, you can also find the scripts used for data cleaning and data visualization for this study in the same repository.</em></blockquote><blockquote><em>The project is also deployed using Django on </em><a href="https://abhash-car-price-prediction.herokuapp.com/"><em>Heroku</em></a><em> and also on Amazon EC2 by </em><a href="http://ec2-54-82-16-204.compute-1.amazonaws.com:8080/"><em>Dockerizing Django App</em></a></blockquote><h3>Content</h3><ol><li>Data Cleaning (Identifying null values, filling missing values and removing outliers)</li><li>Data Preprocessing (Standardization or Normalization)</li><li>ML Models: Linear Regression, Ridge Regression, Lasso, KNN, Random Forest Regressor, Bagging Regressor, Adaboost Regressor, and XGBoost</li><li>Comparison of the performance of the models</li><li>Some insights from data</li></ol><h4>Why is price feature scaled by log transformation?</h4><p>In the regression model, for any fixed value of X, Y is distributed in this problem data-target value (Price ) not normally distributed, it is right skewed.</p><p>To solve this problem, the log transformation on the target variable is applied when it has skewed distribution and we need to apply an inverse function on the predicted values to get the actual predicted target value.</p><p>Due to this, for evaluating the model, the <a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_log_error.html"><em>RMSLE</em></a> is calculated to check the error and the <a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.r2_score.html"><em>R2 Score</em></a> is also calculated to evaluate the accuracy of the model.</p><h3>Some Key Concepts:</h3><ul><li><strong>Learning Rate: </strong>Learning rate is a hyper-parameter that controls how much we are adjusting the weights of our network concerning the loss gradient. The lower the value, the slower we travel along the downward slope. While this might be a good idea (using a low learning rate) in terms of making sure that we do not miss any local minima, it could also mean that we’ll be taking a long time to converge — especially if we get stuck on a plateau region.</li><li><strong>n_estimators</strong>: This is the number of trees you want to build before taking the maximum voting or averages of predictions. A higher number of trees give you better performance but make your code slower.</li><li><strong>R² Score: </strong>It is a statistical measure of how close the data are to the fitted regression line. It is also known as the coefficient of determination, or the coefficient of multiple determination for multiple regression. 0% indicates that the model explains none of the variability of the response data around its mean.</li></ul><h3>1. The Data:</h3><p>The dataset used in this project was downloaded from <a href="https://www.kaggle.com/austinreese/craigslist-carstrucks-data">Kaggle</a>.</p><h3>2. Data Cleaning:</h3><p>The first step is to remove irrelevant/useless features like ‘URL’, ’region_url’, ’vin’, ’image_url’, ’description’, ’county’, ’state’ from the dataset.</p><p>As a next step, check missing values for each feature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*2EPrbZHIVWGSz6xAqUYIIA.png" /><figcaption>Showing missing values (Image By Panwar Abhash Anil)</figcaption></figure><p>Next, now missing values were filled with appropriate values by an appropriate method.</p><p>To fill the missing values, <a href="https://scikit-learn.org/stable/modules/generated/sklearn.impute.IterativeImputer.html"><em>IterativeImputer</em></a> method is used and different estimators are implemented then calculated <a href="https://en.wikipedia.org/wiki/Mean_squared_error"><em>MSE</em></a> of each estimator using <a href="https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.cross_val_score.html"><em>cross_val_score</em></a></p><ol><li>Mean and Median</li><li>BayesianRidge Estimator</li><li>DecisionTreeRegressor Estimator</li><li>ExtraTreesRegressor Estimator</li><li>KNeighborsRegressor Estimator</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*5Mp3PscLpgg1Zmck6TqQnw.png" /><figcaption>MSE with Different Imputation Methods (Image By Panwar Abhash Anil)</figcaption></figure><p>From the above figure, we can conclude that the <em>ExtraTreesRegressor </em>estimator will be better for the imputation method to fill the missing value.</p><figure><img alt="zero-null-value" src="https://cdn-images-1.medium.com/max/419/1*7h8JugocaValwthZeXIo0A.png" /><figcaption>Missing values after filling (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p>At last, after dealing with missing values there zero null values.</p><p><strong>Outliers: </strong>InterQuartile Range (IQR) method is used to remove the outliers from the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*J3alPNZZJ4Wm9WHf0btCnQ.jpeg" /><figcaption>Box Plot of price showing outliers (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*MBJDuHn4xIPy_7EzoH5STA.jpeg" /><figcaption>Box Plot of Odometer showing outliers (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P6qsfXxrfM9BGanUaIsF_w.jpeg" /><figcaption>Box Plot &amp; Histogram of the year (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><ul><li>From figure 1, the prices whose log is below 6.55 and above 11.55 are the outliers</li><li>From figure 2, it is impossible to conclude something so IQR is calculated to find outliers i.e. odometer values below 6.55 and above 11.55 are the outliers.</li><li>From figure 3, the year below 1995 and above 2020 are the outliers.</li></ul><p>At last, Shape of dataset before process= (435849, 25) and after process= (374136, 18). Total 61713 rows and 7 cols removed.</p><h3>3. Data preprocessing:</h3><p><strong>Label Encoder:</strong> In our dataset, 12 features are categorical variables and 4 numerical variables (price column excluded). To apply the ML models, we need to transform these categorical variables into numerical variables. And sklearn library <a href="https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.LabelEncoder.html"><em>LabelEncoder</em></a> is used to solve this problem.</p><p><strong>Normalization</strong>: The dataset is not normally distributed. All the features have different ranges. Without normalization, the ML model will try to disregard coefficients of features that have low values because their impact will be so small compared to the big value. Hence to normalized, <a href="https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html"><em>sklearn library i.e. MinMaxScaler</em></a> is used.</p><p><strong>Train the data.</strong> In this process, 90% of the data was split for the train data and 10% of the data was taken as test data.</p><h3>4. ML Models:</h3><p>In this section, different machine learning algorithms are used to predict price/target-variable.</p><p>The dataset is supervised, so the models are applied in a given order:</p><ol><li><a href="https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html">Linear Regression</a></li><li><a href="https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.ridge_regression.html">Ridge Regression</a></li><li><a href="https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Lasso.html">Lasso Regression</a></li><li><a href="https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsRegressor.html">K-Neighbors Regressor</a></li><li><a href="https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestRegressor.html">Random Forest Regressor</a></li><li><a href="https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.BaggingRegressor.html">Bagging Regressor</a></li><li><a href="https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.AdaBoostRegressor.html">Adaboost Regressor</a></li><li><a href="https://xgboost.readthedocs.io/en/latest/">XGBoost</a></li></ol><h4>1) Linear Regression:</h4><p>In statistics, linear regression is a linear approach to modelling the relationship between a scalar response (or dependent variable) and one or more explanatory variables (or independent variables). In linear regression, the relationships are modelled using linear predictor functions whose unknown model parameters are estimated from the data. Such models are called linear models. <a href="https://en.wikipedia.org/wiki/Linear_regression"><em>More Details</em></a></p><p>Coefficients: The sign of each coefficient indicates the direction of the relationship between a predictor variable and the response variable.</p><ul><li>A positive sign indicates that as the predictor variable increases, the response variable also increases.</li><li>A negative sign indicates that as the predictor variable increases, the response variable decreases.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*2xeokQnLn7xbZ2Ipw5tLDw.png" /><figcaption>Graph showing performance of Linear regression (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*Pi93nxezaDaeqFnf-mbtXA.jpeg" /><figcaption>Graph showing important feature of the dataset (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p>Considering this figure, linear regression suggests that <strong><em>year, cylinder, transmission, fuel, and odometer</em></strong> these five variables are the most important.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*8BEVfmm_vEGtHw1tdhkEOQ.png" /><figcaption>Result of Linear regression (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><h4>2) Ridge Regression:</h4><p><strong>Ridge Regression</strong> is a technique for analyzing multiple regression data that suffer from multicollinearity. When multicollinearity occurs, least squares estimates are unbiased, but their variances are large so they may be far from the true value.</p><p>To find the best alpha value in ridge regression, yellowbrick library <a href="https://www.scikit-yb.org/en/latest/api/regressor/alphas.html"><em>AlphaSelection</em></a> was applied.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*8HDeCd_6C6UPXg28gqLwBA.png" /><figcaption>Graph showing best value of Alpha</figcaption></figure><p>From the figure, the best value of alpha to fit the dataset is 20.336.</p><p>Note: The value of alpha is not constant it varies every time.</p><p>Using this value of alpha, Ridgeregressor is implemented.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*JCldwUXZFuxhUFzXXmaHGg.jpeg" /><figcaption>Graph showing Important Features</figcaption></figure><p>Considering this figure, Lasso regression suggests that <strong><em>year, cylinder, transmission, fuel, and odometer</em></strong> these five variables are the most important.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*uEVvsEUyBM1fdv6kRErZZg.png" /><figcaption>Final Result of this model (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p>The performance of ridge regression is almost the same as Linear Regression.</p><h4>3)Lasso Regression:</h4><p>Lasso regression is a type of linear regression that uses shrinkage. Shrinkage is where data values are shrunk towards a central point as mean. The lasso procedure encourages simple, sparse models (i.e. models with fewer parameters).</p><p><strong>Why Lasso regression is used?</strong></p><p>The goal of lasso regression is to obtain the subset of predictors that minimizes prediction error for a quantitative response variable. The lasso does this by imposing a constraint on the model parameters that cause regression coefficients for some variables to shrink toward zero.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*6RYwCGUqNXZrKReGji1TUA.png" /><figcaption>Final Result of this model (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p>But for this dataset, there is no need for lasso regression as there no much difference in error.</p><h4>4)KNeighbors Regressor: Regression-based on k-nearest neighbors.</h4><p>The target is predicted by local interpolation of the targets associated with the nearest neighbours the training set.</p><p><em>k</em>-NN is a type of <a href="https://en.wikipedia.org/wiki/Instance-based_learning">instance-based learning</a>, or <a href="https://en.wikipedia.org/wiki/Lazy_learning">lazy learning</a>, where the function is only approximated locally and all computation is deferred until function evaluation. <a href="https://www.kite.com/python/docs/sklearn.neighbors.KNeighborsRegressor"><strong><em>Read More</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*ozTH4P3Hi0Cw4_rKQPSGtA.png" /><figcaption>Error Plot For Each K range 1–9 (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p>From the above figure, for k=5 KNN give the least error. So dataset is trained using n_neighbors=5 and metric=’euclidean’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*emXX4dcH_AWq7xbnrFokSA.png" /><figcaption>Final result of KNN (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p>The performance KNN is better and error is decreasing with increased accuracy.</p><h4>5) Random Forest:</h4><p>The random forest is a classification algorithm consisting of many decision trees. It uses bagging and feature randomness when building each tree to try to create an uncorrelated forest of trees whose prediction by committee is more accurate than that of any individual tree. <a href="https://en.wikipedia.org/wiki/Random_forest"><strong><em>Read More</em></strong></a></p><p>In our model, 180 decisions are created with max_features 0.5</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*zkcpztR7BL97M_gJKnbJ4w.jpeg" /><figcaption>Performance of Random Forest (True value vs predicted value)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*etX_i8kHXxAA2ZV1relcBw.jpeg" /></figure><p>This is the simple bar plot which illustrates that <strong><em>year</em></strong> is the most important feature of a car and then <strong><em>odometer</em></strong> variable and then others.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*j_A8fK0kDW4XamxL7Fch3A.png" /><figcaption>Accuracy Table of Random Forest Model (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p>The performance of the Random forest is better and accuracy is increased by approx. 10% which is good. Since the random forest is using bagging when building each tree so next Bagging Regressor will be performed.</p><h4>6) Bagging Regressor:</h4><p>A Bagging regressor is an ensemble meta-estimator that fits base regressors each on random subsets of the original dataset and then aggregates their predictions (either by voting or by averaging) to form a final prediction. Such a meta-estimator can typically be used as a way to reduce the variance of a black-box estimator (e.g., a decision tree), by introducing randomization into its construction procedure and then making an ensemble out of it. <a href="https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.BaggingRegressor.html"><strong><em>Read More</em></strong></a></p><p>In our model, DecisionTreeRegressor is used as the estimator with max_depth=20 which creates 50 decision trees and the results show below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*cAW2QHkrcotgdGiBUgZn_Q.png" /><figcaption>Accuracy Table of Bagging Regressor (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p>The performance of Random Forest is much better than Bagging regressor.</p><p><strong>The key difference between Random forest and Bagging: </strong>The fundamental difference is that in <strong>Random forests</strong>, only a subset of features are selected at random out of the total <strong>and</strong> the best split feature from the subset is used to split each node in a tree, unlike in <strong>bagging</strong> where all features are considered for splitting a node.</p><h4>7) Adaboost regressor:</h4><p>AdaBoost can be used to boost the performance of any machine learning algorithm. Adaboost helps you combine multiple “weak classifiers” into a single “strong classifier”. <strong>Library used: </strong><a href="https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.AdaBoostRegressor.html">AdaBoostRegressor</a> &amp; <a href="https://en.wikipedia.org/wiki/AdaBoost"><strong><em>Read More</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*jKBeeEm8CJSV2JBccKcxXQ.jpeg" /></figure><p>This is the simple bar plot which illustrates that <strong><em>year</em></strong> is the most important feature of a car and then <strong><em>odometer</em></strong> variable and then model, etc.</p><p>In our model, DecisionTreeRegressor is used as an estimator with 24 max_depth and creates 200 trees &amp; learning the model with 0.6 learning_rate and result shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*YFhcbflIh3SsMSMRsg_cZw.png" /><figcaption>Accuracy Table of AdaBoost Regressor (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><h4>8) XGBoost: XGBoost stands for eXtreme Gradient Boosting</h4><p>XGBoost is an <a href="https://en.wikipedia.org/wiki/Ensemble_learning">ensemble learning </a>method.XGBoost is an implementation of gradient boosted decision trees designed for speed and performance. The beauty of this powerful algorithm lies in its scalability, which drives fast learning through parallel and distributed computing and offers efficient memory usage. <a href="https://www.analyticsvidhya.com/blog/2018/09/an-end-to-end-guide-to-understand-the-math-behind-xgboost/"><strong><em>Read More</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*yXftMIVgQZLnjMJ92Z1w0A.jpeg" /></figure><p>This is the simple bar plot in descending of importance which illustrates that which<strong><em> </em>feature/variable<em> </em></strong>is an important feature of a car is more important.</p><p>According to XGBoost, <strong>Odometer</strong> is an important feature whereas from the previous models <strong>year</strong> is an important feature.</p><p>In this model,200 decision trees are created of 24 max depth and the model is learning the parameter with a 0.4 learning rate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*QKrWdcpHiulRLLQuw8pPxw.png" /><figcaption>Accuracy Table of XGBoost Regressor (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><h3>4)Comparison of the performance of the models:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8eZXofAxqfRwtT-i0dtFKg.jpeg" /><figcaption>Accuracy Comparison of Each Model (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*z81UsHSR2SkVrRsDnzyWrw.png" /><figcaption>Overall Accuracy Table (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p>From the above figures, we can conclude that XGBoost regressor with 89.662% accuracy is performing better than other models.</p><h3>5) Some insights from the dataset:</h3><p>1From the pair plot, we can’t conclude anything. There is no correlation between the variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*4prrHWaa8gMCRoivyabCJQ.png" /><figcaption>Pair Plot to Find Correlation</figcaption></figure><p>2From the distplot, we can conclude that initially, the price is increasing rapidly but after a particular point, the price starts decreasing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*DTsSYuGAmFfWgva4LssFSw.png" /><figcaption>Graph Showing Distribution of price (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p>3From figure 1, we analyze that the car price of the diesel variant is high then the price of the electric variant comes. Hybrid variant cars have the lowest price.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*a5diIhr--h_-wTlt6lQKNA.png" /><figcaption>Bar Plot showing the price of each fuel type</figcaption></figure><p>4 From figure 2, we analyze that the car price of the respective fuel also depends upon the condition of the car.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*PD2pzladq6HRqM7_I_j_Rw.png" /><figcaption>Bar Plot between fuel and price with hue condition</figcaption></figure><p>5From figure 3, we analyze that car prices are increasing per year after 1995, and from figure 4, the number of cars also increasing per year, and at some point i.e in 2012yr, the number of cars is nearly the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JBIWEiWC0nr4gr8P4vHGGA.jpeg" /><figcaption>Graph showing how the price varies per year</figcaption></figure><p>6From figure 5, we can analyze that the price of the cars also depends upon the condition of the car, and from figure 6, price varies with the condition of the cars with there size also.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MJrzsqYvonlwCKQfyICkKg.jpeg" /><figcaption>Bar Plot showing the price respective of the condition of the car</figcaption></figure><p>7From figure 7–8, we analyze that price of the cars also various each <strong>transmission</strong> of a car. People are ready to buy the car having “other transmission” and the price of the cars having “manual transmission” is low.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C_9omSXvuIkgC8EBGN-A9Q.jpeg" /><figcaption>Bar Plot showing the price with respective of transmission (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p>8 Below there are similar graphs with the same insight but different features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xpF9jB6QVtjN7625o7mSAw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gxm7kSHaGzG5o3u3LKiGCw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vxVVzH4mRffiV_1qA1ynMA.jpeg" /></figure><h3>Conclusion:</h3><p>By performing different ML models, we aim to get a better result or less error with max accuracy. Our purpose was to predict the price of the used cars having 25 predictors and 509577 data entries.</p><p>Initially, data cleaning is performed to remove the null values and outliers from the dataset then ML models are implemented to predict the price of cars.</p><p>Next, with the help of data visualization features were explored deeply. The relation between the features is examined.</p><p>From the below table, it can be concluded that XGBoost is the best model for the prediction for used car prices. XGBoost as a regression model gave the best MSLE and RMSLE values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*z81UsHSR2SkVrRsDnzyWrw.png" /><figcaption>Accuracy Table (Image By <a href="https://www.linkedin.com/in/abhash-panwar-85126976/">Panwar Abhash Anil</a>)</figcaption></figure><p>That’s all! If you got this far, thank you for reading. Any feedback is appreciated! and can be reached on <a href="https://www.linkedin.com/in/panwar-abhash-anil/"><em>Linkedin</em></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3be02d977b2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/used-car-price-prediction-using-machine-learning-e3be02d977b2">Used Car Price Prediction using Machine Learning</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>