{"id":254,"date":"2021-06-08T20:29:30","date_gmt":"2021-06-08T12:29:30","guid":{"rendered":"https:\/\/swordofmorning.com\/?p=254"},"modified":"2025-10-09T13:56:05","modified_gmt":"2025-10-09T05:56:05","slug":"matlab-tutorial-04-official-pca","status":"publish","type":"post","link":"https:\/\/swordofmorning.com\/index.php\/2021\/06\/08\/matlab-tutorial-04-official-pca\/","title":{"rendered":"Matlab Tutorial 04 official PCA"},"content":{"rendered":"<p><div class=\"has-toc have-toc\"><\/div><br \/>\n&emsp;&emsp;\u672c\u6587\u4ecb\u7ecd\u5982\u4f55\u5728Matlab\u4e2d\u4f7f\u7528\u5b98\u65b9\u5e93\u51fd\u6570\u63d0\u4f9b\u7684PCA\u65b9\u6cd5\u3002<\/p>\n<h3>.1 pca()\u53c2\u6570\u4ecb\u7ecd<\/h3>\n<pre><code>coeff = pca(X)\ncoeff = pca(X,Name,Value)\n[coeff,score,latent] = pca(___)\n[coeff,score,latent,tsquared] = pca(___)\n[coeff,score,latent,tsquared,explained,mu] = pca(___)<\/code><\/pre>\n<p>&emsp;&emsp;\u4e0b\u9762\u4ecb\u7ecd\u5b83\u7684\u8f93\u5165\u53c2\u6570\uff1a<\/p>\n<ul>\n<li>&emsp;&emsp;Input Argument 0: \u7ef4\u5ea6\u4e3an * m\u7684\u7279\u5f81\u77e9\u9635\uff0cn\u662f\u6837\u672c\u6570\uff0cp\u662f\u7279\u5f81\u6570\u3002<\/li>\n<li>&emsp;&emsp;Input Argument 1: 'svd' (default) | 'eig' | 'als'<br \/>\n&emsp;&emsp;'Algorithm' \u2014 Principal component algorithm<br \/>\n&emsp;&emsp;\u4e3b\u6210\u5206\u5206\u6790\u4f7f\u7528\u7684\u7b97\u6cd5\u3002eig (Eigenvalue decomposition )\u7b97\u6cd5, \u6b64\u7b97\u6cd5\u5f53n(number of examples) &gt; p (features) \u65f6\uff0c\u901f\u5ea6\u5feb\u4e8eSVD,\u4f46\u662f\u8ba1\u7b97\u7684\u7ed3\u679c\u6ca1\u6709SVD\u7cbe\u786e\u3002als( Alternating least squares )\u7b97\u6cd5\uff0c\u6b64\u7b97\u6cd5\u4e3a\u4e86\u5904\u7406\u6570\u636e\u96c6X\u4e2d\u6709\u5c11\u8bb8\u7f3a\u5931\u6570\u636e\u65f6\u7684\u60c5\u51b5(i.e 0)\uff0c \u4f46\u662f\u5bf9\u4e8eX\u4e3a\u7a00\u758f\u6570\u636e\u96c6(\u7f3a\u5931\u6570\u636e\u8fc7\u591a)\u65f6\u4e0d\u597d\u7528\u3002<\/li>\n<li>&emsp;&emsp;Input Argument 2: true (default) | false<br \/>\n&emsp;&emsp;'Economy' \u2014 Indicator for economy size output<br \/>\n&emsp;&emsp;\u9009\u62e9\u662f\u5426\u5bf9\u6570\u636e\u8fdb\u884c\u4e2d\u5fc3\u5316\uff0c\u4e5f\u662f\u6570\u636e\u7684\u7279\u5f81\u662f\u5426\u8fdb\u884c\u96f6\u5747\u503c\u5316(i.e.\u6309\u5217\u51cf\u53bb\u5747\u503c\uff0c\u4e3a\u4e86\u5f97\u5230covariance matrix)\uff0c \u5982\u679c\u9009\u62e9\u4e86true\uff0c\u5219\u53ef\u7528score*coeff'\u6062\u590d\u4e2d\u5fc3\u5316\u540e\u7684X\uff0c\u82e5\u9009\u62e9\u4e86false\uff0c\u5219\u53ef\u7528score*coeff'\u6062\u590d\u539f\u59cb\u7684X\u3002<\/li>\n<li>&emsp;&emsp;Input Argument 3: true (default) | false<br \/>\n&emsp;&emsp;'Economy' \u2014 Indicator for economy size output<br \/>\n&emsp;&emsp;\u6709\u65f6\u5019\u8f93\u51fa\u7684coeff(\u6620\u5c04\u77e9\u9635p-by-p)\u8fc7\u5927\uff0c\u800c\u4e14\u662f\u6ca1\u6709\u5fc5\u8981\u7684(\u56e0\u4e3a\u6211\u4eec\u8981\u964d\u7ef4)\uff0c\u6240\u4ee5\u53ef\u4ee5\u53ea\u8f93\u51facoeff(\u4ee5\u53cascore,latent)\u7684\u524dd\u5217\uff0cd\u662f\u6570\u636e\u96c6\u7684\u81ea\u7531\u5ea6\uff0c\u6570\u636e\u96c6\u6ca1NAN\u7684\u65f6\u5019d=n-1\uff1b\u5177\u4f53\u7684\u89e3\u91ca\u89c1matlab\u3002\u603b\u4e4b\u5982\u679c\u5c06\u770b\u89c1\u5b8c\u6574\u7684PCA\u7ed3\u679c\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4e3afalse\u3002<\/li>\n<li>&emsp;&emsp;Input Argument 4: number of variables (default) | scalar integer<br \/>\n&emsp;&emsp;'NumComponents' \u2014 Number of components requested<br \/>\n&emsp;&emsp;\u8f93\u51fa\u6307\u5b9a\u7684components\u4e5f\u5c31\u662f\u66f4\u4e3a\u7075\u6d3b\u7684Economy\uff0c\u4f46\u662f\u7ecf\u8fc7\u8bd5\u9a8c\u53d1\u73b0\u6307\u5b9a\u6210\u5206\u6570\u4ec5\u5728\u5c0f\u4e8ed(\u81ea\u7531\u5ea6)\u65f6\u6709\u6548\uff0c\u5927\u4e8ed\u65f6\u65e0\u6548\uff1b\u9ed8\u8ba4: number of variables ( i.e p,\u7279\u5f81\u6570\u76ee)\u3002<\/li>\n<li>&emsp;&emsp;\u5176\u4f59\u53c2\u6570\u89c1\u5b98\u65b9\u6587\u6863\u3002<\/li>\n<\/ul>\n<h3>.2 \u5b9e\u4f8b<\/h3>\n<pre><code>[cfPC, cfScore, cfLatent, cfLsquare] = pca(ClassFeature);\ncfAcc = cumsum(cfLatent) .\/ sum(cfLatent);\n% \u53d8\u6362\u77e9\u9635\ncfTran = cfPC(:, 1:4);\nClassFeature = bsxfun(@minus, ClassFeature, mean(ClassFeature, 1));\nClassFeaturePCA = ClassFeature * cfTran; <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&emsp;&emsp;\u672c\u6587\u4ecb\u7ecd\u5982\u4f55\u5728Matlab\u4e2d\u4f7f\u7528\u5b98\u65b9\u5e93\u51fd\u6570\u63d0\u4f9b\u7684PCA\u65b9\u6cd5\u3002 .1 pca()\u53c2\u6570\u4ecb\u7ecd coeff = p &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[65],"tags":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/254"}],"collection":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/comments?post=254"}],"version-history":[{"count":1,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/254\/revisions"}],"predecessor-version":[{"id":438,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/254\/revisions\/438"}],"wp:attachment":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/media?parent=254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/categories?post=254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/tags?post=254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}