<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>ISLR on Amit Rajan</title><link>https://amitrajan012.github.io/topics/islr/</link><description>Recent content in ISLR on Amit Rajan</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Thu, 19 Jul 2018 06:25:52 +0100</lastBuildDate><atom:link href="https://amitrajan012.github.io/topics/islr/index.xml" rel="self" type="application/rss+xml"/><item><title>Unsupervised Learning: Applied Exercises</title><link>https://amitrajan012.github.io/post/unsupervised-learning_part6/</link><pubDate>Thu, 19 Jul 2018 06:25:52 +0100</pubDate><guid>https://amitrajan012.github.io/post/unsupervised-learning_part6/</guid><description>&lt;h4 id="applied"&gt;Applied&lt;/h4&gt;&#10;&lt;p&gt;Q7. In the chapter, we mentioned the use of correlation-based distance and Euclidean distance as dissimilarity measures for hierarchical clustering. It turns out that these two measures are almost equivalent: if each observation has been centered to have mean zero and standard deviation one, and if we let \(r_{ij}\) denote the correlation between the ith and jth observations, then the quantity \(1−r _{ij}\) is proportional to the squared Euclidean distance between the ith and jth observations. On the USArrests data, show that this proportionality holds.&lt;/p&gt;</description></item><item><title>Unsupervised Learning: Conceptual Exercises</title><link>https://amitrajan012.github.io/post/unsupervised-learning_part5/</link><pubDate>Sun, 15 Jul 2018 03:51:27 +0100</pubDate><guid>https://amitrajan012.github.io/post/unsupervised-learning_part5/</guid><description>&lt;h3 id="107-exercises"&gt;10.7 Exercises&lt;/h3&gt;&#10;&lt;h4 id="conceptual"&gt;Conceptual&lt;/h4&gt;&#10;&lt;p&gt;Q1. This problem involves the K-means clustering algorithm.&lt;/p&gt;&#10;&lt;p&gt;(a) Prove (10.12).&lt;/p&gt;&#10;&lt;p&gt;&lt;b&gt;Sol:&lt;/b&gt; Equation 10.12 is:&lt;/p&gt;&#10;\[\frac{1}{|C_k|} \sum _{i, i^{&amp;#39;} \in C_k} \sum _{j=1}^{p} (x _{ij} - x _{i^{&amp;#39;}j})^2 =&#10;2\sum _{i \in C_k} \sum _{j=1}^{p} (x _{ij} - \bar{x} _{kj})^2\]&lt;p&gt;where \(\bar{x} _{kj} = \frac{1}{|C_k|} \sum _{i \in C_k} x _{ij}\), is the mean of feature \(j\) in cluster \(C_k\). Expanding LHS, we get&lt;/p&gt;&#10;\[\frac{1}{|C_k|} \sum _{i, i^{&amp;#39;} \in C_k} \sum _{j=1}^{p} (x _{ij} - x _{i^{&amp;#39;}j})^2 =&#10;\frac{1}{|C_k|} \sum _{i, i^{&amp;#39;} \in C_k} \sum _{j=1}^{p} x _{ij}^2 &amp;#43; \frac{1}{|C_k|} \sum _{i, i^{&amp;#39;} \in C_k} \sum _{j=1}^{p} x _{i^{&amp;#39;}j}^2 - \frac{2}{|C_k|} \sum _{i, i^{&amp;#39;} \in C_k} \sum _{j=1}^{p} x _{ij}x _{i^{&amp;#39;}j} \\ = 2 \sum _{i \in C_k} \sum _{j=1}^{p} x _{ij}^2 - \frac{2}{|C_k|} \sum _{i, i^{&amp;#39;} \in C_k} \sum _{j=1}^{p} x _{ij}x _{i^{&amp;#39;}j} \]&lt;p&gt;Expanding RHS and substituting the value of \(\bar{x} _{kj}\), we get&lt;/p&gt;</description></item><item><title>Hierarchical Clustering</title><link>https://amitrajan012.github.io/post/unsupervised-learning_part4/</link><pubDate>Thu, 12 Jul 2018 13:01:01 +0100</pubDate><guid>https://amitrajan012.github.io/post/unsupervised-learning_part4/</guid><description>&lt;h4 id="1032-hierarchical-clustering"&gt;10.3.2 Hierarchical Clustering&lt;/h4&gt;&#10;&lt;p&gt;K-means clustering has a disadvantage that there is a need to pre-specify the number of clusters \(K\). Hierarchical clutsring is an alternative approach which is free from this problem which results in an altarnative tree-based representation of the observations, called as &lt;b&gt;dendrogram&lt;/b&gt;.&lt;/p&gt;&#10;&lt;p&gt;The most common technique used for hierarchical clustering is &lt;b&gt;bottom-up&lt;/b&gt; or &lt;b&gt;agglomerative&lt;/b&gt; clustering. It is based on the fact that the dendrogram (generally depicted as an upside-down tree) is built starting from leaves and combining the clusters up to the trunk.&lt;/p&gt;</description></item><item><title>K-Means Clustering</title><link>https://amitrajan012.github.io/post/unsupervised-learning_part3/</link><pubDate>Mon, 09 Jul 2018 17:09:41 +0100</pubDate><guid>https://amitrajan012.github.io/post/unsupervised-learning_part3/</guid><description>&lt;h3 id="103-clustering-methods"&gt;10.3 Clustering Methods&lt;/h3&gt;&#10;&lt;p&gt;&lt;b&gt;Clustering&lt;/b&gt; is a technique for finding &lt;b&gt;subgroups&lt;/b&gt; or &lt;b&gt;clusters&lt;/b&gt; in a data set based on similarity between individual observations. For clustering, we need to define the measure of similarity which depends on the knowledge of the data set. Two best known clustering methods are &lt;b&gt;K-means clustering&lt;/b&gt; and &lt;b&gt;hierarchical clustering&lt;/b&gt;. In K-means clustering, we partition the observations into a pre-defined number of clusters. In hierarchical clustering, the number of clusters is unknown and the results of clustering is represented as a &lt;b&gt;dendrogram&lt;/b&gt;, which is a tree-like visualization technique that allows us to view the clustering results for various number of clusters (from 1 to \(n\)).&lt;/p&gt;</description></item><item><title>Principal Components Analysis: More on PCA</title><link>https://amitrajan012.github.io/post/unsupervised-learning_part2/</link><pubDate>Fri, 06 Jul 2018 01:19:52 +0100</pubDate><guid>https://amitrajan012.github.io/post/unsupervised-learning_part2/</guid><description>&lt;h4 id="1023-more-on-pca"&gt;10.2.3 More on PCA&lt;/h4&gt;&#10;&lt;h5 id="scaling-the-variables"&gt;Scaling the Variables&lt;/h5&gt;&#10;&lt;p&gt;The results of PCA also depend on the fact that whether &lt;b&gt;the variables are individually scaled or not&lt;/b&gt;. If we perform PCA on the unscaled variables, the variables with higher variance will have very &lt;b&gt;large loading&lt;/b&gt;. As it is undesirable for the principal components obtained to depend on the scale of the variables, we scale each variables to have the &lt;b&gt;standard deviation 1&lt;/b&gt; before performing PCA. If the individual variables are measured in the same unit, the scaling need not to be done.&lt;/p&gt;</description></item><item><title>Principal Components Analysis</title><link>https://amitrajan012.github.io/post/unsupervised-learning_part1/</link><pubDate>Wed, 04 Jul 2018 03:09:02 +0100</pubDate><guid>https://amitrajan012.github.io/post/unsupervised-learning_part1/</guid><description>&lt;h1&gt;&lt;center&gt;Unsupervised Learning&lt;/center&gt;&lt;/h1&gt;&#10;&lt;h3 id="101-the-challenge-of-unsupervised-learning"&gt;10.1 The Challenge of Unsupervised Learning&lt;/h3&gt;&#10;&lt;p&gt;&lt;b&gt;Unsupervised learning&lt;/b&gt; is often performed as a a part of an &lt;b&gt;exploratory data analysis&lt;/b&gt;. In unsupervised learning there is no practical way to assess the performance of the model as we do not have the true answer.&lt;/p&gt;&#10;&lt;h3 id="102-principal-components-analysis"&gt;10.2 Principal Components Analysis&lt;/h3&gt;&#10;&lt;p&gt;In the case of a large set of correlated variables, principal component analysis helps in summarizing the data set with a small number of representative variables that explains most of the variability in the data. The principal component directions are the directions in the feature space along which the original data is &lt;b&gt;highly variable&lt;/b&gt;. &lt;b&gt;Principal component analysis (PCA)&lt;/b&gt; refers to the process by which principal components are computed.&lt;/p&gt;</description></item><item><title>Support Vector Machines: Applied Exercises</title><link>https://amitrajan012.github.io/post/support-vector-machines_part5/</link><pubDate>Fri, 29 Jun 2018 06:19:12 +0100</pubDate><guid>https://amitrajan012.github.io/post/support-vector-machines_part5/</guid><description>&lt;h4 id="applied"&gt;Applied&lt;/h4&gt;&#10;&lt;p&gt;Q4. Generate a simulated two-class data set with 100 observations and two features in which there is a visible but non-linear separation between the two classes. Show that in this setting, a support vector machine with a polynomial kernel (with degree greater than 1) or a radial kernel will outperform a support vector classifier on the training&#10;data. Which technique performs best on the test data? Make plots and report training and test error rates in order to back up your assertions.&lt;/p&gt;</description></item><item><title>Support Vector Machines: Conceptual Exercises</title><link>https://amitrajan012.github.io/post/support-vector-machines_part4/</link><pubDate>Tue, 26 Jun 2018 03:29:17 +0100</pubDate><guid>https://amitrajan012.github.io/post/support-vector-machines_part4/</guid><description>&lt;h3 id="97-exercises"&gt;9.7 Exercises&lt;/h3&gt;&#10;&lt;h4 id="conceptual"&gt;Conceptual&lt;/h4&gt;&#10;&lt;p&gt;Q1. This problem involves hyperplanes in two dimensions.&lt;/p&gt;&#10;&lt;p&gt;(a) Sketch the hyperplane 1 + 3X1 − X2 = 0. Indicate the set of points for which 1 + 3X1 − X2 &amp;gt; 0, as well as the set of points for which 1 + 3X1 − X2 &amp;lt; 0.&lt;/p&gt;&#10;&lt;p&gt;(b) On the same plot, sketch the hyperplane −2 + X1 + 2X2 = 0. Indicate the set of points for which −2+ X1 +2X2 &amp;gt; 0, as well as the set of points for which −2+ X1 + 2X2 &amp;lt; 0.&lt;/p&gt;</description></item><item><title>Support Vector Machines and Kernels</title><link>https://amitrajan012.github.io/post/support-vector-machines_part3/</link><pubDate>Sat, 23 Jun 2018 04:19:37 +0100</pubDate><guid>https://amitrajan012.github.io/post/support-vector-machines_part3/</guid><description>&lt;h3 id="93-support-vector-machines"&gt;9.3 Support Vector Machines&lt;/h3&gt;&#10;&lt;h4 id="931-classification-with-non-linear-decision-boundaries"&gt;9.3.1 Classification with Non-linear Decision Boundaries&lt;/h4&gt;&#10;&lt;p&gt;Support vector classifiers, which are designed to work in the setting of linear decision boundary, can be extended to handle the case of non-linear decision boundary by enlarging the feature space using polynomial transformation of the predictors. For example, if we have a \(p\)-dimensional feature space given as: \(X_1, X_2, ..., X_p\), we could instead fit a support vector classifier using \(2p\) features: \(X_1, X_1^2, X_2, X_2^2, ..., X_p, X_p^2\). In the transformed feature space, the decision boundary is still linear, but if we consider the original feature space, the decison boundary will be non-linear. There are many ways to enlarge the feature space, such as using higher order polynomials or using interaction terms.&lt;/p&gt;</description></item><item><title>Support Vector Classifiers</title><link>https://amitrajan012.github.io/post/support-vector-machines_part2/</link><pubDate>Wed, 20 Jun 2018 02:24:24 +0100</pubDate><guid>https://amitrajan012.github.io/post/support-vector-machines_part2/</guid><description>&lt;h3 id="92-support-vector-classifiers"&gt;9.2 Support Vector Classifiers&lt;/h3&gt;&#10;&lt;h4 id="921-overview-of-the-support-vector-classifier"&gt;9.2.1 Overview of the Support Vector Classifier&lt;/h4&gt;&#10;&lt;p&gt;The maximal margin classifiers can be sensitive to individual observations. Sometimes, adding a single observation in the data set, can lead to dramatic change in the separating hyperplane. The sensitivity and the low margin for a maximal margin classifier may suggest that the maximal margin classifier has &lt;b&gt;overfit&lt;/b&gt; the training data. So, sometimes we may be willing to consider a classifier based on a hyperplane that does not perfectly separate the two classes, and hence, will be &lt;b&gt;more robust (or less sensitive to individual observations)&lt;/b&gt; and will give better results for the unseen data points.&lt;/p&gt;</description></item><item><title>Maximal Margin Classifier</title><link>https://amitrajan012.github.io/post/support-vector-machines_part1/</link><pubDate>Tue, 19 Jun 2018 12:14:23 +0100</pubDate><guid>https://amitrajan012.github.io/post/support-vector-machines_part1/</guid><description>&lt;h1&gt;&lt;center&gt;Support Vector Machines&lt;/center&gt;&lt;/h1&gt;&#10;&lt;p&gt;&lt;b&gt;Support vector machine&lt;/b&gt; is a generalization of a simple and intutive classifier called the &lt;b&gt;maximal margin classifier&lt;/b&gt;. Maximal margin classifier has a limitation that it can be only applied to a data set whose classes are seperated by a linaer boundary.&lt;/p&gt;&#10;&lt;h3 id="91-maximal-margin-classifier"&gt;9.1 Maximal Margin Classifier&lt;/h3&gt;&#10;&lt;h4 id="911-what-is-a-hyperplane"&gt;9.1.1 What Is a Hyperplane?&lt;/h4&gt;&#10;&lt;p&gt;In a \(p\)-dimensional space, a &lt;b&gt;hyperplane&lt;/b&gt; is a flat affine subspace of \(p-1\) dimensions. In two dimensions, the hyperplane is a line and can be given as:&lt;/p&gt;</description></item><item><title>Tree-Based Methods: Applied Exercises</title><link>https://amitrajan012.github.io/post/tree-based-methods_part4/</link><pubDate>Sat, 16 Jun 2018 01:34:53 +0100</pubDate><guid>https://amitrajan012.github.io/post/tree-based-methods_part4/</guid><description>&lt;h4 id="applied"&gt;Applied&lt;/h4&gt;&#10;&lt;p&gt;Q 7. In the lab, we applied random forests to the Boston data using mtry=6 and using ntree=25 and ntree=500. Create a plot displaying the test error resulting from random forests on this data set for a more comprehensive range of values for mtry and ntree. You can model your plot after Figure 8.10. Describe the results obtained.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; pandas &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; pd&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;from&lt;/span&gt; sklearn.ensemble &lt;span style="color:#f92672"&gt;import&lt;/span&gt; RandomForestRegressor&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;from&lt;/span&gt; sklearn.metrics &lt;span style="color:#f92672"&gt;import&lt;/span&gt; mean_squared_error&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;from&lt;/span&gt; sklearn.model_selection &lt;span style="color:#f92672"&gt;import&lt;/span&gt; train_test_split&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;from&lt;/span&gt; math &lt;span style="color:#f92672"&gt;import&lt;/span&gt; sqrt&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;boston &lt;span style="color:#f92672"&gt;=&lt;/span&gt; pd&lt;span style="color:#f92672"&gt;.&lt;/span&gt;read_csv(&lt;span style="color:#e6db74"&gt;&amp;#34;data/Boston.csv&amp;#34;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;boston&lt;span style="color:#f92672"&gt;.&lt;/span&gt;dropna(inplace&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;True&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;def&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;random_forest_ntree&lt;/span&gt;(X_train, Y_train, X_test, Y_test, nTrees, max_feature):&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; test_MSE &lt;span style="color:#f92672"&gt;=&lt;/span&gt; {}&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; nTree &lt;span style="color:#f92672"&gt;in&lt;/span&gt; nTrees:&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; regr &lt;span style="color:#f92672"&gt;=&lt;/span&gt; RandomForestRegressor(max_features&lt;span style="color:#f92672"&gt;=&lt;/span&gt;max_feature, n_estimators&lt;span style="color:#f92672"&gt;=&lt;/span&gt;nTree)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; regr&lt;span style="color:#f92672"&gt;.&lt;/span&gt;fit(X_train, Y_train)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; p &lt;span style="color:#f92672"&gt;=&lt;/span&gt; regr&lt;span style="color:#f92672"&gt;.&lt;/span&gt;predict(X_test)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; test_MSE[nTree] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; mean_squared_error(p, Y_test)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; test_MSE&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;np&lt;span style="color:#f92672"&gt;.&lt;/span&gt;random&lt;span style="color:#f92672"&gt;.&lt;/span&gt;seed(&lt;span style="color:#ae81ff"&gt;5&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;predictors &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;13&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;X_train, X_test, y_train, y_test &lt;span style="color:#f92672"&gt;=&lt;/span&gt; train_test_split(boston&lt;span style="color:#f92672"&gt;.&lt;/span&gt;loc[:, boston&lt;span style="color:#f92672"&gt;.&lt;/span&gt;columns &lt;span style="color:#f92672"&gt;!=&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#39;medv&amp;#39;&lt;/span&gt;],&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; boston[[&lt;span style="color:#e6db74"&gt;&amp;#39;medv&amp;#39;&lt;/span&gt;]], test_size&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;0.1&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;test_MSE_p &lt;span style="color:#f92672"&gt;=&lt;/span&gt; random_forest_ntree(X_train, y_train&lt;span style="color:#f92672"&gt;.&lt;/span&gt;values&lt;span style="color:#f92672"&gt;.&lt;/span&gt;ravel(), X_test, y_test&lt;span style="color:#f92672"&gt;.&lt;/span&gt;values&lt;span style="color:#f92672"&gt;.&lt;/span&gt;ravel(), np&lt;span style="color:#f92672"&gt;.&lt;/span&gt;arange(&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;300&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;5&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; , predictors)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;test_MSE_pby2 &lt;span style="color:#f92672"&gt;=&lt;/span&gt; random_forest_ntree(X_train, y_train&lt;span style="color:#f92672"&gt;.&lt;/span&gt;values&lt;span style="color:#f92672"&gt;.&lt;/span&gt;ravel(), X_test, y_test&lt;span style="color:#f92672"&gt;.&lt;/span&gt;values&lt;span style="color:#f92672"&gt;.&lt;/span&gt;ravel(), np&lt;span style="color:#f92672"&gt;.&lt;/span&gt;arange(&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;300&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;5&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; , int(predictors&lt;span style="color:#f92672"&gt;/&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;2&lt;/span&gt;))&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;test_MSE_psqrt &lt;span style="color:#f92672"&gt;=&lt;/span&gt; random_forest_ntree(X_train, y_train&lt;span style="color:#f92672"&gt;.&lt;/span&gt;values&lt;span style="color:#f92672"&gt;.&lt;/span&gt;ravel(), X_test, y_test&lt;span style="color:#f92672"&gt;.&lt;/span&gt;values&lt;span style="color:#f92672"&gt;.&lt;/span&gt;ravel(), np&lt;span style="color:#f92672"&gt;.&lt;/span&gt;arange(&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;300&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;5&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; , int(sqrt(predictors)))&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;fig &lt;span style="color:#f92672"&gt;=&lt;/span&gt; plt&lt;span style="color:#f92672"&gt;.&lt;/span&gt;figure(figsize&lt;span style="color:#f92672"&gt;=&lt;/span&gt;(&lt;span style="color:#ae81ff"&gt;15&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;8&lt;/span&gt;))&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax &lt;span style="color:#f92672"&gt;=&lt;/span&gt; fig&lt;span style="color:#f92672"&gt;.&lt;/span&gt;add_subplot(&lt;span style="color:#ae81ff"&gt;111&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;lists &lt;span style="color:#f92672"&gt;=&lt;/span&gt; sorted(test_MSE_p&lt;span style="color:#f92672"&gt;.&lt;/span&gt;items())&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;x, y &lt;span style="color:#f92672"&gt;=&lt;/span&gt; zip(&lt;span style="color:#f92672"&gt;*&lt;/span&gt;lists)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;plt&lt;span style="color:#f92672"&gt;.&lt;/span&gt;plot(x, y, color&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#39;r&amp;#39;&lt;/span&gt;, label&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#39;m = p&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;lists &lt;span style="color:#f92672"&gt;=&lt;/span&gt; sorted(test_MSE_pby2&lt;span style="color:#f92672"&gt;.&lt;/span&gt;items())&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;x, y &lt;span style="color:#f92672"&gt;=&lt;/span&gt; zip(&lt;span style="color:#f92672"&gt;*&lt;/span&gt;lists)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;plt&lt;span style="color:#f92672"&gt;.&lt;/span&gt;plot(x, y, color&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#39;g&amp;#39;&lt;/span&gt;, label&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#39;m = p/2&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;lists &lt;span style="color:#f92672"&gt;=&lt;/span&gt; sorted(test_MSE_psqrt&lt;span style="color:#f92672"&gt;.&lt;/span&gt;items())&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;x, y &lt;span style="color:#f92672"&gt;=&lt;/span&gt; zip(&lt;span style="color:#f92672"&gt;*&lt;/span&gt;lists)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;plt&lt;span style="color:#f92672"&gt;.&lt;/span&gt;plot(x, y, color&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#39;b&amp;#39;&lt;/span&gt;, label&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#39;m = sqrt(p)&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_xlabel(&lt;span style="color:#e6db74"&gt;&amp;#39;Number of Trees&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_ylabel(&lt;span style="color:#e6db74"&gt;&amp;#39;Test MSE&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_title(&lt;span style="color:#e6db74"&gt;&amp;#39;Test MSE vs Number of Trees&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;plt&lt;span style="color:#f92672"&gt;.&lt;/span&gt;grid(b&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;True&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;plt&lt;span style="color:#f92672"&gt;.&lt;/span&gt;legend()&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;plt&lt;span style="color:#f92672"&gt;.&lt;/span&gt;show()&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figure class="fig"&gt;&lt;img src="https://amitrajan012.github.io/img/Tree-Based%20Methods_files/Tree-Based%20Methods_10_0.png" alt="" loading="lazy"&gt;&lt;/figure&gt;&#10;&lt;p&gt;Q 8. In the lab, a classification tree was applied to the Carseats data set after converting Sales into a qualitative response variable. Now we will seek to predict Sales using regression trees and related approaches, treating the response as a quantitative variable.&lt;/p&gt;</description></item><item><title>Tree-Based Methods: Conceptual Exercises</title><link>https://amitrajan012.github.io/post/tree-based-methods_part3/</link><pubDate>Thu, 14 Jun 2018 07:14:13 +0100</pubDate><guid>https://amitrajan012.github.io/post/tree-based-methods_part3/</guid><description>&lt;h3 id="84-exercises"&gt;8.4 Exercises&lt;/h3&gt;&#10;&lt;h4 id="conceptual"&gt;Conceptual&lt;/h4&gt;&#10;&lt;p&gt;Q2. It is mentioned in Section 8.2.3 that boosting using depth-one trees (or stumps) leads to an additive model: that is, a model of the form&lt;/p&gt;&#10;\[f(X) = \sum_{j=1}^{p} f_j(X_j)\]&lt;p&gt;Explain why this is the case. You can begin with (8.12) in Algorithm 8.2.&lt;/p&gt;&#10;&lt;p&gt;&lt;b&gt;Sol:&lt;/b&gt; As for depth-one trees, value of \(d\) is 1. Each tree is generated by splitting the data on only one predictor and the final model is formed by adding the shrunken version of them repeatedly. Hence, in the final model:&lt;/p&gt;</description></item><item><title>Bagging, Random Forests, Boosting</title><link>https://amitrajan012.github.io/post/tree-based-methods_part2/</link><pubDate>Wed, 13 Jun 2018 13:04:28 +0100</pubDate><guid>https://amitrajan012.github.io/post/tree-based-methods_part2/</guid><description>&lt;h3 id="82-bagging-random-forests-boosting"&gt;8.2 Bagging, Random Forests, Boosting&lt;/h3&gt;&#10;&lt;h4 id="821-bagging"&gt;8.2.1 Bagging&lt;/h4&gt;&#10;&lt;p&gt;The decision trees discussed above suffers from a problem of &lt;b&gt;high variance&lt;/b&gt;. &lt;b&gt;Bootstrap aggregation&lt;/b&gt; or &lt;b&gt;bagging&lt;/b&gt; is a procedure that reduces the variance of a statistical learning method.&lt;/p&gt;&#10;&lt;p&gt;Give a set of \(n\) independent observation sets \(Z_1, Z_2, ..., Z_n\), each with variance \(\sigma^2\), the variance of the mean \(\bar{Z}\) is given by \(\sigma^2/n\), i.e. &lt;b&gt;averaging a set of observations reduces variance&lt;/b&gt;. Hence, a natural way to reduce the variance of a statistical model is to take many training samples from the population, fit individual models on them, and give the average of them as the final model. Hence, we can calculate \(\widehat{f}^1(x), \widehat{f}^2(x), ..., \widehat{f}^B(x)\) using \(B\) seperate training sets, and finally obtain the low variance statistical model as:&lt;/p&gt;</description></item><item><title>Decision Trees</title><link>https://amitrajan012.github.io/post/tree-based-methods_part1/</link><pubDate>Mon, 11 Jun 2018 17:07:13 +0100</pubDate><guid>https://amitrajan012.github.io/post/tree-based-methods_part1/</guid><description>&lt;h1&gt;&lt;center&gt;Tree-Based Methods&lt;/center&gt;&lt;/h1&gt;&#10;&lt;p&gt;&lt;b&gt;Tree-based&lt;/b&gt; methods &lt;b&gt;stratify&lt;/b&gt; or &lt;b&gt;segment&lt;/b&gt; the predictor space into a number of simple regions. To make a prediction, we use the &lt;b&gt;mean&lt;/b&gt; or the &lt;b&gt;mode&lt;/b&gt; of the training observations in the region in which the observation to be predicted belongs. The set of splitting rules can be summarized via a tree, these methods are also known as &lt;b&gt;decision tree&lt;/b&gt; methods. &lt;b&gt;Bagging, random forests&lt;/b&gt; and &lt;b&gt;boosting&lt;/b&gt; produce multiple trees and then combine them in a single model to make the prediction. They provide improved accuracy at the cost of interpretability.&lt;/p&gt;</description></item><item><title>Moving Beyond Linearity: Applied Exercises</title><link>https://amitrajan012.github.io/post/moving-beyond-linearity_part6/</link><pubDate>Fri, 08 Jun 2018 03:17:36 +0100</pubDate><guid>https://amitrajan012.github.io/post/moving-beyond-linearity_part6/</guid><description>&lt;h4 id="applied"&gt;Applied&lt;/h4&gt;&#10;&lt;p&gt;Q6. In this exercise, you will further analyze the Wage data set considered throughout this chapter.&lt;/p&gt;&#10;&lt;p&gt;(a) Perform polynomial regression to predict wage using age. Use cross-validation to select the optimal degree d for the polynomial. What degree was chosen, and how does this compare to the results of hypothesis testing using ANOVA? Make a plot of the resulting polynomial fit to the data.&lt;/p&gt;&#10;&lt;p&gt;&lt;b&gt;Sol:&lt;/b&gt; The optimal degree of polynomial selected from cross-validation is &lt;b&gt;4&lt;/b&gt;. From the ANOVA of models of degree 1 to 5, it is found that the models of degree 2 and 3 are significant. The test MSE shows the lowest value for degree 3 model as well.&lt;/p&gt;</description></item><item><title>Moving Beyond Linearity: Conceptual Exercises</title><link>https://amitrajan012.github.io/post/moving-beyond-linearity_part5/</link><pubDate>Wed, 06 Jun 2018 06:27:22 +0100</pubDate><guid>https://amitrajan012.github.io/post/moving-beyond-linearity_part5/</guid><description>&lt;h3 id="79-exercises"&gt;7.9 Exercises&lt;/h3&gt;&#10;&lt;h4 id="conceptual"&gt;Conceptual&lt;/h4&gt;&#10;&lt;p&gt;Q1. It was mentioned in the chapter that a cubic regression spline with one knot at ξ can be obtained using a basis of the form \(x, x^2, x^3, (x − ξ)^3 _&amp;#43;\), where \((x − ξ)^3 _&amp;#43; = (x − ξ)^3\) if x &amp;gt; ξ and equals 0 otherwise.&#10;We will now show that a function of the form \(f(x) = β_0 &amp;#43; β_1x &amp;#43; β_2x^2 &amp;#43; β_3x^3 &amp;#43; β_4(x − ξ)^3 _&amp;#43;\) is indeed a cubic regression spline, regardless of the values of \(β_0, β_1, β_2, β_3, β_4\).&lt;/p&gt;</description></item><item><title>Local Regression, Generalized Additive Models</title><link>https://amitrajan012.github.io/post/moving-beyond-linearity_part4/</link><pubDate>Mon, 04 Jun 2018 16:12:19 +0100</pubDate><guid>https://amitrajan012.github.io/post/moving-beyond-linearity_part4/</guid><description>&lt;h3 id="76-local-regression"&gt;7.6 Local Regression&lt;/h3&gt;&#10;&lt;p&gt;&lt;b&gt;Local regression&lt;/b&gt; comutes the fit at a target point \(x_0\) using only the nearby training observstions. The algorithm for local regression is as follows:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Gather the \(k\) points closest to \(x_0\).&lt;/li&gt;&#10;&lt;li&gt;Assign a weight \(K_{i0} = K(x_i, x_0)\) to all the points in the neighborhood such that the points that are farthest have lower weights. All the points except from these \(k\) nearest neighbors have weigth 0.&lt;/li&gt;&#10;&lt;li&gt;Fit a &lt;b&gt;weighted least squares regression&lt;/b&gt; of the aformentioned points using weights, by finding \(\beta_0, \beta_1\) that minimize&lt;/li&gt;&#10;&lt;/ul&gt;&#10;\[\sum _{i=1}^{n}K _{i0}(y_i - \beta_0 - \beta_1 x_i)^2\]&lt;ul&gt;&#10;&lt;li&gt;The fitted value at \(x_0\) is given as \(\widehat{f}(x_0) = \widehat{\beta_0} &amp;#43; \widehat{\beta_1} x_0\).&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;The &lt;b&gt;span s&lt;/b&gt; of a local regression is defined as \(s = \frac{k}{n}\), where \(n\) is total number of training samples. It plays the role of controling the flexibility of the non-linera fit. Smaller the value of \(s\), the more local or wiggly is the fit. For larger values of \(s\), we obtain a global fit. An appropriate value of \(s\) can be chosen by cross-validation.&lt;/p&gt;</description></item><item><title>Smoothing Splines</title><link>https://amitrajan012.github.io/post/moving-beyond-linearity_part3/</link><pubDate>Wed, 30 May 2018 06:02:06 +0100</pubDate><guid>https://amitrajan012.github.io/post/moving-beyond-linearity_part3/</guid><description>&lt;h3 id="75-smoothing-splines"&gt;7.5 Smoothing Splines&lt;/h3&gt;&#10;&lt;h4 id="751-an-overview-of-smoothing-splines"&gt;7.5.1 An Overview of Smoothing Splines&lt;/h4&gt;&#10;&lt;p&gt;Regression splines are created by specifying a set of knots, producing a sequence of basis functions and then estimate spline coefficients using least squares.&lt;/p&gt;&#10;&lt;p&gt;To fit a smooth curve to a data set, we need to find a function \(g(x)\) such that \(RSS = \sum_{i=1}^{n}(y_i - g(x_i))^2\) is minimum. If we do not put any constraint on \(g(x)\), we can always find a function \(g(x)\), which will make RSS 0. This function will be too flexible and will overfit the data. Hence, we need to find a function \(g\) which makes RSS small and which is &lt;b&gt;smooth&lt;/b&gt; as well.&lt;/p&gt;</description></item><item><title>Regression Splines</title><link>https://amitrajan012.github.io/post/moving-beyond-linearity_part2/</link><pubDate>Mon, 28 May 2018 11:12:18 +0100</pubDate><guid>https://amitrajan012.github.io/post/moving-beyond-linearity_part2/</guid><description>&lt;h3 id="74-regression-splines"&gt;7.4 Regression Splines&lt;/h3&gt;&#10;&lt;p&gt;Regression splines are flixible class of basis functions that extend upon polynomial and piecewise constant regression approaches.&lt;/p&gt;&#10;&lt;h4 id="741-piecewise-polynomials"&gt;7.4.1 Piecewise Polynomials&lt;/h4&gt;&#10;&lt;p&gt;&lt;b&gt;Piecewise polynomial regression&lt;/b&gt; fits separate low-degree polynomials over different regions of \(X\). For example, a piecewise squared polynomial fits squared regression model of the form&lt;/p&gt;&#10;\[y_i = \beta_0 &amp;#43; \beta_1 x_i &amp;#43; \beta_2 x_i^2 &amp;#43; \epsilon_i\]&lt;p&gt;where the coefficients \(\beta_0, \beta_1, \beta_2\) differs in different parts of the range of \(X\). The points where the coefficients change are called &lt;b&gt;knots&lt;/b&gt;. Each of the polynomial functions can be fit using least square methods. Increasing the number of knots will give a more flexible piecewise polynomial.&lt;/p&gt;</description></item><item><title>Polynomial Regression, Step Functions, Basis Functions</title><link>https://amitrajan012.github.io/post/moving-beyond-linearity_part1/</link><pubDate>Mon, 28 May 2018 04:22:38 +0100</pubDate><guid>https://amitrajan012.github.io/post/moving-beyond-linearity_part1/</guid><description>&lt;h1&gt;&lt;center&gt;Moving Beyond Linearity&lt;/center&gt;&lt;/h1&gt;&#10;&lt;p&gt;Lineaer models have its limitations in terms of predictive power. Linear models can be extended simply as:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;&lt;b&gt;Polynomial regression&lt;/b&gt; extends linear regression by adding extra higher order predictors (predictors rasied to higher order powers).&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;&lt;b&gt;Step functions&lt;/b&gt; cut the range of a variable into \(K\) distinct regions in order to produce a qualitative variable.&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;&lt;b&gt;Regression splines&lt;/b&gt; is the extension of polynomial regression and step functions. It divides the range of predictor \(X\) into \(K\) distinct regions and within each region a polynomial function is fit to the data.&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;&lt;b&gt;Smoothing splines&lt;/b&gt;&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;&lt;b&gt;Local regression&lt;/b&gt;&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;&lt;b&gt;Generalized additive models&lt;/b&gt;&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;</description></item><item><title>Linear Model Selection and Regularization: Applied Exercises</title><link>https://amitrajan012.github.io/post/linear-model-selection-and-regularization_part5/</link><pubDate>Sat, 26 May 2018 11:08:14 +0100</pubDate><guid>https://amitrajan012.github.io/post/linear-model-selection-and-regularization_part5/</guid><description>&lt;h4 id="applied"&gt;Applied&lt;/h4&gt;&#10;&lt;p&gt;Q8. In this exercise, we will generate simulated data, and will then use this data to perform best subset selection.&lt;/p&gt;&#10;&lt;p&gt;(a) Use the rnorm() function to generate a predictor X of length n = 100, as well as a noise vector of length n = 100.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; numpy &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; np&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;np&lt;span style="color:#f92672"&gt;.&lt;/span&gt;random&lt;span style="color:#f92672"&gt;.&lt;/span&gt;seed(&lt;span style="color:#ae81ff"&gt;5&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;X &lt;span style="color:#f92672"&gt;=&lt;/span&gt; np&lt;span style="color:#f92672"&gt;.&lt;/span&gt;random&lt;span style="color:#f92672"&gt;.&lt;/span&gt;normal(&lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;100&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;e &lt;span style="color:#f92672"&gt;=&lt;/span&gt; np&lt;span style="color:#f92672"&gt;.&lt;/span&gt;random&lt;span style="color:#f92672"&gt;.&lt;/span&gt;normal(&lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;100&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;(b) Generate a response vector Y of length n = 100 according to the model \(Y = β_0 &amp;#43; β_1X &amp;#43; β_2X^2 &amp;#43; β_3X^3 &amp;#43; \epsilon\), where \(β_0, β_1, β_2,\) and \(β_3\) are constants of your choice.&lt;/p&gt;</description></item><item><title>Linear Model Selection and Regularization: Conceptual Exercises</title><link>https://amitrajan012.github.io/post/linear-model-selection-and-regularization_part4/</link><pubDate>Fri, 25 May 2018 06:18:38 +0100</pubDate><guid>https://amitrajan012.github.io/post/linear-model-selection-and-regularization_part4/</guid><description>&lt;h3 id="68-exercises"&gt;6.8 Exercises&lt;/h3&gt;&#10;&lt;h4 id="conceptual"&gt;Conceptual&lt;/h4&gt;&#10;&lt;p&gt;Q1. We perform best subset, forward stepwise, and backward stepwise selection on a single data set. For each approach, we obtain p + 1 models, containing 0, 1, 2, . . . , p predictors. Explain your answers:&lt;/p&gt;&#10;&lt;p&gt;(a) Which of the three models with k predictors has the smallest training RSS?&lt;/p&gt;&#10;&lt;p&gt;&lt;b&gt;Sol:&lt;/b&gt; Training RSS is minimum for best subset selection.&lt;/p&gt;&#10;&lt;p&gt;(b) Which of the three models with k predictors has the smallest test RSS?&lt;/p&gt;</description></item><item><title>Dimension Reduction Methods</title><link>https://amitrajan012.github.io/post/linear-model-selection-and-regularization_part3/</link><pubDate>Thu, 24 May 2018 01:06:16 +0100</pubDate><guid>https://amitrajan012.github.io/post/linear-model-selection-and-regularization_part3/</guid><description>&lt;h3 id="63-dimension-reduction-methods"&gt;6.3 Dimension Reduction Methods&lt;/h3&gt;&#10;&lt;p&gt;Instead of performing a least squares regression on all the \(p\) predictors, we can &lt;b&gt;transform&lt;/b&gt; the predictors and then fit a least squares model on the transformed variables. Let the transformed variables be \(Z_1, Z_2, ..., Z_M\), where \(M &amp;lt; p\), where each of \(Z_m\)s is a linear combination of predictors \(X_1, X_2, ..., X_p\).i.e.&lt;/p&gt;&#10;\[Z_m = \sum _{j=1}^{p} \phi _{jm}X_j\]&lt;p&gt;We can then fit the least squares regression model as \(Z_m\)s as the predictors:&lt;/p&gt;</description></item><item><title>Shrinkage Methods</title><link>https://amitrajan012.github.io/post/linear-model-selection-and-regularization_part2/</link><pubDate>Tue, 22 May 2018 21:16:20 +0100</pubDate><guid>https://amitrajan012.github.io/post/linear-model-selection-and-regularization_part2/</guid><description>&lt;h3 id="62-shrinkage-methods"&gt;6.2 Shrinkage Methods&lt;/h3&gt;&#10;&lt;p&gt;As an alternative to subset selection methods, a model containing all the &lt;b&gt;\(p\) predictors&lt;/b&gt; can be fit using a technique that &lt;b&gt;constrains&lt;/b&gt; or &lt;b&gt;regularizes&lt;/b&gt; the coefficient estimates (or &lt;b&gt;shrinks&lt;/b&gt; the coefficeint estimates towards 0). Two best known techniques for shrinking the coefficient estimates towards 0 are: &lt;b&gt;ridge regression&lt;/b&gt; and the &lt;b&gt;lasso&lt;/b&gt;.&lt;/p&gt;&#10;&lt;h4 id="621-ridge-regression"&gt;6.2.1 Ridge Regression&lt;/h4&gt;&#10;&lt;p&gt;In a least squares fitting, the parameters of the model is estimated by minimizing&lt;/p&gt;</description></item><item><title>Subset Selection</title><link>https://amitrajan012.github.io/post/linear-model-selection-and-regularization_part1/</link><pubDate>Mon, 21 May 2018 13:08:40 +0100</pubDate><guid>https://amitrajan012.github.io/post/linear-model-selection-and-regularization_part1/</guid><description>&lt;h1&gt;&lt;center&gt;Linear Model Selection and Regularization&lt;/center&gt;&lt;/h1&gt;&#10;&lt;p&gt;Befor moving to non-linear models, there are certain other fitting procedures through which a plain linear model can be improved. These alternate fitting procedures can yield better &lt;b&gt;prediction accuracy&lt;/b&gt; and &lt;b&gt;model interpretability&lt;/b&gt;.&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;&lt;b&gt;Prediction Accuracy:&lt;/b&gt; Provided that the relationship between predictors and response is linear, the &lt;b&gt;least square estimates will have low bias&lt;/b&gt;. If n &amp;raquo; p, this model will have low variance as well. If n is not much larger than p, the model will have a lot of variability, resulting in overfitting and poor prediction accuracy. If p &amp;gt; n, the variance is almost infinite and hence the plain least square method can not be used at all.&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;&lt;b&gt;Model Interpretability:&lt;/b&gt; There may be the case that some of the predictors used in the linear model are not significant. Including such &lt;b&gt;irrelevant variables&lt;/b&gt; may lead to unnecessary complexity in the model. These variables can be excluded from the model by &lt;b&gt;feature selection&lt;/b&gt; or &lt;b&gt;variable selection&lt;/b&gt; and hence a better model interpretability.&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;</description></item><item><title>Resampling Methods: Applied Exercises</title><link>https://amitrajan012.github.io/post/resampling-methods_part4/</link><pubDate>Sat, 19 May 2018 13:08:40 +0100</pubDate><guid>https://amitrajan012.github.io/post/resampling-methods_part4/</guid><description>&lt;h4 id="applied"&gt;Applied&lt;/h4&gt;&#10;&lt;p&gt;Q5. In Chapter 4, we used logistic regression to predict the probability of default using income and balance on the Default data set. We will now estimate the test error of this logistic regression model using the validation set approach. Do not forget to set a random seed before beginning your analysis.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; pandas &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; pd&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; seaborn &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; sns&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; matplotlib.pyplot &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; plt&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; numpy &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; np&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; statsmodels.api &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; sm&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;np&lt;span style="color:#f92672"&gt;.&lt;/span&gt;random&lt;span style="color:#f92672"&gt;.&lt;/span&gt;seed(&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;default &lt;span style="color:#f92672"&gt;=&lt;/span&gt; pd&lt;span style="color:#f92672"&gt;.&lt;/span&gt;read_excel(&lt;span style="color:#e6db74"&gt;&amp;#34;data/Default.xlsx&amp;#34;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;default[&lt;span style="color:#e6db74"&gt;&amp;#39;student&amp;#39;&lt;/span&gt;] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; default[&lt;span style="color:#e6db74"&gt;&amp;#39;student&amp;#39;&lt;/span&gt;]&lt;span style="color:#f92672"&gt;.&lt;/span&gt;map({&lt;span style="color:#e6db74"&gt;&amp;#39;Yes&amp;#39;&lt;/span&gt;: &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;No&amp;#39;&lt;/span&gt;: &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;})&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;default[&lt;span style="color:#e6db74"&gt;&amp;#39;default&amp;#39;&lt;/span&gt;] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; default[&lt;span style="color:#e6db74"&gt;&amp;#39;default&amp;#39;&lt;/span&gt;]&lt;span style="color:#f92672"&gt;.&lt;/span&gt;map({&lt;span style="color:#e6db74"&gt;&amp;#39;Yes&amp;#39;&lt;/span&gt;: &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;No&amp;#39;&lt;/span&gt;: &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;})&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;(a) Fit a logistic regression model that uses income and balance to predict default.&lt;/p&gt;</description></item><item><title>Resampling Methods: Conceptual Exercises</title><link>https://amitrajan012.github.io/post/resampling-methods_part3/</link><pubDate>Fri, 18 May 2018 07:18:30 +0100</pubDate><guid>https://amitrajan012.github.io/post/resampling-methods_part3/</guid><description>&lt;h3 id="54-exercises"&gt;5.4 Exercises&lt;/h3&gt;&#10;&lt;h4 id="conceptual"&gt;Conceptual&lt;/h4&gt;&#10;&lt;p&gt;Q1. Using basic statistical properties of the variance, as well as singlevariable calculus, derive that the value of \(\alpha\) which minimizes \(Var(\alpha X &amp;#43; (1 - \alpha) Y)\) is:&lt;/p&gt;&#10;\[\alpha = \frac{\sigma_Y^2 - \sigma _{XY}}{\sigma_X^2 &amp;#43; \sigma_Y^2 - 2\sigma _{XY}}\]&lt;p&gt;&lt;b&gt;Sol:&lt;/b&gt; As we know that \(Var(aX &amp;#43; bY) = a^2 Var(X) &amp;#43; b^2 Var(Y) &amp;#43; 2abCov(X, Y)\), the above quantity (that needs to be minimized) can be transformed as:&lt;/p&gt;</description></item><item><title>The Bootstrap</title><link>https://amitrajan012.github.io/post/resampling-methods_part2/</link><pubDate>Fri, 18 May 2018 02:26:28 +0100</pubDate><guid>https://amitrajan012.github.io/post/resampling-methods_part2/</guid><description>&lt;h3 id="52-the-bootstrap"&gt;5.2 The Bootstrap&lt;/h3&gt;&#10;&lt;p&gt;&lt;b&gt;Bootstrap&lt;/b&gt; can be used to to quantify the uncertainty associated with a given statistical model. For example, bootstrap can be used to estimate &lt;b&gt;standard errors (which measures the uncertainty)&lt;/b&gt; of the coefficients from a linear regression fit. Bootstrap can be applied to a wide range of statistical learning methods. The method of bootstrap is explained below via an example:&lt;/p&gt;&#10;&lt;p&gt;Suppose we wish to invest money in two financial assests which yield returns of \(X\) and \(Y\). We will invest fraction \(\alpha\) of our money in \(X\) and \(1-\alpha\) in \(Y\). As there is a variablility associated with these returns, we wish to choose \(\alpha\) which minimizes the total risk or variance of our investment. i.e. &lt;b&gt;We want to minimize \(Var(\alpha X &amp;#43; (1-\alpha) Y)\)&lt;/b&gt;. The value that minimizes this is given as:&lt;/p&gt;</description></item><item><title>Cross-Validation</title><link>https://amitrajan012.github.io/post/resampling-methods_part1/</link><pubDate>Thu, 17 May 2018 05:22:19 +0100</pubDate><guid>https://amitrajan012.github.io/post/resampling-methods_part1/</guid><description>&lt;h1&gt;&lt;center&gt;Resampling Methods&lt;/center&gt;&lt;/h1&gt;&#10;&lt;p&gt;&lt;b&gt;Resampling methods&lt;/b&gt; involve repeatedly drawing samples from training data and refitting a model on them. Resampling approaches can be computationally expensive. &lt;b&gt;Cross-validation&lt;/b&gt; and &lt;b&gt;bootstrap&lt;/b&gt; are two of the most commonly used resampling methods. Cross-validation can be used to estimate the test error rate associated with a given model in order to evaluate its performance. The process of evaluating a model&amp;rsquo;s performance is called &lt;b&gt;model assessment&lt;/b&gt;. The process of selecting proper level of flexibility for a model is known as &lt;b&gt;model selection&lt;/b&gt;.&lt;/p&gt;</description></item><item><title>Classification: Applied Exercises</title><link>https://amitrajan012.github.io/post/classification_part4/</link><pubDate>Wed, 16 May 2018 10:20:15 +0100</pubDate><guid>https://amitrajan012.github.io/post/classification_part4/</guid><description>&lt;h4 id="applied"&gt;Applied&lt;/h4&gt;&#10;&lt;p&gt;Q10. This question should be answered using the Weekly data set.&lt;/p&gt;&#10;&lt;p&gt;(a) Produce some numerical and graphical summaries of the Weekly data. Do there appear to be any patterns?&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; seaborn &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; sns&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;weekly &lt;span style="color:#f92672"&gt;=&lt;/span&gt; pd&lt;span style="color:#f92672"&gt;.&lt;/span&gt;read_csv(&lt;span style="color:#e6db74"&gt;&amp;#34;data/Weekly.csv&amp;#34;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;sns&lt;span style="color:#f92672"&gt;.&lt;/span&gt;pairplot(weekly, vars&lt;span style="color:#f92672"&gt;=&lt;/span&gt;[&lt;span style="color:#e6db74"&gt;&amp;#39;Lag1&amp;#39;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;Lag2&amp;#39;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;Lag3&amp;#39;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;Lag4&amp;#39;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;Lag5&amp;#39;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;Volume&amp;#39;&lt;/span&gt;], hue&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#39;Direction&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figure class="fig"&gt;&lt;img src="https://amitrajan012.github.io/img/Classification_files/Classification_49_2.png" alt="" loading="lazy"&gt;&lt;/figure&gt;&#10;&lt;p&gt;(b) Use the full data set to perform a logistic regression with Direction as the response and the five lag variables plus Volume as predictors. Use the summary function to print the results. Do any of the predictors appear to be statistically significant? If so, which ones?&lt;/p&gt;</description></item><item><title>Classification: Conceptual Exercises</title><link>https://amitrajan012.github.io/post/classification_part3/</link><pubDate>Tue, 15 May 2018 09:02:08 +0100</pubDate><guid>https://amitrajan012.github.io/post/classification_part3/</guid><description>&lt;h3 id="47-exercises"&gt;4.7 Exercises&lt;/h3&gt;&#10;&lt;h4 id="conceptual"&gt;Conceptual&lt;/h4&gt;&#10;&lt;p&gt;Q1. Using a little bit of algebra, prove that the logistic function representation and logit representation&#10;for the logistic regression model are equivalent.&lt;/p&gt;&#10;&lt;p&gt;&lt;b&gt;Sol: &lt;/b&gt; Logistic function representation is given as:&lt;/p&gt;&#10;\[p(X) = \frac{e^{\beta_0 &amp;#43; \beta_1X}}{1 &amp;#43; e^{\beta_0 &amp;#43; \beta_1X}}\]&lt;p&gt;then \(1-p(X) = \frac{1}{1 &amp;#43; e^{\beta_0 &amp;#43; \beta_1X}}\), Taking the ratio of these two and then taking the log, we get&lt;/p&gt;&#10;\[log\bigg( \frac{p(X)}{1-p(X)} \bigg) = \beta_0 &amp;#43; \beta_1X\]&lt;p&gt;Q2. Under the assumption that the observations in the \(k\)th class is drawn from a normal distribution, the Bayes&amp;rsquo; classifier assign an observation to the class for which the discriminant function is maximized.&lt;/p&gt;</description></item><item><title>Linear Discriminant Analysis</title><link>https://amitrajan012.github.io/post/classification_part2/</link><pubDate>Mon, 14 May 2018 11:12:28 +0100</pubDate><guid>https://amitrajan012.github.io/post/classification_part2/</guid><description>&lt;h3 id="44-linear-discriminant-analysis"&gt;4.4 Linear Discriminant Analysis&lt;/h3&gt;&#10;&lt;p&gt;In logistic regression, we model the the conditional distribution of response \(Y\) given the predictors \(X\). As an alternative approach, we model the distribution of predictors X seperately for each of the response classe. We then use &lt;b&gt;Bayes&amp;rsquo; Theorem&lt;/b&gt; to flip these around into estimates for &lt;b&gt;Pr(Y = k | X = x)&lt;/b&gt;. When these distributions are assumed to be &lt;b&gt;normal&lt;/b&gt;, this model is very similar to logistic regression. The advantage of LDA is as follows:&lt;/p&gt;</description></item><item><title>Logistic Regression</title><link>https://amitrajan012.github.io/post/classification_part1/</link><pubDate>Sun, 13 May 2018 02:17:58 +0100</pubDate><guid>https://amitrajan012.github.io/post/classification_part1/</guid><description>&lt;h1&gt;&lt;center&gt;Classification&lt;/center&gt;&lt;/h1&gt;&#10;&lt;p&gt;A process for predicting &lt;b&gt;qualitative&lt;/b&gt; or &lt;b&gt;categorical&lt;/b&gt; variables is called as &lt;b&gt;Classification&lt;/b&gt;.&lt;/p&gt;&#10;&lt;h3 id="41-an-overview-of-classification"&gt;4.1 An Overview of Classification&lt;/h3&gt;&#10;&lt;p&gt;The dataset used in this chapter will be &lt;b&gt;Default&lt;/b&gt; dataset. We will predict that whether an individual will default on his/her credit card payment on the basis of annual income and monthly credit card balance. The data is displayed below:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; pandas &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; pd&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; seaborn &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; sns&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; matplotlib.pyplot &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; plt&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;default &lt;span style="color:#f92672"&gt;=&lt;/span&gt; pd&lt;span style="color:#f92672"&gt;.&lt;/span&gt;read_excel(&lt;span style="color:#e6db74"&gt;&amp;#34;data/Default.xlsx&amp;#34;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;markers &lt;span style="color:#f92672"&gt;=&lt;/span&gt; {&lt;span style="color:#e6db74"&gt;&amp;#34;Yes&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;x&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;No&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;+&amp;#34;&lt;/span&gt;}&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;palette &lt;span style="color:#f92672"&gt;=&lt;/span&gt; {&lt;span style="color:#e6db74"&gt;&amp;#34;Yes&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;red&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;No&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;green&amp;#34;&lt;/span&gt;}&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;fig &lt;span style="color:#f92672"&gt;=&lt;/span&gt; plt&lt;span style="color:#f92672"&gt;.&lt;/span&gt;figure(figsize&lt;span style="color:#f92672"&gt;=&lt;/span&gt;(&lt;span style="color:#ae81ff"&gt;15&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;8&lt;/span&gt;))&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax &lt;span style="color:#f92672"&gt;=&lt;/span&gt; fig&lt;span style="color:#f92672"&gt;.&lt;/span&gt;add_subplot(&lt;span style="color:#ae81ff"&gt;111&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;sns&lt;span style="color:#f92672"&gt;.&lt;/span&gt;scatterplot(x&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;balance&amp;#34;&lt;/span&gt;, y&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;income&amp;#34;&lt;/span&gt;, hue&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;default&amp;#34;&lt;/span&gt;, style&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;default&amp;#34;&lt;/span&gt;, markers&lt;span style="color:#f92672"&gt;=&lt;/span&gt;markers, palette&lt;span style="color:#f92672"&gt;=&lt;/span&gt;palette,&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; alpha&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;0.6&lt;/span&gt;, data&lt;span style="color:#f92672"&gt;=&lt;/span&gt;default)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_xlabel(&lt;span style="color:#e6db74"&gt;&amp;#39;Balance&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_ylabel(&lt;span style="color:#e6db74"&gt;&amp;#39;Income&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_title(&lt;span style="color:#e6db74"&gt;&amp;#39;Scatter Plot&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;fig &lt;span style="color:#f92672"&gt;=&lt;/span&gt; plt&lt;span style="color:#f92672"&gt;.&lt;/span&gt;figure(figsize&lt;span style="color:#f92672"&gt;=&lt;/span&gt;(&lt;span style="color:#ae81ff"&gt;15&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;8&lt;/span&gt;))&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax &lt;span style="color:#f92672"&gt;=&lt;/span&gt; fig&lt;span style="color:#f92672"&gt;.&lt;/span&gt;add_subplot(&lt;span style="color:#ae81ff"&gt;121&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;sns&lt;span style="color:#f92672"&gt;.&lt;/span&gt;boxplot(x&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;default&amp;#34;&lt;/span&gt;, y&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;balance&amp;#34;&lt;/span&gt;, data&lt;span style="color:#f92672"&gt;=&lt;/span&gt;default)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_xlabel(&lt;span style="color:#e6db74"&gt;&amp;#39;Default&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_ylabel(&lt;span style="color:#e6db74"&gt;&amp;#39;Balance&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_title(&lt;span style="color:#e6db74"&gt;&amp;#39;Box Plot&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax &lt;span style="color:#f92672"&gt;=&lt;/span&gt; fig&lt;span style="color:#f92672"&gt;.&lt;/span&gt;add_subplot(&lt;span style="color:#ae81ff"&gt;122&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;sns&lt;span style="color:#f92672"&gt;.&lt;/span&gt;boxplot(x&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;default&amp;#34;&lt;/span&gt;, y&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;income&amp;#34;&lt;/span&gt;, data&lt;span style="color:#f92672"&gt;=&lt;/span&gt;default)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_xlabel(&lt;span style="color:#e6db74"&gt;&amp;#39;Default&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_ylabel(&lt;span style="color:#e6db74"&gt;&amp;#39;Income&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_title(&lt;span style="color:#e6db74"&gt;&amp;#39;Box Plot&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;plt&lt;span style="color:#f92672"&gt;.&lt;/span&gt;show()&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figure class="fig"&gt;&lt;img src="https://amitrajan012.github.io/img/Classification_files/Classification_5_0.png" alt="" loading="lazy"&gt;&lt;/figure&gt;&#10;&lt;figure class="fig"&gt;&lt;img src="https://amitrajan012.github.io/img/Classification_files/Classification_5_1.png" alt="" loading="lazy"&gt;&lt;/figure&gt;&#10;&lt;h3 id="42-why-not-linear-regression"&gt;4.2 Why Not Linear Regression?&lt;/h3&gt;&#10;&lt;p&gt;In general, there is no natural way to convert a qualitative response variable with more than two levels into a quantitative response that is ready for linear regression. For the binary qualitative response, we can simply encode the variables as 0 and 1 and predict the values taking 0.5 as threshold.&lt;/p&gt;</description></item><item><title>Linear Regression: Applied Exercises</title><link>https://amitrajan012.github.io/post/linear-regression_part5/</link><pubDate>Fri, 11 May 2018 05:18:18 +0100</pubDate><guid>https://amitrajan012.github.io/post/linear-regression_part5/</guid><description>&lt;h4 id="applied"&gt;Applied&lt;/h4&gt;&#10;&lt;p&gt;&lt;b&gt;Solution 8:&lt;/b&gt;&lt;/p&gt;&#10;&lt;p&gt;(a) Perform linear regression on auto data with &lt;b&gt;mpg&lt;/b&gt; as response and &lt;b&gt;horsepower&lt;/b&gt; as the predictor and display the summary results.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; statsmodels.api &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; sm&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;X &lt;span style="color:#f92672"&gt;=&lt;/span&gt; sm&lt;span style="color:#f92672"&gt;.&lt;/span&gt;add_constant(auto[[&lt;span style="color:#e6db74"&gt;&amp;#39;horsepower&amp;#39;&lt;/span&gt;]], prepend&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;True&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;model &lt;span style="color:#f92672"&gt;=&lt;/span&gt; sm&lt;span style="color:#f92672"&gt;.&lt;/span&gt;OLS(auto[&lt;span style="color:#e6db74"&gt;&amp;#39;mpg&amp;#39;&lt;/span&gt;], X)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;result &lt;span style="color:#f92672"&gt;=&lt;/span&gt; model&lt;span style="color:#f92672"&gt;.&lt;/span&gt;fit()&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;print(result&lt;span style="color:#f92672"&gt;.&lt;/span&gt;summary())&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;print(&lt;span style="color:#e6db74"&gt;&amp;#34;Prediction for horsepower 98: &amp;#34;&lt;/span&gt; &lt;span style="color:#f92672"&gt;+&lt;/span&gt;str(result&lt;span style="color:#f92672"&gt;.&lt;/span&gt;predict([&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;98&lt;/span&gt;])))&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;print(&lt;span style="color:#e6db74"&gt;&amp;#34;95% CI: &amp;#34;&lt;/span&gt; &lt;span style="color:#f92672"&gt;+&lt;/span&gt;str(result&lt;span style="color:#f92672"&gt;.&lt;/span&gt;conf_int(alpha&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;0.05&lt;/span&gt;, cols&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;None&lt;/span&gt;)))&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt; OLS Regression Results&#10;==============================================================================&#10;Dep. Variable: mpg R-squared: 0.606&#10;Model: OLS Adj. R-squared: 0.605&#10;Method: Least Squares F-statistic: 599.7&#10;Date: Thu, 06 Sep 2018 Prob (F-statistic): 7.03e-81&#10;Time: 21:37:43 Log-Likelihood: -1178.7&#10;No. Observations: 392 AIC: 2361.&#10;Df Residuals: 390 BIC: 2369.&#10;Df Model: 1&#10;Covariance Type: nonrobust&#10;==============================================================================&#10; coef std err t P&amp;gt;|t| [0.025 0.975]&#10;------------------------------------------------------------------------------&#10;const 39.9359 0.717 55.660 0.000 38.525 41.347&#10;horsepower -0.1578 0.006 -24.489 0.000 -0.171 -0.145&#10;==============================================================================&#10;Omnibus: 16.432 Durbin-Watson: 0.920&#10;Prob(Omnibus): 0.000 Jarque-Bera (JB): 17.305&#10;Skew: 0.492 Prob(JB): 0.000175&#10;Kurtosis: 3.299 Cond. No. 322.&#10;==============================================================================&#10;&#10;Warnings:&#10;[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.&#10;Prediction for horsepower 98: [24.46707715]&#10;95% CI: 0 1&#10;const 38.525212 41.346510&#10;horsepower -0.170517 -0.145172&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;p&gt;i. Is there a relationship between the predictor and the response?&lt;/p&gt;</description></item><item><title>Linear Regression: Conceptual Exercises</title><link>https://amitrajan012.github.io/post/linear-regression_part4/</link><pubDate>Thu, 10 May 2018 10:28:18 +0100</pubDate><guid>https://amitrajan012.github.io/post/linear-regression_part4/</guid><description>&lt;h4 id="37-exercises"&gt;3.7 Exercises&lt;/h4&gt;&#10;&lt;h4 id="conceptual"&gt;Conceptual&lt;/h4&gt;&#10;&lt;figure class="fig"&gt;&lt;img src="https://amitrajan012.github.io/img/Linear%20Regression_files/Q3.3.png" alt="" loading="lazy"&gt;&lt;/figure&gt;&#10;&lt;p&gt;&lt;b&gt;Solution:&lt;/b&gt; The linear fit can be given as:&lt;/p&gt;&#10;\[50 &amp;#43; (20 \times GPA) &amp;#43; (0.07 \times IQ) &amp;#43; (35 \times GENDER) &amp;#43; (0.01 \times GPA \times IQ) - (10 \times GPA \times GENDER)\]&lt;p&gt;(a) For a fixed value of IQ and GPA, the average salary for male will be \(50 &amp;#43; 20 \times GPA\) and for the female it will be \(85 &amp;#43; 20 \times GPA - 10 \times GPA\). For the salary of male to be higher, \(50 &amp;#43; 20GPA &amp;gt; 85 &amp;#43; 10GPA\), i.e. \(GPA &amp;gt; 3.5\).&lt;/p&gt;</description></item><item><title>Other Considerations in the Regression Model</title><link>https://amitrajan012.github.io/post/linear-regression_part3/</link><pubDate>Wed, 09 May 2018 11:11:48 +0100</pubDate><guid>https://amitrajan012.github.io/post/linear-regression_part3/</guid><description>&lt;h3 id="33-other-considerations-in-the-regression-model"&gt;3.3 Other Considerations in the Regression Model&lt;/h3&gt;&#10;&lt;h4 id="331-qualitative-predictors"&gt;3.3.1 Qualitative Predictors&lt;/h4&gt;&#10;&lt;p&gt;There can be a case when predictor variables can be &lt;b&gt;qualitative.&lt;/b&gt;&lt;/p&gt;&#10;&lt;h4 id="predictors-with-only-two-levels"&gt;Predictors with Only Two Levels&lt;/h4&gt;&#10;&lt;p&gt;For the predictors with only two values, we can create an &lt;b&gt;indicator&lt;/b&gt; or &lt;b&gt;dummy variable&lt;/b&gt; with values 0 and 1 and use it in the regression model. The final prediction will not depend on the coding scheme. Only difference will be in the model coefficients and the way they are interpreted.&lt;/p&gt;</description></item><item><title>Multiple Linear Regression</title><link>https://amitrajan012.github.io/post/linear-regression_part2/</link><pubDate>Tue, 08 May 2018 06:12:03 +0100</pubDate><guid>https://amitrajan012.github.io/post/linear-regression_part2/</guid><description>&lt;h3 id="32-multiple-linear-regression"&gt;3.2 Multiple Linear Regression&lt;/h3&gt;&#10;&lt;p&gt;In general, suppose we have \(p\) distinct predictors, the multiple linear regression takes the form:&lt;/p&gt;&#10;\[Y = \beta_0 &amp;#43; \beta_1 X_1 &amp;#43; \beta_2 X_2 &amp;#43; ... &amp;#43; \beta_p X_p &amp;#43; \epsilon\]&lt;p&gt;where \(\beta_j\) can be interpreted as the average effect on \(Y\) of a one unit increase in \(X_j\), &lt;b&gt;holding all other predictors fixed.&lt;/b&gt;&lt;/p&gt;&#10;&lt;h4 id="321-estimating-the-regression-coefficients"&gt;3.2.1 Estimating the Regression Coefficients&lt;/h4&gt;&#10;&lt;p&gt;Given the estimates, \(\widehat{\beta_0}, \widehat{\beta_1},..., \widehat{\beta_p}\), predictions can be done as:&lt;/p&gt;</description></item><item><title>Simple Linear Regression</title><link>https://amitrajan012.github.io/post/linear-regression_part1/</link><pubDate>Tue, 08 May 2018 02:18:09 +0100</pubDate><guid>https://amitrajan012.github.io/post/linear-regression_part1/</guid><description>&lt;h1&gt;&lt;center&gt;Linear Regression&lt;/center&gt;&lt;/h1&gt;&#10;&lt;p&gt;&lt;b&gt;Linear Regression&lt;/b&gt; is a useful tool for predicting a quantitative response.&lt;/p&gt;&#10;&lt;h3 id="31-simple-linear-regression"&gt;3.1 Simple Linear Regression&lt;/h3&gt;&#10;&lt;p&gt;&lt;b&gt;Simple linear regression&lt;/b&gt; is a straightforward approach for predicting a &lt;b&gt;quantitative response&lt;/b&gt; on the basis of a single predictor variable. Mathematically it can be written as:&lt;/p&gt;&#10;\[Y \approx \beta_0 &amp;#43; \beta_1 X\]&lt;p&gt;\(\beta_0\) and \(\beta_1\) represent intercept and slope and are called as &lt;b&gt;model coefficients or parameters.&lt;/b&gt; The estimated equation is given as:&lt;/p&gt;&#10;\[\widehat{y} \approx \widehat{\beta_0} &amp;#43; \widehat{\beta_1} x\]&lt;p&gt;where hat symbol is used to denote the estimated values.&lt;/p&gt;</description></item><item><title>Statistical Learning: Applied Exercises</title><link>https://amitrajan012.github.io/post/statistical-learning_part4/</link><pubDate>Sun, 06 May 2018 07:24:34 +0100</pubDate><guid>https://amitrajan012.github.io/post/statistical-learning_part4/</guid><description>&lt;h4 id="applied"&gt;Applied&lt;/h4&gt;&#10;&lt;p&gt;&lt;b&gt;Q8. This exercise relates to the College data set, which can be found in the file College.csv. It contains a number of variables for 777 different universities and colleges in the US.&lt;/b&gt;&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; pandas &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; pd&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;college &lt;span style="color:#f92672"&gt;=&lt;/span&gt; pd&lt;span style="color:#f92672"&gt;.&lt;/span&gt;read_csv(&lt;span style="color:#e6db74"&gt;&amp;#34;data/College.csv&amp;#34;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;college&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_index(&lt;span style="color:#e6db74"&gt;&amp;#39;Unnamed: 0&amp;#39;&lt;/span&gt;, drop&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;True&lt;/span&gt;, inplace&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;True&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;college&lt;span style="color:#f92672"&gt;.&lt;/span&gt;index&lt;span style="color:#f92672"&gt;.&lt;/span&gt;names &lt;span style="color:#f92672"&gt;=&lt;/span&gt; [&lt;span style="color:#e6db74"&gt;&amp;#39;Name&amp;#39;&lt;/span&gt;]&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;college&lt;span style="color:#f92672"&gt;.&lt;/span&gt;describe()&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&#10;&lt;style scoped&gt;&#10; .dataframe tbody tr th:only-of-type {&#10; vertical-align: middle;&#10; }&#10;&lt;pre&gt;&lt;code&gt;.dataframe tbody tr th {&#10; vertical-align: top;&#10;}&#10;&#10;.dataframe thead th {&#10; text-align: right;&#10;}&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;p&gt;&lt;/style&gt;&lt;/p&gt;&#10;&lt;table border="1" class="dataframe"&gt;&#10; &lt;thead&gt;&#10; &lt;tr style="text-align: right;"&gt;&#10; &lt;th&gt;&lt;/th&gt;&#10; &lt;th&gt;Apps&lt;/th&gt;&#10; &lt;th&gt;Accept&lt;/th&gt;&#10; &lt;th&gt;Enroll&lt;/th&gt;&#10; &lt;th&gt;Top10perc&lt;/th&gt;&#10; &lt;th&gt;Top25perc&lt;/th&gt;&#10; &lt;th&gt;F.Undergrad&lt;/th&gt;&#10; &lt;th&gt;P.Undergrad&lt;/th&gt;&#10; &lt;th&gt;Outstate&lt;/th&gt;&#10; &lt;th&gt;Room.Board&lt;/th&gt;&#10; &lt;th&gt;Books&lt;/th&gt;&#10; &lt;th&gt;Personal&lt;/th&gt;&#10; &lt;th&gt;PhD&lt;/th&gt;&#10; &lt;th&gt;Terminal&lt;/th&gt;&#10; &lt;th&gt;S.F.Ratio&lt;/th&gt;&#10; &lt;th&gt;perc.alumni&lt;/th&gt;&#10; &lt;th&gt;Expend&lt;/th&gt;&#10; &lt;th&gt;Grad.Rate&lt;/th&gt;&#10; &lt;/tr&gt;&#10; &lt;/thead&gt;&#10; &lt;tbody&gt;&#10; &lt;tr&gt;&#10; &lt;th&gt;count&lt;/th&gt;&#10; &lt;td&gt;777.000000&lt;/td&gt;&#10; &lt;td&gt;777.000000&lt;/td&gt;&#10; &lt;td&gt;777.000000&lt;/td&gt;&#10; &lt;td&gt;777.000000&lt;/td&gt;&#10; &lt;td&gt;777.000000&lt;/td&gt;&#10; &lt;td&gt;777.000000&lt;/td&gt;&#10; &lt;td&gt;777.000000&lt;/td&gt;&#10; &lt;td&gt;777.000000&lt;/td&gt;&#10; &lt;td&gt;777.000000&lt;/td&gt;&#10; &lt;td&gt;777.000000&lt;/td&gt;&#10; &lt;td&gt;777.000000&lt;/td&gt;&#10; &lt;td&gt;777.000000&lt;/td&gt;&#10; &lt;td&gt;777.000000&lt;/td&gt;&#10; &lt;td&gt;777.000000&lt;/td&gt;&#10; &lt;td&gt;777.000000&lt;/td&gt;&#10; &lt;td&gt;777.000000&lt;/td&gt;&#10; &lt;td&gt;777.00000&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;th&gt;mean&lt;/th&gt;&#10; &lt;td&gt;3001.638353&lt;/td&gt;&#10; &lt;td&gt;2018.804376&lt;/td&gt;&#10; &lt;td&gt;779.972973&lt;/td&gt;&#10; &lt;td&gt;27.558559&lt;/td&gt;&#10; &lt;td&gt;55.796654&lt;/td&gt;&#10; &lt;td&gt;3699.907336&lt;/td&gt;&#10; &lt;td&gt;855.298584&lt;/td&gt;&#10; &lt;td&gt;10440.669241&lt;/td&gt;&#10; &lt;td&gt;4357.526384&lt;/td&gt;&#10; &lt;td&gt;549.380952&lt;/td&gt;&#10; &lt;td&gt;1340.642214&lt;/td&gt;&#10; &lt;td&gt;72.660232&lt;/td&gt;&#10; &lt;td&gt;79.702703&lt;/td&gt;&#10; &lt;td&gt;14.089704&lt;/td&gt;&#10; &lt;td&gt;22.743887&lt;/td&gt;&#10; &lt;td&gt;9660.171171&lt;/td&gt;&#10; &lt;td&gt;65.46332&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;th&gt;std&lt;/th&gt;&#10; &lt;td&gt;3870.201484&lt;/td&gt;&#10; &lt;td&gt;2451.113971&lt;/td&gt;&#10; &lt;td&gt;929.176190&lt;/td&gt;&#10; &lt;td&gt;17.640364&lt;/td&gt;&#10; &lt;td&gt;19.804778&lt;/td&gt;&#10; &lt;td&gt;4850.420531&lt;/td&gt;&#10; &lt;td&gt;1522.431887&lt;/td&gt;&#10; &lt;td&gt;4023.016484&lt;/td&gt;&#10; &lt;td&gt;1096.696416&lt;/td&gt;&#10; &lt;td&gt;165.105360&lt;/td&gt;&#10; &lt;td&gt;677.071454&lt;/td&gt;&#10; &lt;td&gt;16.328155&lt;/td&gt;&#10; &lt;td&gt;14.722359&lt;/td&gt;&#10; &lt;td&gt;3.958349&lt;/td&gt;&#10; &lt;td&gt;12.391801&lt;/td&gt;&#10; &lt;td&gt;5221.768440&lt;/td&gt;&#10; &lt;td&gt;17.17771&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;th&gt;min&lt;/th&gt;&#10; &lt;td&gt;81.000000&lt;/td&gt;&#10; &lt;td&gt;72.000000&lt;/td&gt;&#10; &lt;td&gt;35.000000&lt;/td&gt;&#10; &lt;td&gt;1.000000&lt;/td&gt;&#10; &lt;td&gt;9.000000&lt;/td&gt;&#10; &lt;td&gt;139.000000&lt;/td&gt;&#10; &lt;td&gt;1.000000&lt;/td&gt;&#10; &lt;td&gt;2340.000000&lt;/td&gt;&#10; &lt;td&gt;1780.000000&lt;/td&gt;&#10; &lt;td&gt;96.000000&lt;/td&gt;&#10; &lt;td&gt;250.000000&lt;/td&gt;&#10; &lt;td&gt;8.000000&lt;/td&gt;&#10; &lt;td&gt;24.000000&lt;/td&gt;&#10; &lt;td&gt;2.500000&lt;/td&gt;&#10; &lt;td&gt;0.000000&lt;/td&gt;&#10; &lt;td&gt;3186.000000&lt;/td&gt;&#10; &lt;td&gt;10.00000&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;th&gt;25%&lt;/th&gt;&#10; &lt;td&gt;776.000000&lt;/td&gt;&#10; &lt;td&gt;604.000000&lt;/td&gt;&#10; &lt;td&gt;242.000000&lt;/td&gt;&#10; &lt;td&gt;15.000000&lt;/td&gt;&#10; &lt;td&gt;41.000000&lt;/td&gt;&#10; &lt;td&gt;992.000000&lt;/td&gt;&#10; &lt;td&gt;95.000000&lt;/td&gt;&#10; &lt;td&gt;7320.000000&lt;/td&gt;&#10; &lt;td&gt;3597.000000&lt;/td&gt;&#10; &lt;td&gt;470.000000&lt;/td&gt;&#10; &lt;td&gt;850.000000&lt;/td&gt;&#10; &lt;td&gt;62.000000&lt;/td&gt;&#10; &lt;td&gt;71.000000&lt;/td&gt;&#10; &lt;td&gt;11.500000&lt;/td&gt;&#10; &lt;td&gt;13.000000&lt;/td&gt;&#10; &lt;td&gt;6751.000000&lt;/td&gt;&#10; &lt;td&gt;53.00000&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;th&gt;50%&lt;/th&gt;&#10; &lt;td&gt;1558.000000&lt;/td&gt;&#10; &lt;td&gt;1110.000000&lt;/td&gt;&#10; &lt;td&gt;434.000000&lt;/td&gt;&#10; &lt;td&gt;23.000000&lt;/td&gt;&#10; &lt;td&gt;54.000000&lt;/td&gt;&#10; &lt;td&gt;1707.000000&lt;/td&gt;&#10; &lt;td&gt;353.000000&lt;/td&gt;&#10; &lt;td&gt;9990.000000&lt;/td&gt;&#10; &lt;td&gt;4200.000000&lt;/td&gt;&#10; &lt;td&gt;500.000000&lt;/td&gt;&#10; &lt;td&gt;1200.000000&lt;/td&gt;&#10; &lt;td&gt;75.000000&lt;/td&gt;&#10; &lt;td&gt;82.000000&lt;/td&gt;&#10; &lt;td&gt;13.600000&lt;/td&gt;&#10; &lt;td&gt;21.000000&lt;/td&gt;&#10; &lt;td&gt;8377.000000&lt;/td&gt;&#10; &lt;td&gt;65.00000&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;th&gt;75%&lt;/th&gt;&#10; &lt;td&gt;3624.000000&lt;/td&gt;&#10; &lt;td&gt;2424.000000&lt;/td&gt;&#10; &lt;td&gt;902.000000&lt;/td&gt;&#10; &lt;td&gt;35.000000&lt;/td&gt;&#10; &lt;td&gt;69.000000&lt;/td&gt;&#10; &lt;td&gt;4005.000000&lt;/td&gt;&#10; &lt;td&gt;967.000000&lt;/td&gt;&#10; &lt;td&gt;12925.000000&lt;/td&gt;&#10; &lt;td&gt;5050.000000&lt;/td&gt;&#10; &lt;td&gt;600.000000&lt;/td&gt;&#10; &lt;td&gt;1700.000000&lt;/td&gt;&#10; &lt;td&gt;85.000000&lt;/td&gt;&#10; &lt;td&gt;92.000000&lt;/td&gt;&#10; &lt;td&gt;16.500000&lt;/td&gt;&#10; &lt;td&gt;31.000000&lt;/td&gt;&#10; &lt;td&gt;10830.000000&lt;/td&gt;&#10; &lt;td&gt;78.00000&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;tr&gt;&#10; &lt;th&gt;max&lt;/th&gt;&#10; &lt;td&gt;48094.000000&lt;/td&gt;&#10; &lt;td&gt;26330.000000&lt;/td&gt;&#10; &lt;td&gt;6392.000000&lt;/td&gt;&#10; &lt;td&gt;96.000000&lt;/td&gt;&#10; &lt;td&gt;100.000000&lt;/td&gt;&#10; &lt;td&gt;31643.000000&lt;/td&gt;&#10; &lt;td&gt;21836.000000&lt;/td&gt;&#10; &lt;td&gt;21700.000000&lt;/td&gt;&#10; &lt;td&gt;8124.000000&lt;/td&gt;&#10; &lt;td&gt;2340.000000&lt;/td&gt;&#10; &lt;td&gt;6800.000000&lt;/td&gt;&#10; &lt;td&gt;103.000000&lt;/td&gt;&#10; &lt;td&gt;100.000000&lt;/td&gt;&#10; &lt;td&gt;39.800000&lt;/td&gt;&#10; &lt;td&gt;64.000000&lt;/td&gt;&#10; &lt;td&gt;56233.000000&lt;/td&gt;&#10; &lt;td&gt;118.00000&lt;/td&gt;&#10; &lt;/tr&gt;&#10; &lt;/tbody&gt;&#10;&lt;/table&gt;&#10;&lt;/div&gt;</description></item><item><title>Statistical Learning: Conceptual Exercises</title><link>https://amitrajan012.github.io/post/statistical-learning_part3/</link><pubDate>Sun, 06 May 2018 01:38:54 +0100</pubDate><guid>https://amitrajan012.github.io/post/statistical-learning_part3/</guid><description>&lt;h3 id="24-exercises"&gt;2.4 Exercises&lt;/h3&gt;&#10;&lt;h4 id="conceptual"&gt;Conceptual&lt;/h4&gt;&#10;&lt;p&gt;&lt;b&gt;Q1. For each of parts (a) through (d), indicate whether we would generally expect the performance of a flexible statistical learning method to be better or worse than an inflexible method. Justify your answer. &lt;/b&gt;&lt;/p&gt;&#10;&lt;p&gt;(a) The sample size n is extremely large, and the number of predic- tors p is small.&lt;/p&gt;&#10;&lt;p&gt;&lt;b&gt;Sol:&lt;/b&gt; Better&lt;/p&gt;&#10;&lt;p&gt;(b) The number of predictors p is extremely large, and the number of observations n is small.&lt;/p&gt;</description></item><item><title>Assessing Model Accuracy</title><link>https://amitrajan012.github.io/post/statistical-learning_part2/</link><pubDate>Sat, 05 May 2018 07:11:10 +0100</pubDate><guid>https://amitrajan012.github.io/post/statistical-learning_part2/</guid><description>&lt;h3 id="22-assessing-model-accuracy"&gt;2.2 Assessing Model Accuracy&lt;/h3&gt;&#10;&lt;p&gt;No one statistical learning method dominates all other over all possible data sets. Hence it is an important task to decide that for any given data set which model fits best.&lt;/p&gt;&#10;&lt;h4 id="221-measuring-the-quality-of-fit"&gt;2.2.1 Measuring the Quality of Fit&lt;/h4&gt;&#10;&lt;p&gt;In the &lt;b&gt;regression&lt;/b&gt; setting, the most commonly used measure for quality of fit is &lt;b&gt;mean squared error (MSE)&lt;/b&gt;, which is given as:&lt;/p&gt;&#10;\[MSE = \frac{1}{n} \sum_{i=1}^{n} (y_i - \widehat{f}(x_i))^{2}\]&lt;p&gt;where \(\widehat{f}(x_i)\) is the prediction for the \(i\)th observation. MSE will be small if the predicted responses are very close to the true responses. While training a model, &lt;b&gt;training MSE&lt;/b&gt; is of lesser significance. We should be more interested in &lt;b&gt;test MSE&lt;/b&gt;, which is the MSE for the previously unseen test observation not used to train the model. When the test data is available, we can simply compute test MSE and select the model which has the lowest test MSE. In the absence of test data, the basic approach is to simply select a model with the lowest training MSE. Below figure shows the MSE of test and train data for a model.&lt;/p&gt;</description></item><item><title>What Is Statistical Learning?</title><link>https://amitrajan012.github.io/post/statistical-learning_part1/</link><pubDate>Fri, 04 May 2018 09:32:21 +0100</pubDate><guid>https://amitrajan012.github.io/post/statistical-learning_part1/</guid><description>&lt;h1&gt;&lt;center&gt;Statistical Learning&lt;/center&gt;&lt;/h1&gt;&#10;&lt;h3 id="21-what-is-statistical-learning"&gt;2.1 What Is Statistical Learning?&lt;/h3&gt;&#10;&lt;p&gt;The &lt;b&gt;Advertising&lt;/b&gt; data set consists of the sales of that product in 200 different markets, along with advertising budgets for the product in each of those markets for three different media: &lt;b&gt;TV, radio, and newspaper.&lt;/b&gt; The plot of data is shown below. Our goal is to develop an accurate model that can be used to predict sales on the basis of the three media budgets.&lt;/p&gt;</description></item><item><title>Introduction to Statistical Learning</title><link>https://amitrajan012.github.io/post/introduction/</link><pubDate>Wed, 02 May 2018 11:14:32 +0100</pubDate><guid>https://amitrajan012.github.io/post/introduction/</guid><description>&lt;h1&gt;&lt;center&gt;Chapter 1: Introduction&lt;/center&gt;&lt;/h1&gt;&#10;&lt;h3 id="wage-data"&gt;Wage Data&lt;/h3&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; pandas &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; pd&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; matplotlib.pyplot &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; plt&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; seaborn &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; sns&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;wage &lt;span style="color:#f92672"&gt;=&lt;/span&gt; pd&lt;span style="color:#f92672"&gt;.&lt;/span&gt;read_csv(&lt;span style="color:#e6db74"&gt;&amp;#34;data/Wage.csv&amp;#34;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;wage&lt;span style="color:#f92672"&gt;.&lt;/span&gt;loc[df[&lt;span style="color:#e6db74"&gt;&amp;#39;education&amp;#39;&lt;/span&gt;] &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#39;1. &amp;lt; HS Grad&amp;#39;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;education&amp;#39;&lt;/span&gt;] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;wage&lt;span style="color:#f92672"&gt;.&lt;/span&gt;loc[df[&lt;span style="color:#e6db74"&gt;&amp;#39;education&amp;#39;&lt;/span&gt;] &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#39;2. HS Grad&amp;#39;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;education&amp;#39;&lt;/span&gt;] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;2&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;wage&lt;span style="color:#f92672"&gt;.&lt;/span&gt;loc[df[&lt;span style="color:#e6db74"&gt;&amp;#39;education&amp;#39;&lt;/span&gt;] &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#39;3. Some College&amp;#39;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;education&amp;#39;&lt;/span&gt;] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;3&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;wage&lt;span style="color:#f92672"&gt;.&lt;/span&gt;loc[df[&lt;span style="color:#e6db74"&gt;&amp;#39;education&amp;#39;&lt;/span&gt;] &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#39;4. College Grad&amp;#39;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;education&amp;#39;&lt;/span&gt;] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;4&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;wage&lt;span style="color:#f92672"&gt;.&lt;/span&gt;loc[df[&lt;span style="color:#e6db74"&gt;&amp;#39;education&amp;#39;&lt;/span&gt;] &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#39;5. Advanced Degree&amp;#39;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;education&amp;#39;&lt;/span&gt;] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;5&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;wage&lt;span style="color:#f92672"&gt;.&lt;/span&gt;head()&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;fig &lt;span style="color:#f92672"&gt;=&lt;/span&gt; plt&lt;span style="color:#f92672"&gt;.&lt;/span&gt;figure(figsize&lt;span style="color:#f92672"&gt;=&lt;/span&gt;(&lt;span style="color:#ae81ff"&gt;15&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;8&lt;/span&gt;))&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax &lt;span style="color:#f92672"&gt;=&lt;/span&gt; fig&lt;span style="color:#f92672"&gt;.&lt;/span&gt;add_subplot(&lt;span style="color:#ae81ff"&gt;131&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;sns&lt;span style="color:#f92672"&gt;.&lt;/span&gt;regplot(x&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;, y&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;wage&amp;#34;&lt;/span&gt;, color&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#39;#D7DBDD&amp;#39;&lt;/span&gt;, data&lt;span style="color:#f92672"&gt;=&lt;/span&gt;wage, order&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;2&lt;/span&gt;, scatter_kws&lt;span style="color:#f92672"&gt;=&lt;/span&gt;{&lt;span style="color:#e6db74"&gt;&amp;#39;alpha&amp;#39;&lt;/span&gt;:&lt;span style="color:#ae81ff"&gt;0.5&lt;/span&gt;},&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; line_kws&lt;span style="color:#f92672"&gt;=&lt;/span&gt;{&lt;span style="color:#e6db74"&gt;&amp;#39;color&amp;#39;&lt;/span&gt;:&lt;span style="color:#e6db74"&gt;&amp;#39;g&amp;#39;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;alpha&amp;#39;&lt;/span&gt;:&lt;span style="color:#ae81ff"&gt;0.7&lt;/span&gt;})&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_xlabel(&lt;span style="color:#e6db74"&gt;&amp;#39;Age&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_ylabel(&lt;span style="color:#e6db74"&gt;&amp;#39;Wage&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_title(&lt;span style="color:#e6db74"&gt;&amp;#39;Wage vs Age&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax &lt;span style="color:#f92672"&gt;=&lt;/span&gt; fig&lt;span style="color:#f92672"&gt;.&lt;/span&gt;add_subplot(&lt;span style="color:#ae81ff"&gt;132&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;sns&lt;span style="color:#f92672"&gt;.&lt;/span&gt;regplot(x&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;year&amp;#34;&lt;/span&gt;, y&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;wage&amp;#34;&lt;/span&gt;, color&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#39;#D7DBDD&amp;#39;&lt;/span&gt;, data&lt;span style="color:#f92672"&gt;=&lt;/span&gt;wage, order&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;, scatter_kws&lt;span style="color:#f92672"&gt;=&lt;/span&gt;{&lt;span style="color:#e6db74"&gt;&amp;#39;alpha&amp;#39;&lt;/span&gt;:&lt;span style="color:#ae81ff"&gt;0.5&lt;/span&gt;},&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; line_kws&lt;span style="color:#f92672"&gt;=&lt;/span&gt;{&lt;span style="color:#e6db74"&gt;&amp;#39;color&amp;#39;&lt;/span&gt;:&lt;span style="color:#e6db74"&gt;&amp;#39;g&amp;#39;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;alpha&amp;#39;&lt;/span&gt;:&lt;span style="color:#ae81ff"&gt;0.7&lt;/span&gt;})&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_xlabel(&lt;span style="color:#e6db74"&gt;&amp;#39;Year&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_ylabel(&lt;span style="color:#e6db74"&gt;&amp;#39;Wage&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_title(&lt;span style="color:#e6db74"&gt;&amp;#39;Wage vs Year&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax &lt;span style="color:#f92672"&gt;=&lt;/span&gt; fig&lt;span style="color:#f92672"&gt;.&lt;/span&gt;add_subplot(&lt;span style="color:#ae81ff"&gt;133&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;sns&lt;span style="color:#f92672"&gt;.&lt;/span&gt;boxplot(x&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;education&amp;#34;&lt;/span&gt;, y&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;wage&amp;#34;&lt;/span&gt;, data&lt;span style="color:#f92672"&gt;=&lt;/span&gt;wage)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_xlabel(&lt;span style="color:#e6db74"&gt;&amp;#39;Education&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_ylabel(&lt;span style="color:#e6db74"&gt;&amp;#39;Wage&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax&lt;span style="color:#f92672"&gt;.&lt;/span&gt;set_title(&lt;span style="color:#e6db74"&gt;&amp;#39;Wage vs Education&amp;#39;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;plt&lt;span style="color:#f92672"&gt;.&lt;/span&gt;show()&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figure class="fig"&gt;&lt;img src="https://amitrajan012.github.io/img/Introduction_files/Introduction_3_1.png" alt="" loading="lazy"&gt;&lt;/figure&gt;&#10;&lt;p&gt;The Wage dataset consists of data containing income, age, year and education level of different individuals. As shown in the above figure, it can be interpreted that wage increases with increase in age upto 60 years and decreases afterwards (but deviation is significant). Wage increases linearly with the year (but deviation is significant). The people with higher education level tends to have higher wage. So ideally if we want to predict wage, we should consider the non-linear relationship between wage and age and take into consideration the effect of year and education level as well. This process involves predicting a &lt;b&gt;continuous&lt;/b&gt; or &lt;b&gt;quantitative&lt;/b&gt; value and is often referred to as a &lt;b&gt;regression&lt;/b&gt; problem.&lt;/p&gt;</description></item></channel></rss>