{"id":36635,"date":"2024-11-01T09:50:10","date_gmt":"2024-11-01T09:50:10","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=36635"},"modified":"2024-11-01T11:52:25","modified_gmt":"2024-11-01T11:52:25","slug":"deep-learning-pytorch-course-principal-component-analysis-pca","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/36635\/","title":{"rendered":"Deep Learning PyTorch Course, Principal Component Analysis (PCA)"},"content":{"rendered":"<p><body><\/p>\n<p>Principal Component Analysis (PCA) is a representative technique for reducing the dimensionality of data,<br \/>\n   mainly used for purposes such as high-dimensional data analysis, data visualization, noise reduction, and feature extraction.<br \/>\n   PCA plays a very important role in the data preprocessing and analysis stages in the fields of deep learning and machine learning.<\/p>\n<h2>1. Overview of PCA<\/h2>\n<p>PCA is a useful tool when processing large datasets, with the following objectives:<\/p>\n<ul>\n<li><strong>Dimensionality Reduction:<\/strong> Reduces high-dimensional data to lower dimensions while preserving important information of the data.<\/li>\n<li><strong>Visualization:<\/strong> Provides insights through visualization of the data.<\/li>\n<li><strong>Noise Reduction:<\/strong> Removes noise from high-dimensional data and emphasizes the signal.<\/li>\n<li><strong>Feature Extraction:<\/strong> Extracts key features from the data to enhance the performance of machine learning models.<\/li>\n<\/ul>\n<h2>2. Mathematical Principles of PCA<\/h2>\n<p>PCA is conducted through the following steps:<\/p>\n<ol>\n<li><strong>Data Normalization:<\/strong> Normalizes the data so that the mean of each variable is 0 and the variance is 1.<\/li>\n<li><strong>Covariance Matrix Calculation:<\/strong> Calculates the covariance matrix of the normalized data. The covariance matrix indicates the correlation between data variables.<\/li>\n<li><strong>Eigenvalue Decomposition:<\/strong> Decomposes the covariance matrix to find the eigenvectors (principal components). The eigenvectors indicate the directions of the data, and the eigenvalues represent the importance of those directions.<\/li>\n<li><strong>Principal Component Selection:<\/strong> Selects principal components in descending order based on eigenvalue size and chooses them according to the desired number of dimensions.<\/li>\n<li><strong>Data Transformation:<\/strong> Transforms the original data into a new lower-dimensional space using the selected principal components.<\/li>\n<\/ol>\n<h2>3. Example of PCA: Implementation Using PyTorch<\/h2>\n<p>Now we will implement PCA using PyTorch. The code below manually implements the PCA algorithm and shows how to transform data using it.<\/p>\n<h3>3.1. Data Generation<\/h3>\n<pre><code>import numpy as np\nimport matplotlib.pyplot as plt\n\n# Generate random data\nnp.random.seed(0)\nmean = [0, 0]\ncov = [[1, 0.8], [0.8, 1]]  # Covariance matrix\ndata = np.random.multivariate_normal(mean, cov, 100)\n\n# Visualize the data\nplt.scatter(data[:, 0], data[:, 1])\nplt.title('Original Data')\nplt.xlabel('X1')\nplt.ylabel('X2')\nplt.axis('equal')\nplt.grid()\nplt.show()<\/code><\/pre>\n<h3>3.2. PCA Implementation<\/h3>\n<pre><code>import torch\n\ndef pca_manual(data, num_components=1):\n    # 1. Data Normalization\n    data_mean = data.mean(dim=0)\n    normalized_data = data - data_mean\n\n    # 2. Covariance Matrix Calculation\n    covariance_matrix = torch.mm(normalized_data.t(), normalized_data) \/ (normalized_data.size(0) - 1)\n\n    # 3. Eigenvalue Decomposition\n    eigenvalues, eigenvectors = torch.eig(covariance_matrix, eigenvectors=True)\n\n    # 4. Sort by Eigenvalue\n    sorted_indices = torch.argsort(eigenvalues[:, 0], descending=True)\n    selected_indices = sorted_indices[:num_components]\n\n    # 5. Principal Component Selection\n    principal_components = eigenvectors[:, selected_indices]\n\n    # 6. Data Transformation\n    transformed_data = torch.mm(normalized_data, principal_components)\n    \n    return transformed_data\n\n# Convert data to tensor\ndata_tensor = torch.tensor(data, dtype=torch.float32)\n\n# Apply PCA\ntransformed_data = pca_manual(data_tensor, num_components=1)\n\n# Visualize transformed data\nplt.scatter(transformed_data.numpy(), np.zeros_like(transformed_data.numpy()), alpha=0.5)\nplt.title('PCA Transformed Data')\nplt.xlabel('Principal Component 1')\nplt.axis('equal')\nplt.grid()\nplt.show()<\/code><\/pre>\n<h2>4. Use Cases of PCA<\/h2>\n<p>PCA is utilized in various fields.<\/p>\n<ul>\n<li><strong>Image Compression:<\/strong> PCA is used to reduce pixel data of high-resolution images, minimizing quality loss while saving space.<\/li>\n<li><strong>Gene Data Analysis:<\/strong> Reduces the dimensionality of biological data to facilitate data analysis and visualization.<\/li>\n<li><strong>Natural Language Processing:<\/strong> Reduces the dimensionality of word embeddings to help computers understand similarities between words.<\/li>\n<\/ul>\n<h2>5. Deep Learning Preprocessing Using PCA<\/h2>\n<p>In deep learning, PCA is often used in the data preprocessing stage. By reducing the dimensionality of the data,<br \/>\n   it increases the efficiency of model learning and helps prevent overfitting. For example,<br \/>\n   when processing image data, PCA can be used to reduce the dimension of input images,<br \/>\n   providing only the main features to the model. This can reduce computational costs and improve the training speed of the model.<\/p>\n<h2>6. Limitations of PCA<\/h2>\n<p>While PCA is a powerful technique, it has some limitations:<\/p>\n<ul>\n<li><strong>Assumption of Linearity:<\/strong> PCA is most effective when data is linearly distributed. It may not be sufficiently effective for nonlinear data.<\/li>\n<li><strong>Interpretation of the Space:<\/strong> Interpreting the dimensions reduced by PCA can be difficult, and principal components may not be relevant to the actual problem.<\/li>\n<\/ul>\n<h2>7. Alternative Techniques<\/h2>\n<p>Nonlinear dimensionality reduction techniques that serve as alternatives to PCA include:<\/p>\n<ul>\n<li><strong>Kernel PCA:<\/strong> A version of PCA that uses kernel methods to handle nonlinear data.<\/li>\n<li><strong>t-SNE:<\/strong> Useful for data visualization, placing similar data points close together.<\/li>\n<li><strong>UMAP:<\/strong> A faster and more efficient data visualization technique than t-SNE.<\/li>\n<\/ul>\n<h2>8. Conclusion<\/h2>\n<p>Principal Component Analysis (PCA) is one of the key techniques in deep learning and machine learning,<br \/>\n   used for various purposes, including dimensionality reduction, visualization, and feature extraction.<br \/>\n   I hope you learned the principles of PCA and how to implement it using PyTorch through this course.<br \/>\n   I look forward to you achieving better results by utilizing PCA in future data analysis and modeling processes.<br \/>\n   In the next course, we will cover deeper topics in deep learning.<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Principal Component Analysis (PCA) is a representative technique for reducing the dimensionality of data, mainly used for purposes such as high-dimensional data analysis, data visualization, noise reduction, and feature extraction. PCA plays a very important role in the data preprocessing and analysis stages in the fields of deep learning and machine learning. 1. Overview of &hellip; <a href=\"https:\/\/atmokpo.com\/w\/36635\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Deep Learning PyTorch Course, Principal Component Analysis (PCA)&#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-36635","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, Principal Component Analysis (PCA) - \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\/36635\/\" \/>\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, Principal Component Analysis (PCA) - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Principal Component Analysis (PCA) is a representative technique for reducing the dimensionality of data, mainly used for purposes such as high-dimensional data analysis, data visualization, noise reduction, and feature extraction. PCA plays a very important role in the data preprocessing and analysis stages in the fields of deep learning and machine learning. 1. Overview of &hellip; \ub354 \ubcf4\uae30 &quot;Deep Learning PyTorch Course, Principal Component Analysis (PCA)&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/36635\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:50:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:52:25+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\/36635\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36635\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Deep Learning PyTorch Course, Principal Component Analysis (PCA)\",\"datePublished\":\"2024-11-01T09:50:10+00:00\",\"dateModified\":\"2024-11-01T11:52:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36635\/\"},\"wordCount\":590,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"PyTorch Study\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/36635\/\",\"url\":\"https:\/\/atmokpo.com\/w\/36635\/\",\"name\":\"Deep Learning PyTorch Course, Principal Component Analysis (PCA) - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:50:10+00:00\",\"dateModified\":\"2024-11-01T11:52:25+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36635\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/36635\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/36635\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Deep Learning PyTorch Course, Principal Component Analysis (PCA)\"}]},{\"@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, Principal Component Analysis (PCA) - \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\/36635\/","og_locale":"ko_KR","og_type":"article","og_title":"Deep Learning PyTorch Course, Principal Component Analysis (PCA) - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Principal Component Analysis (PCA) is a representative technique for reducing the dimensionality of data, mainly used for purposes such as high-dimensional data analysis, data visualization, noise reduction, and feature extraction. PCA plays a very important role in the data preprocessing and analysis stages in the fields of deep learning and machine learning. 1. Overview of &hellip; \ub354 \ubcf4\uae30 \"Deep Learning PyTorch Course, Principal Component Analysis (PCA)\"","og_url":"https:\/\/atmokpo.com\/w\/36635\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:50:10+00:00","article_modified_time":"2024-11-01T11:52:25+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\/36635\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/36635\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Deep Learning PyTorch Course, Principal Component Analysis (PCA)","datePublished":"2024-11-01T09:50:10+00:00","dateModified":"2024-11-01T11:52:25+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/36635\/"},"wordCount":590,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["PyTorch Study"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/36635\/","url":"https:\/\/atmokpo.com\/w\/36635\/","name":"Deep Learning PyTorch Course, Principal Component Analysis (PCA) - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:50:10+00:00","dateModified":"2024-11-01T11:52:25+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/36635\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/36635\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/36635\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Deep Learning PyTorch Course, Principal Component Analysis (PCA)"}]},{"@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\/36635","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=36635"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36635\/revisions"}],"predecessor-version":[{"id":36636,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36635\/revisions\/36636"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=36635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=36635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=36635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}