{"id":36557,"date":"2024-11-01T09:49:32","date_gmt":"2024-11-01T09:49:32","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=36557"},"modified":"2024-11-01T11:52:43","modified_gmt":"2024-11-01T11:52:43","slug":"deep-learning-pytorch-course-logistic-regression-and-linear-regression","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/36557\/","title":{"rendered":"Deep Learning PyTorch Course, Logistic Regression and Linear Regression"},"content":{"rendered":"<p><body><\/p>\n<p>In this course, we will explore two important regression analysis techniques, <strong>logistic regression<\/strong> and <strong>linear regression<\/strong>, which are fundamental concepts in <strong>deep learning<\/strong>. In this process, we will implement both models using <strong>PyTorch<\/strong> and examine how each technique is utilized.<\/p>\n<h2>Table of Contents<\/h2>\n<ol>\n<li><a href=\"#linear_regression\">1. Linear Regression<\/a><\/li>\n<li><a href=\"#logistic_regression\">2. Logistic Regression<\/a><\/li>\n<li><a href=\"#conclusion\">3. Conclusion<\/a><\/li>\n<\/ol>\n<h2 id=\"linear_regression\">1. Linear Regression<\/h2>\n<p>Linear regression is a statistical method that models the relationship between input variables and output variables using a straight line. It performs predictions by finding the optimal line for a given set of data points.<\/p>\n<h3>1.1 Linear Regression Model Equation<\/h3>\n<p>The linear regression model can be represented by the following equation:<\/p>\n<pre><code>y = \u03b20 + \u03b21*x1 + \u03b22*x2 + ... + \u03b2n*xn<\/code><\/pre>\n<p>Here, <code>y<\/code> is the predicted value, <code>\u03b20<\/code> is the intercept, and <code>\u03b21, \u03b22, ..., \u03b2n<\/code> are the regression coefficients. These regression coefficients are learned from the data.<\/p>\n<h3>1.2 Implementing Linear Regression in PyTorch<\/h3>\n<p>Now, let&#8217;s implement the linear regression model using PyTorch. We will create a simple linear regression model with the code below.<\/p>\n<pre><code>\nimport torch\nimport torch.nn as nn\nimport torch.optim as optim\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n# Generate data\nx_data = np.array([[1], [2], [3], [4], [5]])\ny_data = np.array([[2], [3], [5], [7], [11]])\n\n# Convert to tensor\nx_tensor = torch.Tensor(x_data)\ny_tensor = torch.Tensor(y_data)\n\n# Define linear regression model\nmodel = nn.Linear(1, 1)\n\n# Define loss function and optimizer\ncriterion = nn.MSELoss()\noptimizer = optim.SGD(model.parameters(), lr=0.01)\n\n# Train the model\nfor epoch in range(100):\n    model.train()\n    \n    optimizer.zero_grad()\n    y_pred = model(x_tensor)\n    loss = criterion(y_pred, y_tensor)\n    loss.backward()\n    optimizer.step()\n\n# Visualize the results\nplt.scatter(x_data, y_data, color='blue', label='Actual Data')\nplt.plot(x_data, model(x_tensor).detach().numpy(), color='red', label='Regression Line')\nplt.legend()\nplt.title('Linear Regression Prediction')\nplt.xlabel('x')\nplt.ylabel('y')\nplt.show()\n<\/code><\/pre>\n<p>The code above is an example of training a linear regression model using a simple dataset. After training the model, we can visualize and compare the actual data with the predicted values.<\/p>\n<h2 id=\"logistic_regression\">2. Logistic Regression<\/h2>\n<p>Logistic regression is a linear model designed to handle classification problems. It is primarily used in binary classification, where it applies a sigmoid function (logistic function) to the linear combination of inputs, converting the output into a probability value between 0 and 1.<\/p>\n<h3>2.1 Logistic Regression Model Equation<\/h3>\n<p>The logistic regression model can be represented by the following equations:<\/p>\n<pre><code>y = 1 \/ (1 + e^(-z))\nz = \u03b20 + \u03b21*x1 + \u03b22*x2 + ... + \u03b2n*xn<\/code><\/pre>\n<p>Here, <code>z<\/code> is the linear combination, and <code>y<\/code> is the probability of the class.<\/p>\n<h3>2.2 Implementing Logistic Regression in PyTorch<\/h3>\n<p>Now, let&#8217;s implement the logistic regression model using PyTorch. The code below is an example solving a simple binary classification problem.<\/p>\n<pre><code>\n# Generate data (binary classification)\nfrom sklearn.datasets import make_classification\nimport torch.nn.functional as F\n\n# Create binary classification dataset\nX, y = make_classification(n_samples=100, n_features=2, n_classes=2, n_informative=2, n_redundant=0, random_state=42)\nX_tensor = torch.Tensor(X)\ny_tensor = torch.Tensor(y).view(-1, 1)\n\n# Define logistic regression model\nclass LogisticRegressionModel(nn.Module):\n    def __init__(self):\n        super(LogisticRegressionModel, self).__init__()\n        self.linear = nn.Linear(2, 1)\n\n    def forward(self, x):\n        return torch.sigmoid(self.linear(x))\n\n# Define model, loss function, and optimizer\nmodel = LogisticRegressionModel()\ncriterion = nn.BCELoss()\noptimizer = optim.SGD(model.parameters(), lr=0.01)\n\n# Train the model\nfor epoch in range(100):\n    model.train()\n    \n    optimizer.zero_grad()\n    y_pred = model(X_tensor)\n    \n    loss = criterion(y_pred, y_tensor)\n    loss.backward()\n    optimizer.step()\n\n# Predictions\nmodel.eval()\nwith torch.no_grad():\n    y_pred = model(X_tensor)\n\n# Visualize predictions\npredicted_classes = (y_pred.numpy() > 0.5).astype(int)\nplt.scatter(X[y[:, 0] == 0][:, 0], X[y[:, 0] == 0][:, 1], color='blue', label='Class 0')\nplt.scatter(X[y[:, 0] == 1][:, 0], X[y[:, 0] == 1][:, 1], color='red', label='Class 1')\nplt.scatter(X[predicted_classes[:, 0] == 1][:, 0], X[predicted_classes[:, 0] == 1][:, 1], color='green', label='Predicted')\nplt.legend()\nplt.title('Logistic Regression Prediction')\nplt.xlabel('Feature 1')\nplt.ylabel('Feature 2')\nplt.show()\n<\/code><\/pre>\n<p>The code above is an example of training a logistic regression model to solve a simple binary classification problem. After training the model, we can visualize and compare the actual classes with the predicted classes.<\/p>\n<h2 id=\"conclusion\">3. Conclusion<\/h2>\n<p>In this course, we covered logistic regression and linear regression. Both models were implemented using PyTorch with a simple dataset, highlighting the differences in the types of problems they address and their significance. These techniques form the foundation of machine learning and deep learning and are widely used in solving real-world problems. I hope this course broadens your understanding.<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this course, we will explore two important regression analysis techniques, logistic regression and linear regression, which are fundamental concepts in deep learning. In this process, we will implement both models using PyTorch and examine how each technique is utilized. Table of Contents 1. Linear Regression 2. Logistic Regression 3. Conclusion 1. Linear Regression Linear &hellip; <a href=\"https:\/\/atmokpo.com\/w\/36557\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Deep Learning PyTorch Course, Logistic Regression and Linear Regression&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[149],"tags":[],"class_list":["post-36557","post","type-post","status-publish","format-standard","hentry","category-pytorch-study"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Deep Learning PyTorch Course, Logistic Regression and Linear Regression - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/36557\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Deep Learning PyTorch Course, Logistic Regression and Linear Regression - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In this course, we will explore two important regression analysis techniques, logistic regression and linear regression, which are fundamental concepts in deep learning. In this process, we will implement both models using PyTorch and examine how each technique is utilized. Table of Contents 1. Linear Regression 2. Logistic Regression 3. Conclusion 1. Linear Regression Linear &hellip; \ub354 \ubcf4\uae30 &quot;Deep Learning PyTorch Course, Logistic Regression and Linear Regression&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/36557\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:49:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:52:43+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/36557\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36557\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Deep Learning PyTorch Course, Logistic Regression and Linear Regression\",\"datePublished\":\"2024-11-01T09:49:32+00:00\",\"dateModified\":\"2024-11-01T11:52:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36557\/\"},\"wordCount\":381,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"PyTorch Study\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/36557\/\",\"url\":\"https:\/\/atmokpo.com\/w\/36557\/\",\"name\":\"Deep Learning PyTorch Course, Logistic Regression and Linear Regression - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:49:32+00:00\",\"dateModified\":\"2024-11-01T11:52:43+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36557\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/36557\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/36557\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Deep Learning PyTorch Course, Logistic Regression and Linear Regression\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Deep Learning PyTorch Course, Logistic Regression and Linear Regression - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/36557\/","og_locale":"ko_KR","og_type":"article","og_title":"Deep Learning PyTorch Course, Logistic Regression and Linear Regression - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In this course, we will explore two important regression analysis techniques, logistic regression and linear regression, which are fundamental concepts in deep learning. In this process, we will implement both models using PyTorch and examine how each technique is utilized. Table of Contents 1. Linear Regression 2. Logistic Regression 3. Conclusion 1. Linear Regression Linear &hellip; \ub354 \ubcf4\uae30 \"Deep Learning PyTorch Course, Logistic Regression and Linear Regression\"","og_url":"https:\/\/atmokpo.com\/w\/36557\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:49:32+00:00","article_modified_time":"2024-11-01T11:52:43+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/36557\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/36557\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Deep Learning PyTorch Course, Logistic Regression and Linear Regression","datePublished":"2024-11-01T09:49:32+00:00","dateModified":"2024-11-01T11:52:43+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/36557\/"},"wordCount":381,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["PyTorch Study"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/36557\/","url":"https:\/\/atmokpo.com\/w\/36557\/","name":"Deep Learning PyTorch Course, Logistic Regression and Linear Regression - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:49:32+00:00","dateModified":"2024-11-01T11:52:43+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/36557\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/36557\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/36557\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Deep Learning PyTorch Course, Logistic Regression and Linear Regression"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=36557"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36557\/revisions"}],"predecessor-version":[{"id":36558,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36557\/revisions\/36558"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=36557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=36557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=36557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}