{"id":3190,"date":"2024-05-28T19:44:47","date_gmt":"2024-05-28T14:44:47","guid":{"rendered":"https:\/\/afzalbadshah.com\/?p=3190"},"modified":"2024-05-28T19:47:47","modified_gmt":"2024-05-28T14:47:47","slug":"introduction-to-linear-regression-exploring-the-secrets-of-prediction","status":"publish","type":"post","link":"https:\/\/afzalbadshah.com\/index.php\/2024\/05\/28\/introduction-to-linear-regression-exploring-the-secrets-of-prediction\/","title":{"rendered":"Introduction to Linear Regression: Exploring the Secrets of Prediction"},"content":{"rendered":"\n<p>Linear regression is a fundamental machine learning algorithm used for predicting a continuous outcome based on one or more input features. It assumes a linear relationship between the input features and the target variable, making it easy to interpret and implement. <a href=\"https:\/\/afzalbadshah.com\/index.php\/category\/courses\/data-science\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Visit the detailed tutorial here. <\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"640\" height=\"360\" src=\"https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/05\/2-1024x576.webp?resize=640%2C360&#038;ssl=1\" alt=\"\" class=\"wp-image-3224\" srcset=\"https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/05\/2-jpg.webp?resize=1024%2C576&amp;ssl=1 1024w, https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/05\/2-jpg.webp?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/05\/2-jpg.webp?resize=768%2C432&amp;ssl=1 768w, https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/05\/2-jpg.webp?resize=1536%2C864&amp;ssl=1 1536w, https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/05\/2-jpg.webp?resize=480%2C270&amp;ssl=1 480w, https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/05\/2-jpg.webp?w=1920&amp;ssl=1 1920w, https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/05\/2-jpg.webp?w=1280&amp;ssl=1 1280w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><figcaption class=\"wp-element-caption\">Linear regression<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Types of Linear Regression<\/h3>\n\n\n\n<p>There are two main types of linear regression:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Simple Linear Regression<\/h4>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"640\" height=\"360\" src=\"https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/05\/7-1024x576.webp?resize=640%2C360&#038;ssl=1\" alt=\"\" class=\"wp-image-3510\" srcset=\"https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/05\/7-jpg.webp?resize=1024%2C576&amp;ssl=1 1024w, https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/05\/7-jpg.webp?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/05\/7-jpg.webp?resize=768%2C432&amp;ssl=1 768w, https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/05\/7-jpg.webp?resize=1536%2C864&amp;ssl=1 1536w, https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/05\/7-jpg.webp?resize=480%2C270&amp;ssl=1 480w, https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/05\/7-jpg.webp?w=1920&amp;ssl=1 1920w, https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/05\/7-jpg.webp?w=1280&amp;ssl=1 1280w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p>Simple linear regression models the relationship between one independent variable and the dependent variable using a linear equation. For example, predicting house prices based on square footage.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Multiple Linear Regression<\/h4>\n\n\n\n<p>Multiple linear regression models the relationship between multiple independent variables and the dependent variable using a linear equation. Predicting house prices based on square footage, number of bedrooms, and location.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example: Predicting House Prices<\/h3>\n\n\n\n<p>Let&#8217;s consider a real estate scenario where we want to predict house prices based on various features. We have a dataset containing the following features: square footage, number of bedrooms, and location (represented as dummy variables for different neighbourhoods), along with the corresponding house prices.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Square Footage (X1)<\/th><th>Number of Bedrooms (X2)<\/th><th>Location (X3, X4, X5)<\/th><th>Price (y)<\/th><\/tr><\/thead><tbody><tr><td>1500<\/td><td>3<\/td><td>1 0 0<\/td><td>250,000<\/td><\/tr><tr><td>2000<\/td><td>4<\/td><td>0 1 0<\/td><td>300,000<\/td><\/tr><tr><td>1800<\/td><td>3<\/td><td>0 0 1<\/td><td>280,000<\/td><\/tr><tr><td>2200<\/td><td>4<\/td><td>1 0 0<\/td><td>320,000<\/td><\/tr><tr><td>1600<\/td><td>3<\/td><td>0 1 0<\/td><td>270,000<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Steps to Build a Linear Regression Model<\/h3>\n\n\n\n<p>Here are the steps to build a linear regression model for this example:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Data Visualization<\/h4>\n\n\n\n<p>Plot the data points on scatter plots to visualize the relationships between the independent variables and the target variable (house prices).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Model Training<\/h4>\n\n\n\n<p>For simple linear regression, fit a model to predict house prices based on square footage. For multiple linear regression, fit a model to predict house prices based on square footage, number of bedrooms, and location.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Model Evaluation<\/h4>\n\n\n\n<p>Evaluate the performance of each model using metrics like Mean Squared Error (MSE) or R-squared. Compare the performance of the simple and multiple regression models.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Prediction<\/h4>\n\n\n\n<p>Use the trained models to make predictions on new, unseen data. For example, predict the price of a house with 1800 square feet, 3 bedrooms, and located in the first neighbourhood.<\/p>\n\n\n\n<p>Linear regression is a versatile algorithm for predicting continuous outcomes based on input features. By understanding the differences between simple and multiple linear regression and applying them to real-world scenarios, students can effectively use linear regression for various prediction tasks, such as predicting house prices based on square footage, number of bedrooms, and location.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Material<\/h2>\n\n\n\n<p><a href=\"https:\/\/drive.google.com\/file\/d\/1Mhay5KIVsiQwDKPtlARzzfqO_248Nw1M\/view?usp=sharing\" target=\"_blank\" rel=\"noopener\" title=\"\">Download the presentation here.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linear regression is a fundamental machine learning algorithm used for predicting a continuous outcome based on one or more input features. It assumes a linear relationship between the input features and the target variable, making it easy to interpret and implement. Visit the detailed tutorial here. Types of Linear Regression There are two main types of linear regression: Simple Linear Regression Simple linear regression models the relationship between one independent variable and the dependent variable using a linear equation. For&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/afzalbadshah.com\/index.php\/2024\/05\/28\/introduction-to-linear-regression-exploring-the-secrets-of-prediction\/\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":3507,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[468],"tags":[],"class_list":["post-3190","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-science"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/afzalbadshah.com\/wp-content\/uploads\/2024\/05\/1-7-jpg.webp?fit=1920%2C1080&ssl=1","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pf3emP-Ps","jetpack-related-posts":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/posts\/3190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/comments?post=3190"}],"version-history":[{"count":5,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/posts\/3190\/revisions"}],"predecessor-version":[{"id":3513,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/posts\/3190\/revisions\/3513"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/media\/3507"}],"wp:attachment":[{"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/media?parent=3190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/categories?post=3190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afzalbadshah.com\/index.php\/wp-json\/wp\/v2\/tags?post=3190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}