{"id":6477,"date":"2021-01-21T18:27:57","date_gmt":"2021-01-21T12:57:57","guid":{"rendered":"https:\/\/copyassignment.com\/?p=6477"},"modified":"2022-08-05T09:28:17","modified_gmt":"2022-08-05T03:58:17","slug":"linear-regression-machine-learning","status":"publish","type":"post","link":"https:\/\/copyassignment.com\/linear-regression-machine-learning\/","title":{"rendered":"Linear Regression: Your 1st Step in Machine Learning"},"content":{"rendered":"\n<p>Hi guys! So until now, we&#8217;ve learned about how we can use libraries to play with data. We did data analysis on a real dataset and we also learned how to visualize data. But what was the purpose behind it? Why do so many things? What are we trying to achieve? I&#8217;ll tell you all about it along with a seemingly simple ML algorithm called <strong>Linear Regression<\/strong>.<\/p>\n\n\n\n<p>Before going on it&#8217;s recommended you know how to use commonly used libraries like NumPy, pandas, etc. You can learn about them <strong><a class=\"rank-math-link\" href=\"https:\/\/copyassignment.com\/machine-learning-a-gentle-introduction\/\">here<\/a><\/strong>.<\/p>\n\n\n\n\n\n<h2 class=\"wp-block-heading\">Purpose of Machine Learning<\/h2>\n\n\n\n<p>So let&#8217;s say John is a developer who is given a task to find the yield of crops given the amount of rain and temperature throughout the year. John tried finding the relation between yield and other factors and hard code an expression to find the yield. John is exceptional at math and found an expression takes predicts this with decent accuracy. The Boss was happy! <\/p>\n\n\n\n<p>Next data he is assigned another project where now he has to find if a person has diabetes or not based on given data. Well as intelligent as John is he got really tired after yesterday. He still took the same approach and submitted his project.<\/p>\n\n\n\n\n\n<p>Did you notice how John had to find the best-fit expression for the data every time he is given data? If only there was a way to predict the value for any dataset without recoding everything and there is! And that&#8217;s what Machine Learning can do.<\/p>\n\n\n\n<p><strong>Machine learning<\/strong> allows an algorithm to become more accurate at predicting outcomes without being explicitly programmed to do so. Predicting is one of the things that ML can do but actually, you can do much more cool stuff with it too and once you go deep into it you&#8217;ll learn all about it.<\/p>\n\n\n\n<p>So until now, we&#8217;ve done a lot of things with data. We&#8217;ve handled missing values, handled string data and we&#8217;ll learn to do much more cool stuff in the future. But why? Why does it?  To put it simply when you train a model you need the data to be all numerical, there shouldn&#8217;t be missing values or strings. Um Ok! But why analyze the data? <\/p>\n\n\n\n<p>The purpose of analyses is to find important features and the useless ones that were destined to be removed in order to improve the quality of data, by removing any unnecessary feature that might hinder the training algorithm.<\/p>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<h2 class=\"wp-block-heading\">Types of Machine Learning Problems<\/h2>\n\n\n\n<p>In machine learning, you&#8217;ll usually work with predicting an outcome, and based on what you are predicting you can classify an ML problem in two:-<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Regression:<\/strong> Predicting a Continuous Value.<\/li><li><strong>Classification:<\/strong> Predicting a Discrete Class.<\/li><\/ul>\n\n\n\n<p>Let&#8217;s say you have to predict the stock price, this is a <strong>regression <\/strong>problem since the stock price is a continuous value. Now let&#8217;s say you have to predict the breed of a dog, this is a <strong>classification<\/strong> problem.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Linear Regression?<\/h2>\n\n\n\n<p>Alright, so we are all set to learn our first ML algorithm, yay! So what exactly is Linear Regression? <strong>Linear Regression<\/strong>&nbsp;is a machine learning algorithm based on&nbsp;<strong>supervised learning<\/strong>. It basically performs a&nbsp;regression task. It is mostly used for finding out the relationship between variables. Linear regression models differ based on the kind of relationship between dependent and independent variables they are considering, and the number of independent variables getting used.<\/p>\n\n\n\n<p>Some of the assumptions of Linear Regression are,<\/p>\n\n\n\n<ul class=\"wp-block-list\" id=\"block-c4e3ddaf-694f-4292-9855-83c3a8117d91\"><li><strong>Linear relationship:<\/strong> Assumes the relationship between the features and target is linear.<\/li><li><strong>Multivariate normality:<\/strong>&nbsp;Assumes all variables are multivariate normal. It&#8217;s basically a generalization of normal distribution over higher dimensions.<\/li><li><strong>No or little multicollinearity<\/strong>: &nbsp;Multicollinearity occurs when the independent variables are too highly correlated with each other.<\/li><\/ul>\n\n\n\n<p>Now, let&#8217;s understand the long answer, imagine you have the following dataset:-<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">x<\/td><td class=\"has-text-align-center\" data-align=\"center\">y<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">1<\/td><td class=\"has-text-align-center\" data-align=\"center\">2<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">2<\/td><td class=\"has-text-align-center\" data-align=\"center\">3<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">3<\/td><td class=\"has-text-align-center\" data-align=\"center\">2<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">5<\/td><td class=\"has-text-align-center\" data-align=\"center\">4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>So the above data is pretty simple x is our input and y is the output. Now we have the task of predicting y given x. Before moving ahead let&#8217;s plot it.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><div style=\"position:absolute;top:-20px;right:0px;cursor:pointer\" class=\"copy-simple-code-block\"><span class=\"dashicon dashicons dashicons-admin-page\"><\/span><\/div><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"true\">import numpy as np\nimport matplotlib.pyplot as plt\n\nX = np.array([1,2,3,5])\nY = np.array([2,3,2,4])\n\nplt.scatter(X,Y)\nplt.show()<\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"382\" height=\"249\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/image-55.png\" alt=\"Linear Regression: Your 1st Step in Machine Learning\" class=\"wp-image-6506 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/image-55.png 382w, https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/image-55-300x196.png 300w\" data-sizes=\"(max-width: 382px) 100vw, 382px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 382px; --smush-placeholder-aspect-ratio: 382\/249;\" \/><figcaption>Plot of data<\/figcaption><\/figure>\n\n\n\n<p>So as we can see there is no particular relation between x and y. But in linear regression,<strong> <\/strong>we assume a linear relationship between inputs and output and try to find the line that best fits the curve. But what does <strong>best fit the data<\/strong> mean? Well, we try to find the line that gives us the best prediction for the given dataset. <\/p>\n\n\n\n<p>But how do we define the best prediction? Well, we take a metric and the line that gives the best value for that metric is our <strong>best fit line for the data.<\/strong> For regression, we generally use metrics like RMSE, MAE, etc.<\/p>\n\n\n\n<p>For the above dataset, the best line is <strong>y = 0.43<em>x<\/em>&nbsp;+ 1.57<\/strong>. That is the equation of the line that best fits the above-given dataset and as we can our dataset the value of the line changes too. That basically means that most of the points in the dataset should be on or near the line. Let&#8217;s plot this line and verify.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><div style=\"position:absolute;top:-20px;right:0px;cursor:pointer\" class=\"copy-simple-code-block\"><span class=\"dashicon dashicons dashicons-admin-page\"><\/span><\/div><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"true\">X = np.array([1,2,3,5])\nY = np.array([2,3,2,4])\n\ny = lambda x: 0.43*x + 1.57\nline = np.array([y(x) for x in range(7)])\n\nplt.plot(line)\nplt.scatter(X,Y)\nplt.show()<\/pre><\/div>\n\n\n\n<p> <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"388\" height=\"254\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/image-56.png\" alt=\"Plotting the line\" class=\"wp-image-6507 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/image-56.png 388w, https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/image-56-300x196.png 300w\" data-sizes=\"(max-width: 388px) 100vw, 388px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 388px; --smush-placeholder-aspect-ratio: 388\/254;\" \/><figcaption>Plotting the line<\/figcaption><\/figure>\n\n\n\n<p>That seems fine, I mean there can be infinite lines but the one that best fits the given dataset is this one. And that&#8217;s what linear regression does it takes some set of input and linearly maps it to the output. Cool! So how do we find this line? Let&#8217;s see.<\/p>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<h2 class=\"wp-block-heading\">Working on Linear Regression<\/h2>\n\n\n\n<p>So in the above dataset, we have 2 variables x and y. So the equation of line we need to find is of form <br><strong>y = m*x + c, <\/strong>but we&#8217;ll write it as:-<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/image-58.png\" alt=\"Linear equation formula\" class=\"wp-image-6509 lazyload\" width=\"186\" height=\"34\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 186px; --smush-placeholder-aspect-ratio: 186\/34;\" \/><figcaption>Linear equation formula<\/figcaption><\/figure>\n<\/div>\n\n\n<p>\u03b8<sub>o<\/sub> and \u03b8<sub>1<\/sub> are the same as c and m we&#8217;ll call them parameters. Our job is to find the value of parameters such that our hypothesis, h\u03b8(x), minimizes the RMSE value. RMSE is called Root Mean Squared Error and it&#8217;s calculated by the following formula:-<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img decoding=\"async\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/1-1.png\" alt=\"Root Mean Squared Error\" class=\"wp-image-15960 lazyload\" width=\"253\" height=\"65\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/1-1.png 505w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/1-1-300x77.png 300w\" data-sizes=\"(max-width: 253px) 100vw, 253px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 253px; --smush-placeholder-aspect-ratio: 253\/65;\" \/><figcaption>Root Mean Squared Error<\/figcaption><\/figure>\n<\/div>\n\n\n<p>Now we have 2 ways to go about it:-<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Gradient Descent<\/li><li>Ordinary Least Square<\/li><\/ol>\n\n\n\n<p>Now, since in sklearn Linear Regression is done by OLS I&#8217;ll explain that since I&#8217;ll talk about Gradient Descent in the next article. For the above hypothesis we can find the parameters with the following formula:-<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img decoding=\"async\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/2-1.png\" alt=\"Ordinary Least Square\" class=\"wp-image-15970 lazyload\" width=\"162\" height=\"35\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/2-1.png 324w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/2-1-300x65.png 300w\" data-sizes=\"(max-width: 162px) 100vw, 162px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 162px; --smush-placeholder-aspect-ratio: 162\/35;\" \/><figcaption>Ordinary Least Square<\/figcaption><\/figure>\n<\/div>\n\n\n<p>Now let&#8217;s try doing OLS on the above dataset:-<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><div style=\"position:absolute;top:-20px;right:0px;cursor:pointer\" class=\"copy-simple-code-block\"><span class=\"dashicon dashicons dashicons-admin-page\"><\/span><\/div><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"true\">n = len(X)\ntheta_1 = ((n * (X*Y).sum()) - (X.sum() * Y.sum())) \/ ((n * (X**2).sum()) - X.sum()**2)\ntheta_0 = (Y.sum() - theta_1 * X.sum()) \/ n\nprint(theta_1, theta_0)<\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/3-1.png\" alt=\"Output of LInear regression formula\" class=\"wp-image-15971 lazyload\" width=\"380\" height=\"36\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/3-1.png 380w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/3-1-300x28.png 300w\" data-sizes=\"(max-width: 380px) 100vw, 380px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 380px; --smush-placeholder-aspect-ratio: 380\/36;\" \/><figcaption>Output of OLS<\/figcaption><\/figure>\n\n\n\n<p>Well, the values look the same as we expected. But one thing to understand is that the above formula works only for data set where we have only one feature column. But in the real world that rarely happens so what about n feature columns? <\/p>\n\n\n\n<p>Now we have a dataset with 2 features. Now let&#8217;s call this the <strong>X matrix<\/strong> now we have an X matrix with a shape (4,2) and let another matrix <strong>\u03b8<\/strong> <strong>matrix<\/strong> which looks like [[\u03b8<sub>1<\/sub>, \u03b8<sub>o<\/sub>]] and has a shape (1,2). Now we can write the hypothesis as the matrix multiplication of \u03b8<sup>T<\/sup>, i.e. transpose of <strong>\u03b8 matrix<\/strong>, and <strong>X matrix<\/strong> like:- <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/image-65.png\" alt=\"\" class=\"wp-image-6517 lazyload\" width=\"165\" height=\"41\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 165px; --smush-placeholder-aspect-ratio: 165\/41;\" \/><\/figure>\n<\/div>\n\n\n<p>x<sub>o<\/sub> is still the column with all values as 1 and it can be rewritten as the matrix multiplication of \u03b8<sup>T<\/sup> and X.<\/p>\n\n\n\n<p>Now that we know how it works let&#8217;s understand how we can code it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation of Linear Regression using sklearn<\/h2>\n\n\n\n<p>To implement Linear Regression we use a library called sklearn and it comes installed in Anaconda. Linear Regression is present in sklearn under linear_model. In\u00a0this\u00a0section,\u00a0we\u00a0will\u00a0see\u00a0how\u00a0the\u00a0Python\u00a0Scikit-Learn\u00a0library\u00a0for\u00a0machine\u00a0learning\u00a0can\u00a0be\u00a0used\u00a0to\u00a0implement\u00a0regression\u00a0functions.\u00a0We\u00a0will\u00a0start\u00a0with\u00a0<br>simple\u00a0linear\u00a0regression\u00a0involving\u00a0two\u00a0variables.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Loading the data<\/h3>\n\n\n\n<p>In\u00a0this\u00a0regression\u00a0task,\u00a0we\u00a0will\u00a0predict\u00a0the\u00a0percentage\u00a0of\u00a0marks\u00a0that\u00a0a\u00a0student\u00a0is\u00a0expected\u00a0to\u00a0score\u00a0based\u00a0<br>on\u00a0the\u00a0number\u00a0of\u00a0hours\u00a0they\u00a0studied.\u00a0You can download the data <a href=\"https:\/\/github.com\/keerthanabuvan\/Linear-Regression\" data-type=\"URL\" data-id=\"https:\/\/github.com\/keerthanabuvan\/Linear-Regression\" target=\"_blank\" rel=\"noreferrer noopener\">here.<\/a> This\u00a0is\u00a0a\u00a0simple\u00a0linear\u00a0regression\u00a0task\u00a0as\u00a0it\u00a0involves\u00a0just\u00a0two\u00a0variables. So let&#8217;s start by importing the libraries and loading the data.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><div style=\"position:absolute;top:-20px;right:0px;cursor:pointer\" class=\"copy-simple-code-block\"><span class=\"dashicon dashicons dashicons-admin-page\"><\/span><\/div><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"true\"># Importing the required libraries\nimport pandas as pd\nimport numpy as np  \nimport matplotlib.pyplot as plt  \n%matplotlib inline\n\n# Loading the data\ns_data = pd.read_csv(\"data.csv\")\ns_data.head()<\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"268\" height=\"212\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/4-1.png\" alt=\"\" class=\"wp-image-15991 lazyload\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 268px; --smush-placeholder-aspect-ratio: 268\/212;\" \/><\/figure>\n\n\n\n<div style=\"text-align:center\" class=\"wp-block-atomic-blocks-ab-button ab-block-button\"><a href=\"https:\/\/copyassignment.com\/top-100-python-projects-with-source-code\/\" class=\"ab-button ab-button-shape-rounded ab-button-size-medium\" style=\"color:#ffffff;background-color:#3373dc\">Best 100+ Python Projects with source code<\/a><\/div>\n\n\n\n<p>Let&#8217;s\u00a0plot\u00a0our\u00a0data\u00a0points\u00a0on\u00a0the 2D\u00a0graph\u00a0to\u00a0eyeball\u00a0our\u00a0dataset\u00a0and\u00a0see\u00a0if\u00a0we\u00a0can\u00a0manually\u00a0find\u00a0any\u00a0<br>relationship\u00a0between\u00a0the\u00a0data.\u00a0We\u00a0can\u00a0create\u00a0the\u00a0plot\u00a0with\u00a0the\u00a0following\u00a0lines of code<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\"># Plotting the distribution of scores in a graph\ns_data.plot(x='Hours', y='Scores', style='o')  \nplt.title('Hours vs Percentage')  \nplt.xlabel('Hours Studied')  \nplt.ylabel('Percentage Score')  \nplt.show()<\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"491\" height=\"292\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/5-1.png\" alt=\"Plotting the dat\" class=\"wp-image-15992 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/5-1.png 491w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/5-1-300x178.png 300w\" data-sizes=\"(max-width: 491px) 100vw, 491px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 491px; --smush-placeholder-aspect-ratio: 491\/292;\" \/><figcaption>Hour vs Percentage graph<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Linear Regression model<\/h3>\n\n\n\n<p>Now that we have our data let&#8217;s create our LinearRegression object and train it on the data. To train the data we use the <strong>fit() <\/strong>method. Let&#8217;s do it.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><div style=\"position:absolute;top:-20px;right:0px;cursor:pointer\" class=\"copy-simple-code-block\"><span class=\"dashicon dashicons dashicons-admin-page\"><\/span><\/div><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"true\">from sklearn.linear_model import LinearRegression\n\nreg = LinearRegression()\nreg.fit(X,Y)<\/pre><\/div>\n\n\n\n<p>From\u00a0the\u00a0graph\u00a0above,\u00a0we\u00a0can\u00a0clearly\u00a0see\u00a0that\u00a0there\u00a0is\u00a0a\u00a0positive\u00a0linear\u00a0relationship\u00a0between\u00a0the\u00a0number\u00a0of\u00a0hours\u00a0studied\u00a0and\u00a0percentage\u00a0of\u00a0the score.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Splitting the data<\/h3>\n\n\n\n<p>The\u00a0next\u00a0step\u00a0is\u00a0to\u00a0divide\u00a0the\u00a0data\u00a0into\u00a0&#8220;attributes&#8221;\u00a0(inputs)\u00a0and\u00a0&#8220;labels&#8221;\u00a0(outputs). Now\u00a0that\u00a0we\u00a0have\u00a0our\u00a0attributes\u00a0and\u00a0labels,\u00a0the\u00a0next\u00a0step\u00a0is\u00a0to\u00a0split\u00a0this\u00a0data\u00a0into\u00a0training\u00a0and\u00a0test\u00a0sets.\u00a0We&#8217;ll\u00a0do\u00a0this\u00a0by\u00a0using\u00a0Scikit-Learn&#8217;s\u00a0built-in\u00a0train_test_split()\u00a0method:<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">X = s_data.iloc[:, :-1].values  \ny = s_data.iloc[:, 1].values  \n\nfrom sklearn.model_selection import train_test_split  \nX_train, X_test, y_train, y_test = train_test_split(X, y, \n                            test_size=0.2, random_state=0) <\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Training the model<\/h3>\n\n\n\n<p>We&nbsp;have&nbsp;split&nbsp;our&nbsp;data&nbsp;into&nbsp;training&nbsp;and&nbsp;testing&nbsp;sets,&nbsp;and&nbsp;now&nbsp;is&nbsp;finally&nbsp;the&nbsp;time&nbsp;to&nbsp;train&nbsp;our&nbsp;algorithm.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><div style=\"position:absolute;top:-20px;right:0px;cursor:pointer\" class=\"copy-simple-code-block\"><span class=\"dashicon dashicons dashicons-admin-page\"><\/span><\/div><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"true\">from sklearn.linear_model import LinearRegression  \nregressor = LinearRegression()  \nregressor.fit(X_train, y_train)\n\n# Plotting the regression line\nline = regressor.coef_*X+regressor.intercept_\n\n# Plotting for the test data\nplt.scatter(X, y)\nplt.plot(X, line);\nplt.show()<\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"472\" height=\"259\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/6-1.png\" alt=\"Graph for the test data\" class=\"wp-image-15993 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/6-1.png 472w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/6-1-300x165.png 300w\" data-sizes=\"(max-width: 472px) 100vw, 472px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 472px; --smush-placeholder-aspect-ratio: 472\/259;\" \/><figcaption>Graph for the test data<\/figcaption><\/figure>\n\n\n\n<p>Now&nbsp;that&nbsp;we&nbsp;have&nbsp;trained&nbsp;our&nbsp;algorithm,&nbsp;it&#8217;s&nbsp;time&nbsp;to&nbsp;make&nbsp;some&nbsp;predictions.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\"># Testing the data\nprint(X_test)\n<\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"116\" height=\"105\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/7-1.png\" alt=\"\" class=\"wp-image-15994 lazyload\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 116px; --smush-placeholder-aspect-ratio: 116\/105;\" \/><figcaption>Output for test data<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Predicting the outcome<\/h3>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\"># Predicting the scores\ny_pred = regressor.predict(X_test) \n\n# Comparing Actual vs Predicted\ndf = pd.DataFrame({'Actual': y_test, 'Predicted': y_pred})  \ndf <\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"268\" height=\"202\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/8-1.png\" alt=\"Comparison of actual and predicted output\" class=\"wp-image-15995 lazyload\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 268px; --smush-placeholder-aspect-ratio: 268\/202;\" \/><figcaption>Comparison of actual and predicted output<\/figcaption><\/figure>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\"># You can also test with your own data\nhour = [[9.25]]\nown_pred = regressor.predict(hour)\nprint(\"No of Hours = {}\".format(hour))\nprint(\"Predicted Score = {}\".format(own_pred[0]))<\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"419\" height=\"59\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/9-1.png\" alt=\"\" class=\"wp-image-15996 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/9-1.png 419w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/9-1-300x42.png 300w\" data-sizes=\"(max-width: 419px) 100vw, 419px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 419px; --smush-placeholder-aspect-ratio: 419\/59;\" \/><figcaption>The output of custom input<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Evaluating the results<\/h3>\n\n\n\n<p>The\u00a0final\u00a0step\u00a0is\u00a0to\u00a0evaluate\u00a0the\u00a0performance\u00a0of\u00a0the algorithm. This\u00a0step\u00a0is\u00a0particularly\u00a0important\u00a0to\u00a0compare\u00a0how\u00a0well\u00a0different\u00a0algorithms\u00a0perform\u00a0on\u00a0a\u00a0particular\u00a0dataset.\u00a0For\u00a0simplicity\u00a0here,\u00a0we\u00a0have\u00a0chosen\u00a0the\u00a0mean\u00a0square\u00a0error.\u00a0There\u00a0are\u00a0many\u00a0such\u00a0metrics.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\"># Calculating the mean absolute error\nfrom sklearn import metrics  \nprint('Mean Absolute Error:', \n      metrics.mean_absolute_error(y_test, y_pred)) <\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"383\" height=\"39\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/10.png\" alt=\"Output of Mean Absolute error\" class=\"wp-image-15997 lazyload\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/10.png 383w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/08\/10-300x31.png 300w\" data-sizes=\"(max-width: 383px) 100vw, 383px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 383px; --smush-placeholder-aspect-ratio: 383\/39;\" \/><figcaption>Output of Mean Absolute error<\/figcaption><\/figure>\n\n\n\n<p>Congrats! You just coded your first ML model. It&#8217;s not the best result but we&#8217;ll learn more as we go on.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Advantages of Linear Regression<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>The implementation of Linear regression is very simple.<\/li><li>Linear regression fits linearly separable datasets almost perfectly and is often used to find the nature of the relationship between variables.<\/li><li>In Linear regression, the Overfitting of data can be reduced by regularization<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Disadvantages of Linear Regression<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>The linear regression algorithm is prone to underfitting<\/li><li>It is sensitive to outliers<\/li><li>The linear Regression algorithm assumes that the data is independent<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Linear Regression Algorithm | Linear Regression in Python | Machine Learning Algorithm | Edureka\" width=\"500\" height=\"281\" data-src=\"https:\/\/www.youtube.com\/embed\/E5RjzSK0fvY?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>Credits to&nbsp;<a href=\"https:\/\/www.youtube.com\/channel\/UCkw4JCwteGrDHIsyIIKo4tQ\" class=\"rank-math-link\">edureka!<\/a><\/p>\n\n\n\n<div style=\"text-align:center\" class=\"wp-block-atomic-blocks-ab-button ab-block-button\"><a href=\"https:\/\/copyassignment.com\/top-100-python-projects-with-source-code\/\" class=\"ab-button ab-button-shape-rounded ab-button-size-medium\" style=\"color:#ffffff;background-color:#3373dc\">Best 100+ Python Projects with source code<\/a><\/div>\n\n\n\n<p style=\"font-size:30px\"><strong>Thank for reading<\/strong><\/p>\n\n\n\n<p style=\"font-size:28px\"><strong>Keep Learning<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>Tell us if you have any queries or if you found something wrong in this article.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p style=\"font-size:28px\"><strong>Also Read:<\/strong><\/p>\n\n\n<ul class=\"wp-block-latest-posts__list wp-block-latest-posts\"><li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/machine-learning-a-gentle-introduction\/\" aria-label=\"Machine Learning: A Gentle Introduction\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Machine-Learning-A-Gentle-Introduction-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"Machine Learning: A Gentle Introduction\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Machine-Learning-A-Gentle-Introduction-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Machine-Learning-A-Gentle-Introduction-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Machine-Learning-A-Gentle-Introduction-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/machine-learning-a-gentle-introduction\/\">Machine Learning: A Gentle Introduction<\/a><div class=\"wp-block-latest-posts__post-excerpt\">Introduction to Machine Learning Machine Learning is probably one of the most interesting and hyped branches of computer science. The thing that separates humans from machines is the fact that humans learn from their experiences. But is it possible to make a machine learn? And The answer is Yes! It is possible through Machine Learning&#8230;.<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/machine-learning-course-description\/\" aria-label=\"Machine Learning Course Description\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Machine-Learning-Course-Description-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"Machine Learning Course Description\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Machine-Learning-Course-Description-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Machine-Learning-Course-Description-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Machine-Learning-Course-Description-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/machine-learning-course-description\/\">Machine Learning Course Description<\/a><div class=\"wp-block-latest-posts__post-excerpt\">Before you start, let me give you an overview of what this series has to offer you. Our machine learning course series comprises of the following sections:- ML Environment Setup and Overview Jupyter Notebook: The Ultimate Guide Numpy Pandas Matplotlib Seaborn Sklearn Linear Regression Logistic Regression Decision Tree Random Forest Support Vector Machine K Nearest&#8230;<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/ml-environment-setup-and-overview\/\" aria-label=\"ML Environment Setup and Overview\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/ML-Environment-Setup-and-Overview-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"ML Environment Setup and Overview\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/ML-Environment-Setup-and-Overview-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/ML-Environment-Setup-and-Overview-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/ML-Environment-Setup-and-Overview-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/ml-environment-setup-and-overview\/\">ML Environment Setup and Overview<\/a><div class=\"wp-block-latest-posts__post-excerpt\">Introduction to Machine Learning In this article, you will learn about the ML Environment Setup, Machine Learning terminology, its paradigms, and a tutorial to help you set up your machine so you can code what you learn. Before we start with our ML Environment Setup, read this article to get an overview of machine learning&#8230;.<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/jupyter-notebook-the-ultimate-guide\/\" aria-label=\"Jupyter Notebook: The Ultimate Guide\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Jupyter-Notebook-The-Ultimate-Guide-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"Jupyter Notebook: The Ultimate Guide\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Jupyter-Notebook-The-Ultimate-Guide-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Jupyter-Notebook-The-Ultimate-Guide-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Jupyter-Notebook-The-Ultimate-Guide-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/jupyter-notebook-the-ultimate-guide\/\">Jupyter Notebook: The Ultimate Guide<\/a><div class=\"wp-block-latest-posts__post-excerpt\">Introduction to Jupyter Notebook Whenever one starts programming the first aim of that person is to find an IDE that suits his\/her needs. In ML there are times when you&#8217;ll want to keep a check on your data after doing a change. But in code editors like Vim, Vscode, etc. you have to run your&#8230;<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/numpy-for-machine-learning-a-complete-guide\/\" aria-label=\"Numpy For Machine Learning: A Complete Guide\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Numpy-For-Machine-Learning-A-Complete-Guide-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"Numpy For Machine Learning: A Complete Guide\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Numpy-For-Machine-Learning-A-Complete-Guide-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Numpy-For-Machine-Learning-A-Complete-Guide-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Numpy-For-Machine-Learning-A-Complete-Guide-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/numpy-for-machine-learning-a-complete-guide\/\">Numpy For Machine Learning: A Complete Guide<\/a><div class=\"wp-block-latest-posts__post-excerpt\">Up until now you&#8217;ve learned about the general idea of what ML does, set up your environment, and got to know about the working of your coding environment i.e. Jupyter Notebook. In this section, you&#8217;ll learn about a very powerful library called Numpy. We&#8217;ll learn about Numpy Array(np array for short) and operations on them,&#8230;<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/python-pandas-tutorial-complete-introduction\/\" aria-label=\"Python Pandas Tutorial: A Complete Introduction for Beginners\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Python-Pandas-Tutorial-A-Complete-Introduction-for-Beginners-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"Python Pandas Tutorial: A Complete Introduction for Beginners\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Python-Pandas-Tutorial-A-Complete-Introduction-for-Beginners-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Python-Pandas-Tutorial-A-Complete-Introduction-for-Beginners-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Python-Pandas-Tutorial-A-Complete-Introduction-for-Beginners-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/python-pandas-tutorial-complete-introduction\/\">Python Pandas Tutorial: A Complete Introduction for Beginners<\/a><div class=\"wp-block-latest-posts__post-excerpt\">In the previous section, we learned about Numpy and how we can use it to load, save, and pre-process data easily by using Numpy Arrays. Now Numpy is a great library to do data preprocessing but I&#8217;d like to tell you all about another wonderful Python library called Pandas. At the end of this tutorial,&#8230;<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/matplotlib-python-a-beginners-walkthrough\/\" aria-label=\"Matplotlib Python: A Beginner&#8217;s Walkthrough\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Matplotlib-Python-A-Beginners-Walkthrough-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"Matplotlib Python: A Beginner&#039;s Walkthrough\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Matplotlib-Python-A-Beginners-Walkthrough-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Matplotlib-Python-A-Beginners-Walkthrough-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Matplotlib-Python-A-Beginners-Walkthrough-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/matplotlib-python-a-beginners-walkthrough\/\">Matplotlib Python: A Beginner&#8217;s Walkthrough<\/a><div class=\"wp-block-latest-posts__post-excerpt\">We know how to analyze data by analyzing the statistics of the data and we&#8217;ve learned how to manipulate the data. But is statistics enough to analyze the data? Short answer, Visualization of data is necessary in order to find details that we missed that&#8217;s why Matplotlib Python is the best library to visualize data&#8230;<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/seaborn-create-elegant-plots\/\" aria-label=\"Seaborn: Create Elegant Plots\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/PANDAs-4-768x432-1-150x150.png\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"Seaborn: Create Elegant Plots\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/PANDAs-4-768x432-1-150x150.png 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/PANDAs-4-768x432-1-100x100.png 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/seaborn-create-elegant-plots\/\">Seaborn: Create Elegant Plots<\/a><div class=\"wp-block-latest-posts__post-excerpt\">In the previous tutorial, we learned why data visualization is important and how we can create plots using matplotlib. In this tutorial, we&#8217;ll learn about another data visualization library called Seaborn, which is built on top of matplotlib. But why do we need seaborn if we have matplotlib? Using seaborn you can make plots that&#8230;<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/set-up-python-environment\/\" aria-label=\"Set up Python Environment\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Set-up-Python-Environment-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"Set up Python Environment\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Set-up-Python-Environment-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Set-up-Python-Environment-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Set-up-Python-Environment-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/set-up-python-environment\/\">Set up Python Environment<\/a><div class=\"wp-block-latest-posts__post-excerpt\">Now, it&#8217;s time to install the tools that we will use to write programs. So, we will be learning to Set up Python Environment in this article. Let&#8217;s start. 1. Installing Python first. First, we need to go to the official site of python: https:\/\/www.python.org\/ Now we need to go to the downloads page of&#8230;<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/linear-regression-machine-learning\/\" aria-label=\"Linear Regression: Your 1st Step in Machine Learning\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/Linear-Regression-Machine-Learning-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"Linear Regression Machine Learning\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/Linear-Regression-Machine-Learning-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/Linear-Regression-Machine-Learning-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/Linear-Regression-Machine-Learning-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/linear-regression-machine-learning\/\">Linear Regression: Your 1st Step in Machine Learning<\/a><div class=\"wp-block-latest-posts__post-excerpt\">Hi guys! So until now, we&#8217;ve learned about how we can use libraries to play with data. We did data analysis on a real dataset and we also learned how to visualize data. But what was the purpose behind it? Why do so many things? What are we trying to achieve? I&#8217;ll tell you all&#8230;<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/gradient-descent-linear-regression\/\" aria-label=\"Gradient Descent: Another Approach to Linear Regression\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Gradient-Descent-Another-Approach-to-Linear-Regression-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"Gradient Descent: Another Approach to Linear Regression\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Gradient-Descent-Another-Approach-to-Linear-Regression-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Gradient-Descent-Another-Approach-to-Linear-Regression-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/06\/Gradient-Descent-Another-Approach-to-Linear-Regression-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/gradient-descent-linear-regression\/\">Gradient Descent: Another Approach to Linear Regression<\/a><div class=\"wp-block-latest-posts__post-excerpt\">In the last tutorial, we learned about our first ML algorithm called Linear Regression. We did it using an approach called Ordinary Least Squares, but there is another way to approach it. It is an approach that becomes the basis of Neural Networks, and it&#8217;s called Gradient Descent. And don&#8217;t get intimidated by the name&#8230;<\/div><\/li>\n<li><div class=\"wp-block-latest-posts__featured-image alignleft\"><a href=\"https:\/\/copyassignment.com\/logistic-regression-machine-learning\/\" aria-label=\"Logistic Regression: Regression Model for Classification\"><img decoding=\"async\" width=\"150\" height=\"150\" data-src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/Untitled-7-150x150.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image lazyload\" alt=\"Logistic Regression: Regression Model for Classification\" data-srcset=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/Untitled-7-150x150.jpg 150w, https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/Untitled-7-600x600.jpg 600w, https:\/\/copyassignment.com\/wp-content\/uploads\/2021\/01\/Untitled-7-100x100.jpg 100w\" data-sizes=\"(max-width: 150px) 100vw, 150px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 150px; --smush-placeholder-aspect-ratio: 150\/150;\" \/><\/a><\/div><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/logistic-regression-machine-learning\/\">Logistic Regression: Regression Model for Classification<\/a><div class=\"wp-block-latest-posts__post-excerpt\">We will discuss Logistic Regression: Regression Model for Classification in this article, but let us see what we did in the past couple of articles, we discussed how we can use an ML algorithm called Linear Regression to predict continuous values by training it over a training dataset. We talked about 2 ways to do&#8230;<\/div><\/li>\n<\/ul>\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n","protected":false},"excerpt":{"rendered":"<p>Hi guys! So until now, we&#8217;ve learned about how we can use libraries to play with data. We did data analysis on a real dataset&#8230;<\/p>\n","protected":false},"author":62,"featured_media":16090,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,1137],"tags":[1199,1120,1750],"class_list":["post-6477","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-allcategorites","category-machine-learning","tag-linear-regression-your-1st-step-in-machine-learning","tag-machine-learning","tag-machine-learning-algorithms","wpcat-22-id","wpcat-1137-id"],"_links":{"self":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/posts\/6477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/users\/62"}],"replies":[{"embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/comments?post=6477"}],"version-history":[{"count":0,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/posts\/6477\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/media\/16090"}],"wp:attachment":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/media?parent=6477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/categories?post=6477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/tags?post=6477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}