{"id":145,"date":"2025-07-18T01:45:58","date_gmt":"2025-07-18T01:45:58","guid":{"rendered":"https:\/\/www.rickykurosawa.com\/?page_id=145"},"modified":"2026-04-07T23:48:51","modified_gmt":"2026-04-07T23:48:51","slug":"using-pca-to-build-a-simple-faceid-system-but-for-leaves","status":"publish","type":"page","link":"https:\/\/www.rickykurosawa.com\/?page_id=145","title":{"rendered":"Using PCA to build a simple FaceID system&#8230; but for leaves"},"content":{"rendered":"\n<div class=\"wp-block-columns alignwide is-layout-flex wp-container-core-columns-is-layout-3a88641f wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<h2 class=\"wp-block-heading\">Introduction and Purpose<\/h2>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><\/div>\n<\/div>\n\n\n<p><script><br \/>\nwindow.MathJax = {<br \/>\n  tex: {<br \/>\n    inlineMath: [['\\\\(','\\\\)']],<br \/>\n    displayMath: [['$$','$$']]<br \/>\n  },<br \/>\n  svg: {<br \/>\n    fontCache: 'global'<br \/>\n  }<br \/>\n};<br \/>\n<\/script><br \/>\n<script src=\"https:\/\/cdn.jsdelivr.net\/npm\/mathjax@3\/es5\/tex-svg.js\" async><\/script><\/p>\n\n\n<div class=\"wp-block-columns alignwide is-layout-flex wp-container-core-columns-is-layout-3a88641f wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Facial recognition and machine learning have become more and more relevant in modern society. As we use more data to help inform decisions, it becomes increasingly important to use computational resources efficiently. In PCA (principal component analysis), eigenvectors point in the principal directions of the data, while eigenvalues measure the variance along those directions.<br><br>In our case, we use PCA and the power method to identify tree species through images of its leaves. Since a single image can be represented as a 690,000&#215;1 RGB vector, the covariance matrix would be a 690,000&#215;690,000 matrix, which is computationally expensive to compute and analyze. Instead, we use the power method to compute the dominant eigenvalue and its respective eigenvector without actually computing the covariance matrix.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"960\" data-id=\"151\" src=\"https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/Leaf1-1.jpg\" alt=\"\" class=\"wp-image-151\" srcset=\"https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/Leaf1-1.jpg 720w, https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/Leaf1-1-225x300.jpg 225w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><figcaption class=\"wp-element-caption\">This is an example of the images we used to identify tree species using leaves<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"960\" data-id=\"150\" src=\"https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/Leaf2-1.jpg\" alt=\"\" class=\"wp-image-150\" srcset=\"https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/Leaf2-1.jpg 720w, https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/Leaf2-1-225x300.jpg 225w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><figcaption class=\"wp-element-caption\">This is another example of the images we used to identify tree species using leaves. Both images were taken from <a href=\"https:\/\/archive.ics.uci.edu\/ml\/datasets\/leaf\">https:\/\/archive.ics.uci.edu\/ml\/datasets\/leaf<\/a><\/figcaption><\/figure>\n<\/figure>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading alignwide\">Results and Process<\/h2>\n\n\n\n<div class=\"wp-block-columns alignwide is-layout-flex wp-container-core-columns-is-layout-3a88641f wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\">\n<p class=\"wp-block-paragraph\">The first goal was to use the first principle component, aka the dominant eigenvector.  To test the effectiveness of one eigenvector, we tested a sample of 30 images not used in the &#8220;training&#8221; process. The 30 images consisted of 3 images of leaves from 10 different species. After applying our numerical method that finds this dominant eigenvector, we compare our sample image to this dominant eigenvector. The program compares the sample image and the eigenvectors of the 10 species to determine which species it guesses. The eigenvector closest (orthogonally) to the sample image vector is the species guessed. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To the right, we can see the confusion chart, which nicely shows how our program performed. We can see that our program struggled to identify species 9 the most, and had an overall identification rate of 26\/30.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/2D_Confusion_Chart-1024x768.jpg\" alt=\"\" class=\"wp-image-154\" style=\"width:477px;height:auto\" srcset=\"https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/2D_Confusion_Chart-1024x768.jpg 1024w, https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/2D_Confusion_Chart-300x225.jpg 300w, https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/2D_Confusion_Chart-768x576.jpg 768w, https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/2D_Confusion_Chart.jpg 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">This is the confusion chart for 30 sample images using the first principle component.<\/figcaption><\/figure>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns alignwide is-layout-flex wp-container-core-columns-is-layout-3a88641f wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Afterwards, we implement another principle component, the secondmost dominant eigenvector. This is supposed to help increase the successful identification rate. In this case, we compared the distance between the sample vector to our eigenspace spanned by the twomost dominant eigenvectors. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To the right, we can again see a different confusion chart. After implementing the second principle component, the program was significantly better at identifying species 9, but new errors seem to apper. The overall identifaction rate was 27\/30.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Overall, this small increase in improvement is likely due to the sensitivity of these vectors to the image background. This project was a super cool application of the power method and introduced me to the idea of vectorizing data, which connects conceptually to the embeddings widely used in today\u2019s AI models.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/3D_Confusion_Chart-1024x768.jpg\" alt=\"\" class=\"wp-image-155\" style=\"width:476px;height:auto\" srcset=\"https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/3D_Confusion_Chart-1024x768.jpg 1024w, https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/3D_Confusion_Chart-300x225.jpg 300w, https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/3D_Confusion_Chart-768x576.jpg 768w, https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/3D_Confusion_Chart.jpg 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">This is the confusion chart for the same 30 sample images using the first two principle components.<\/figcaption><\/figure>\n<\/div>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction and Purpose Facial recognition and machine learning have become more and more relevant in modern society. As we use more data to help inform decisions, it becomes increasingly important to use computational resources efficiently. In PCA (principal component analysis), eigenvectors point in the principal directions of the data, while eigenvalues measure the variance along [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-145","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Using PCA to build a simple FaceID system... but for leaves - Ricky Kurosawa<\/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:\/\/www.rickykurosawa.com\/?page_id=145\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using PCA to build a simple FaceID system... but for leaves - Ricky Kurosawa\" \/>\n<meta property=\"og:description\" content=\"Introduction and Purpose Facial recognition and machine learning have become more and more relevant in modern society. As we use more data to help inform decisions, it becomes increasingly important to use computational resources efficiently. In PCA (principal component analysis), eigenvectors point in the principal directions of the data, while eigenvalues measure the variance along [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.rickykurosawa.com\/?page_id=145\" \/>\n<meta property=\"og:site_name\" content=\"Ricky Kurosawa\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-07T23:48:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/Leaf1-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"720\" \/>\n\t<meta property=\"og:image:height\" content=\"960\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.rickykurosawa.com\\\/?page_id=145\",\"url\":\"https:\\\/\\\/www.rickykurosawa.com\\\/?page_id=145\",\"name\":\"Using PCA to build a simple FaceID system... but for leaves - Ricky Kurosawa\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.rickykurosawa.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.rickykurosawa.com\\\/?page_id=145#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.rickykurosawa.com\\\/?page_id=145#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.rickykurosawa.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2025\\\/07\\\/Leaf1-1.jpg\",\"datePublished\":\"2025-07-18T01:45:58+00:00\",\"dateModified\":\"2026-04-07T23:48:51+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.rickykurosawa.com\\\/?page_id=145#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.rickykurosawa.com\\\/?page_id=145\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.rickykurosawa.com\\\/?page_id=145#primaryimage\",\"url\":\"https:\\\/\\\/www.rickykurosawa.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2025\\\/07\\\/Leaf1-1.jpg\",\"contentUrl\":\"https:\\\/\\\/www.rickykurosawa.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2025\\\/07\\\/Leaf1-1.jpg\",\"width\":720,\"height\":960},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.rickykurosawa.com\\\/?page_id=145#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.rickykurosawa.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using PCA to build a simple FaceID system&#8230; but for leaves\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.rickykurosawa.com\\\/#website\",\"url\":\"https:\\\/\\\/www.rickykurosawa.com\\\/\",\"name\":\"Ricky Kurosawa\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.rickykurosawa.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using PCA to build a simple FaceID system... but for leaves - Ricky Kurosawa","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:\/\/www.rickykurosawa.com\/?page_id=145","og_locale":"en_US","og_type":"article","og_title":"Using PCA to build a simple FaceID system... but for leaves - Ricky Kurosawa","og_description":"Introduction and Purpose Facial recognition and machine learning have become more and more relevant in modern society. As we use more data to help inform decisions, it becomes increasingly important to use computational resources efficiently. In PCA (principal component analysis), eigenvectors point in the principal directions of the data, while eigenvalues measure the variance along [&hellip;]","og_url":"https:\/\/www.rickykurosawa.com\/?page_id=145","og_site_name":"Ricky Kurosawa","article_modified_time":"2026-04-07T23:48:51+00:00","og_image":[{"width":720,"height":960,"url":"https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/Leaf1-1.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.rickykurosawa.com\/?page_id=145","url":"https:\/\/www.rickykurosawa.com\/?page_id=145","name":"Using PCA to build a simple FaceID system... but for leaves - Ricky Kurosawa","isPartOf":{"@id":"https:\/\/www.rickykurosawa.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.rickykurosawa.com\/?page_id=145#primaryimage"},"image":{"@id":"https:\/\/www.rickykurosawa.com\/?page_id=145#primaryimage"},"thumbnailUrl":"https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/Leaf1-1.jpg","datePublished":"2025-07-18T01:45:58+00:00","dateModified":"2026-04-07T23:48:51+00:00","breadcrumb":{"@id":"https:\/\/www.rickykurosawa.com\/?page_id=145#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.rickykurosawa.com\/?page_id=145"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.rickykurosawa.com\/?page_id=145#primaryimage","url":"https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/Leaf1-1.jpg","contentUrl":"https:\/\/www.rickykurosawa.com\/wordpress\/wp-content\/uploads\/2025\/07\/Leaf1-1.jpg","width":720,"height":960},{"@type":"BreadcrumbList","@id":"https:\/\/www.rickykurosawa.com\/?page_id=145#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.rickykurosawa.com\/"},{"@type":"ListItem","position":2,"name":"Using PCA to build a simple FaceID system&#8230; but for leaves"}]},{"@type":"WebSite","@id":"https:\/\/www.rickykurosawa.com\/#website","url":"https:\/\/www.rickykurosawa.com\/","name":"Ricky Kurosawa","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.rickykurosawa.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.rickykurosawa.com\/index.php?rest_route=\/wp\/v2\/pages\/145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rickykurosawa.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.rickykurosawa.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.rickykurosawa.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rickykurosawa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=145"}],"version-history":[{"count":11,"href":"https:\/\/www.rickykurosawa.com\/index.php?rest_route=\/wp\/v2\/pages\/145\/revisions"}],"predecessor-version":[{"id":433,"href":"https:\/\/www.rickykurosawa.com\/index.php?rest_route=\/wp\/v2\/pages\/145\/revisions\/433"}],"wp:attachment":[{"href":"https:\/\/www.rickykurosawa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}