{"id":66,"date":"2011-02-05T11:44:44","date_gmt":"2011-02-05T19:44:44","guid":{"rendered":"http:\/\/www.zhanxw.com\/blog\/?p=66"},"modified":"2011-02-05T11:44:44","modified_gmt":"2011-02-05T19:44:44","slug":"kernel-pca-%e5%8e%9f%e7%90%86%e5%92%8c%e6%bc%94%e7%a4%ba","status":"publish","type":"post","link":"https:\/\/zhanxw.com\/blog\/2011\/02\/kernel-pca-%e5%8e%9f%e7%90%86%e5%92%8c%e6%bc%94%e7%a4%ba\/","title":{"rendered":"Kernel PCA \u539f\u7406\u548c\u6f14\u793a"},"content":{"rendered":"<p>\u4e3b\u6210\u4efd\uff08Principal Component Analysis\uff09\u5206\u6790\u662f\u964d\u7ef4\uff08Dimension Reduction\uff09\u7684\u91cd\u8981\u624b\u6bb5\u3002\u6bcf\u4e00\u4e2a\u4e3b\u6210\u5206\u90fd\u662f\u6570\u636e\u5728\u67d0\u4e00\u4e2a\u65b9\u5411\u4e0a\u7684\u6295\u5f71\uff0c\u5728\u4e0d\u540c\u7684\u65b9\u5411\u4e0a\u8fd9\u4e9b\u6570\u636e\u65b9\u5deeVariance\u7684\u5927\u5c0f\u7531\u5176\u7279\u5f81\u503c\uff08eigenvalue\uff09\u51b3\u5b9a\u3002\u4e00\u822c\u6211\u4eec\u4f1a\u9009\u53d6\u6700\u5927\u7684\u51e0\u4e2a\u7279\u5f81\u503c\u6240\u5728\u7684\u7279\u5f81\u5411\u91cf\uff08eigenvector\uff09\uff0c\u8fd9\u4e9b\u65b9\u5411\u4e0a\u7684\u4fe1\u606f\u4e30\u5bcc\uff0c\u4e00\u822c\u8ba4\u4e3a\u5305\u542b\u4e86\u66f4\u591a\u6211\u4eec\u6240\u611f\u5174\u8da3\u7684\u4fe1\u606f\u3002\u5f53\u7136\uff0c\u8fd9\u91cc\u9762\u6709\u8f83\u5f3a\u7684\u5047\u8bbe\uff1a\uff081\uff09\u7279\u5f81\u6839\u7684\u5927\u5c0f\u51b3\u5b9a\u4e86\u6211\u4eec\u611f\u5174\u8da3\u4fe1\u606f\u7684\u591a\u5c11\u3002\u5373\u5c0f\u7279\u5f81\u6839\u5f80\u5f80\u4ee3\u8868\u4e86\u566a\u58f0\uff0c\u4f46\u5b9e\u9645\u4e0a\uff0c\u5411\u5c0f\u4e00\u70b9\u7684\u7279\u5f81\u6839\u65b9\u5411\u6295\u5f71\u4e5f\u6709\u53ef\u80fd\u5305\u62ec\u6211\u4eec\u611f\u5174\u8da3\u7684\u6570\u636e\uff1b \uff082\uff09\u7279\u5f81\u5411\u91cf\u7684\u65b9\u5411\u662f\u4e92\u76f8\u6b63\u4ea4\uff08orthogonal\uff09\u7684\uff0c\u8fd9\u79cd\u6b63\u4ea4\u6027\u4f7f\u5f97PCA\u5bb9\u6613\u53d7\u5230Outlier\u7684\u5f71\u54cd\uff0c\u4f8b\u5982\u5728\u30101\u3011\u4e2d\u63d0\u5230\u7684\u4f8b\u5b50\uff083\uff09\u96be\u4e8e\u89e3\u91ca\u7ed3\u679c\u3002\u4f8b\u5982\u5728\u5efa\u7acb\u7ebf\u6027\u56de\u5f52\u6a21\u578b\uff08Linear Regression Model\uff09\u5206\u6790\u56e0\u53d8\u91cf\uff08response\uff09\u548c\u7b2c\u4e00\u4e2a\u4e3b\u6210\u4efd\u7684\u5173\u7cfb\u65f6\uff0c\u6211\u4eec\u5f97\u5230\u7684\u56de\u5f52\u7cfb\u6570\uff08Coefficiency\uff09\u4e0d\u662f\u67d0\u4e00\u4e2a\u81ea\u53d8\u91cf\uff08covariate\uff09\u7684\u8d21\u732e\uff0c\u800c\u662f\u5bf9\u6240\u6709\u81ea\u53d8\u91cf\u7684\u67d0\u4e2a\u7ebf\u6027\u7ec4\u5408\uff08Linear Combination\uff09\u7684\u8d21\u732e\u3002<\/p>\n<p>\u5728Kernel PCA\u5206\u6790\u4e4b\u4e2d\uff0c\u6211\u4eec\u540c\u6837\u9700\u8981\u8fd9\u4e9b\u5047\u8bbe\uff0c\u4f46\u4e0d\u540c\u7684\u5730\u65b9\u662f\u6211\u4eec\u8ba4\u4e3a\u539f\u6709\u6570\u636e\u6709\u66f4\u9ad8\u7684\u7ef4\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u66f4\u9ad8\u7ef4\u7684\u7a7a\u95f4\uff08Hilbert Space\uff09\u4e2d\u505aPCA\u5206\u6790\uff08\u5373\u5728\u66f4\u9ad8\u7ef4\u7a7a\u95f4\u91cc\uff0c\u628a\u539f\u59cb\u6570\u636e\u5411\u4e0d\u540c\u7684\u65b9\u5411\u6295\u5f71\uff09\u3002\u8fd9\u6837\u505a\u7684\u4f18\u70b9\u6709\uff1a\u5bf9\u4e8e\u5728\u901a\u5e38\u7ebf\u6027\u7a7a\u95f4\u96be\u4e8e\u7ebf\u6027\u5206\u7c7b\u7684\u6570\u636e\u70b9\uff0c\u6211\u4eec\u6709\u53ef\u80fd\u518d\u66f4\u9ad8\u7ef4\u5ea6\u4e0a\u627e\u5230\u5408\u9002\u7684\u9ad8\u7ef4\u7ebf\u6027\u5206\u7c7b\u5e73\u9762\u3002\u6211\u4eec\u7b2c\u4e8c\u90e8\u5206\u7684\u4f8b\u5b50\u5c31\u8bf4\u660e\u4e86\u8fd9\u4e00\u70b9\u3002<\/p>\n<p>\u672c\u6587\u5199\u4f5c\u7684\u52a8\u673a\u662f\u56e0\u4e3a\u4f5c\u8005\u6ca1\u6709\u627e\u5230\u4e00\u7bc7\u597d\u7684\u6587\u7ae0\uff08\u770b\u4e86wikipedia\u548c\u82e5\u5e72google\u7ed3\u679c\u540e\uff09\u6df1\u5c42\u6b21\u4ecb\u7ecdPCA\u548cKernel PCA\u4e4b\u95f4\u7684\u8054\u7cfb\uff0c\u4ee5\u53ca\u5982\u4f55\u4ee5\u516c\u5f0f\u5f62\u5f0f\u6765\u89e3\u91ca\u5982\u4f55\u5229\u7528Kernel PCA\u6765\u505a\u6295\u5f71\uff0c\u7279\u522b\u6709\u4e9b\u56fe\u7247\u7684\u4f8b\u5b50\u53ea\u662f\u5c55\u793a\u4e86\u7ed3\u679c\u548c\u4e00\u4e9b\u516c\u5f0f\uff0c\u8fd9\u91cc\u9762\u5177\u4f53\u7684\u8fc7\u7a0b\u5e76\u6ca1\u6709\u6d89\u53ca\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u505a\u51fa\u8f83\u597d\u7684\u89e3\u7b54\u3002<\/p>\n<p><strong>1. Kernel Principal Component Analysis \u7684\u77e9\u9635\u57fa\u7840<\/strong><\/p>\n<p>\u6211\u4eec\u4ece\u89e3\u51b3\u8fd9\u51e0\u4e2a\u95ee\u9898\u5165\u624b\uff1a\u4f20\u7edf\u7684PCA\u5982\u4f55\u505a\uff1f\u5728\u9ad8\u7ef4\u7a7a\u95f4\u91cc\u7684PCA\u5e94\u8be5\u5982\u4f55\u505a\uff1f\u5982\u4f55\u7528Kernel Trick\u5728\u9ad8\u7ef4\u7a7a\u95f4\u505aPCA\uff1f\u5982\u4f55\u5728\u4e3b\u6210\u5206\u65b9\u5411\u4e0a\u6295\u5f71\uff1f\u5982\u4f55Centering \u9ad8\u7ef4\u7a7a\u95f4\u7684\u6570\u636e\uff1f<\/p>\n<p><strong>1.1 \u4f20\u7edf\u7684PCA\u5982\u4f55\u505a\uff1f<\/strong><\/p>\n<p>\u8ba9\u6211\u5148\u5b9a\u4e49\u5982\u4e0b\u53d8\u91cf\uff1a [latex] X= [x_1, x_2, \\ldots, x_N] [\/latex] \u662f\u4e00\u4e2a[latex] d \\times N [\/latex]\u77e9\u9635\uff0c\u4ee3\u8868\u8f93\u5165\u7684\u6570\u636e\u6709[latex] N[\/latex] \u4e2a\uff0c\u6bcf\u4e2asample\u7684\u7ef4\u6570\u662f[latex] d [\/latex]\u3002\u6211\u4eec\u505a\u964d\u7ef4\uff0c\u5c31\u662f\u60f3\u7528[latex] k [\/latex]\u7ef4\u7684\u6570\u636e\u6765\u8868\u793a\u539f\u59cb\u7684[latex]d[\/latex]\u7ef4\u6570\u636e\uff08[latex] k \\le d [\/latex]\uff09\u3002<br \/>\n\u5f53\u6211\u4eec\u4f7f\u7528centered\u7684\u6570\u636e\uff08\u5373[latex]\\sum_i x_i = 0[\/latex]\uff09\u65f6\uff0c\u53ef\u5b9a\u4e49\u534f\u65b9\u5dee\u77e9\u9635[latex]C[\/latex]\u4e3a\uff1a<br \/>\n[mathjax]<br \/>\n$$C=\\frac{1}{N} x_i x_i^T = \\frac{1}{N} X X^T$$<br \/>\n\u505a\u7279\u5f81\u503c\u5206\u89e3\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\uff1a<br \/>\n$$CU = U \\Lambda \\Rightarrow C = U \\Lambda U^T = \\sum_a \\lambda_a u_a u_a^T$$<br \/>\n\u6ce8\u610f\u8fd9\u91cc\u7684[latex]C, U , \\Lambda[\/latex]\u7684\u7ef4\u6570\u90fd\u662f[latex]d \\times d[\/latex], \u4e14[latex] U=[u_1, u_2, \\ldots, u_d] [\/latex], [latex]\\Lambda = diag(\\lambda_1, \\lambda_2, \\ldots, \\lambda_d) [\/latex]\u3002<br \/>\n\u5f53\u6211\u4eec\u505a\u964d\u7ef4\u65f6\uff0c\u53ef\u4ee5\u5229\u7528\u524d[latex]k[\/latex]\u4e2a\u7279\u5f81\u5411\u91cf[latex]U_k = [u_1, u_2, \\ldots, u_k] [\/latex]\u3002\u5219\u5c06\u4e00\u4e2a[latex]d[\/latex]\u7ef4\u7684[latex]x_i[\/latex]\u5411[latex]k[\/latex]\u7ef4\u7684\u4e3b\u6210\u5206\u7684\u65b9\u5411\u6295\u5f71\u540e\u7684[latex]y_i = U_k^T x_i[\/latex] \uff08\u8fd9\u91cc\u7684\u6bcf\u4e00\u4e2a[latex]u_i[\/latex]\u90fd\u662f[latex]d[\/latex]\u7ef4\u7684\uff0c\u4ee3\u8868\u662f\u4e00\u4e2a\u6295\u5f71\u65b9\u5411\uff0c\u4e14[latex]u_i^T u_i = 1[\/latex]\uff0c\u8868\u793a\u8fd9\u662f\u4e00\u4e2a\u65cb\u8f6c\u53d8\u91cf\uff09<\/p>\n<p><strong>1.2 \u5728\u9ad8\u7ef4\u7a7a\u95f4\u91cc\u7684PCA\u5e94\u8be5\u5982\u4f55\u505a\uff1f<\/strong><\/p>\n<p>\u9ad8\u7ef4\u7a7a\u95f4\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e00\u4e2a\u6620\u5c04[latex]\\Phi : X^d \\rightarrow \\mathcal{F}[\/latex]\uff0c\u8fd9\u91cc[latex]\\mathcal{F}[\/latex]\u8868\u793aHilbert\u6cdb\u51fd\u7a7a\u95f4\u3002<br \/>\n\u73b0\u5728\u6211\u4eec\u7684\u8f93\u5165\u6570\u636e\u662f[latex]\\Phi(x_i), i = 1, 2, &#8230;n[\/latex]\uff0c \u4ed6\u4eec\u7684\u7ef4\u6570\u53ef\u4ee5\u8bf4\u662f\u65e0\u7a77\u7ef4\u7684\uff08\u6cdb\u51fd\u7a7a\u95f4\uff09\u3002<br \/>\n\u5728\u8fd9\u4e2a\u65b0\u7684\u7a7a\u95f4\u4e2d\uff0c\u5047\u8bbe\u534f\u65b9\u5dee\u77e9\u9635\u540c\u6837\u662fcentered\uff0c\u6211\u4eec\u7684\u534f\u65b9\u5dee\u77e9\u9635\u4e3a\uff1a<br \/>\n$$\\bar{C}=\\frac{1}{N} \\Phi(x_i) \\Phi(x_i)^T = \\frac{1}{N} \\Phi(X) \\Phi(X)^T$$<br \/>\n\u8fd9\u91cc\u6709\u4e00\u4e2a\u9677\u9631\uff0c\u6211\u8df3\u8fdb\u53bb\u8fc7\uff1a<br \/>\n\u5728\u5bf9Kernel trick\u4e00\u77e5\u534a\u89e3\u7684\u65f6\u5019\uff0c\u6211\u4eec\u5e38\u5e38\u4ece\u5f62\u5f0f\u4e0a\u8ba4\u4e3a[latex]\\bar{C} [\/latex]\u53ef\u4ee5\u7528[latex]K_{i,j} = K(x_i, x_j)[\/latex]\u6765\u4ee3\u66ff\uff0c<br \/>\n\u56e0\u6b64\u5bf9[latex]K=(K_{ij})[\/latex]\u505a\u7279\u5f81\u503c\u5206\u89e3\uff0c\u7136\u540e\u5f97\u5230[latex]K=U \\Lambda U^T[\/latex]\uff0c\u5e76\u4e14\u5bf9\u539f\u6709\u6570\u636e\u964d\u7ef4\u7684\u65f6\u5019\uff0c\u5b9a\u4e49[latex]Y_i=U_k^T X_i[\/latex]\u3002<br \/>\n\u4f46\u8fd9\u4e2a\u9519\u8bef\u7684\u65b9\u6cd5\u6709\u4e24\u4e2a\u95ee\u9898\uff1a\u4e00\u662f\u6211\u4eec\u4e0d\u77e5\u9053\u77e9\u9635[latex]\\bar{C}[\/latex]\u7684\u7ef4\u6570\uff1b\u4e8c\u662f[latex]U_k^T X_i[\/latex]\u4ece\u5f62\u5f0f\u4e0a\u770b\u4e0d\u51fa\u662f\u4ece\u9ad8\u7ef4\u7a7a\u95f4\u7684[latex]\\Phi(X_i)[\/latex]\u6295\u5f71\uff0c\u5e76\u4e14\u5f53\u6709\u65b0\u7684\u6570\u636e\u65f6\uff0c\u6211\u4eec\u65e0\u6cd5\u4ece\u7406\u8bba\u4e0a\u7406\u89e3[latex] U_k^T X_{\\mathrm{new}} [\/latex]\u662f\u4ece\u9ad8\u7ef4\u7a7a\u95f4\u7684\u6295\u5f71\u3002<br \/>\n\u5982\u679c\u5e94\u7528\u8fd9\u79cd\u9519\u8bef\u7684\u65b9\u6cd5\uff0c\u6211\u4eec\u6709\u53ef\u80fd\u5f97\u5230\u770b\u8d77\u6765\u5dee\u4e0d\u591a\u6b63\u786e\u7684\u7ed3\u679c\uff0c\u4f46\u672c\u8d28\u4e0a\u8fd9\u662f\u9519\u8bef\u7684\u3002<br \/>\n\u6b63\u786e\u7684\u65b9\u6cd5\u662f\u901a\u8fc7Kernel trick\u5c06PCA\u6295\u5f71\u7684\u8fc7\u7a0b\u901a\u8fc7\u5185\u79ef\u7684\u5f62\u5f0f\u8868\u8fbe\u51fa\u6765\uff0c\u8be6\u7ec6\u89c11.3<\/p>\n<p><strong>1.3 \u5982\u4f55\u7528Kernel Trick\u5728\u9ad8\u7ef4\u7a7a\u95f4\u505aPCA\uff1f<\/strong><\/p>\n<p><strong> <\/strong><\/p>\n<p><strong> <\/strong> \u57281.1\u8282\u4e2d\uff0c\u901a\u8fc7PCA\uff0c\u6211\u4eec\u5f97\u5230\u4e86[latex]U[\/latex]\u77e9\u9635\u3002\u8fd9\u91cc\u5c06\u4ecb\u7ecd\u5982\u4f55\u4ec5\u5229\u7528\u5185\u79ef\u7684\u6982\u5ff5\u6765\u8ba1\u7b97\u4f20\u7edf\u7684PCA\u3002<br \/>\n\u9996\u5148\u6211\u4eec\u8bc1\u660e[latex]U[\/latex]\u53ef\u4ee5\u7531[latex]x_1, x_2, \\ldots, x_N[\/latex]\u5c55\u5f00\uff08span)\uff1a<br \/>\n$$ C u_a = \\lambda_a u_a $$<br \/>\n$$ \\begin{align}<br \/>\nu_a &amp;=  \\frac{1}{\\lambda_a} C u  \\\\<br \/>\n&amp;=  \\frac{1}{\\lambda_a} (\\sum_i x_i x_i^T )u \\\\<br \/>\n&amp;=  \\frac{1}{\\lambda_a} \\sum_i x_i (x_i^T u) \\\\<br \/>\n&amp;=  \\frac{1}{\\lambda_a} \\sum_i  (x_i^T u) x_i \\\\<br \/>\n&amp;=  \\sum_i  \\frac{x_i^T u}{\\lambda_a} x_i \\\\<br \/>\n&amp;= \\sum_i \\alpha_i^a x_i<br \/>\n\\end{align}$$<br \/>\n\u8fd9\u91cc\u5b9a\u4e49[latex]\\alpha_i^a=\\frac{x_i^T u}{\\lambda_a} [\/latex]\u3002<br \/>\n\u56e0\u4e3a[latex]x_i^T u[\/latex] \u662f\u4e00\u4e2a\u6807\u91cf\uff08scala\uff09\uff0c\u6240\u4ee5[latex]\\alpha_i^a[\/latex]\u4e5f\u662f\u4e00\u4e2a\u6807\u91cf\uff0c\u56e0\u6b64[latex]u_i[\/latex] \u662f\u53ef\u4ee5\u7531[latex]x_i[\/latex]\u5f20\u6210\u3002<\/p>\n<p>\u8fdb\u800c\u6211\u4eec\u663e\u793aPCA\u6295\u5f71\u53ef\u4ee5\u7528\u5185\u79ef\u8fd0\u7b97\u8868\u793a\uff0c\u4f8b\u5982\u6211\u4eec\u628a[latex]x_i[\/latex]\u5411\u4efb\u610f\u4e00\u4e2a\u4e3b\u6210\u5206\u5206\u91cf[latex]u_a[\/latex]\u8fdb\u884c\u6295\u5f71\uff0c\u5f97\u5230\u7684\u662f[latex]u_a^T x_i[\/latex]\uff0c\u4e5f\u5c31\u662f[latex]x_i^T u_a[\/latex] \u3002\u4f5c\u8005\u731c\u6d4b\u5199\u6210\u8fd9\u79cd\u5f62\u5f0f\u662f\u4e3a\u4e86\u80fd\u62bd\u51fa[latex]x_i^T x_j = \\mathrm{&lt;} x_i, x_j\\mathrm{&gt;} [\/latex]\u7684\u5185\u79ef\u5f62\u5f0f\u3002<\/p>\n<p>$$\\begin{align}<br \/>\nx_i^T C u_a &amp;= \\lambda_a x_i^T u_a  \\\\<br \/>\nx_i^T \\frac{1}{N} \\sum_j x_j x_j^T \\sum_k \\alpha_k^a x_k &amp;= \\lambda_a x_i^T \\sum_k \\alpha_k^a x_k \\\\<br \/>\n\\sum_j  \\alpha_k^a \\sum_k (x_i^T x_j) (x_j^T x_k) &amp;= N \\lambda_a \\sum_k \\alpha_k^a (x_i^T x_k) \\\\<br \/>\n\\end{align}$$<br \/>\n\u5f53\u6211\u4eec\u5b9a\u4e49[latex] K_{ij} = x_i^T x_j [\/latex]\u65f6\uff0c\u4e0a\u5f0f\u53ef\u4ee5\u5199\u4e3a[latex] K^2 \\alpha = N \\lambda_a K \\alpha^a[\/latex]<br \/>\n\uff08\u8fd9\u91cc[latex]\\alpha^a[\/latex]\u5b9a\u4e49\u4e3a[latex][\\alpha_1^a, \\alpha_2^a, \\ldots, \\alpha_N^a]^T[\/latex].\uff09<br \/>\n\u8fdb\u4e00\u6b65\uff0c\u6211\u4eec\u5f97\u5230\u89e3\u4e3a\uff1a<br \/>\n$$K \\alpha = \\tilde{\\lambda}_a \\alpha \\quad \\mathrm{with} \\quad \\tilde{\\lambda}_a = N \\lambda_a$$<br \/>\n[latex]K[\/latex]\u77e9\u9635\u5305\u542b\u7279\u5f81\u503c[latex]\\tilde{\\lambda}[\/latex]\u548c[latex]\\alpha^a[\/latex]\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7[latex]\\alpha[\/latex]\u53ef\u4ee5\u8ba1\u7b97\u5f97\u5230[latex]u_a[\/latex]\uff0c<br \/>\n\u6ce8\u610f\u7279\u5f81\u503c\u5206\u89e3\u65f6Eigendecomposition\uff0c[latex]\\alpha^a[\/latex]\u53ea\u4ee3\u8868\u4e00\u4e2a\u65b9\u5411\uff0c\u5b83\u7684\u957f\u5ea6\u4e00\u822c\u4e3a1\uff0c\u4f46\u5728\u6b64\u5904\u4e0d\u4e3a1\u3002<br \/>\n\u8fd9\u91cc\u8ba1\u7b97\u51fa[latex]\\alpha_a[\/latex]\u7684\u957f\u5ea6\uff08\u4e0b\u9762\u5c06\u8981\u7528\u5230\uff09\uff1a<br \/>\n\u56e0\u4e3a[latex]u_a[\/latex]\u7684\u957f\u5ea6\u662f1\uff0c\u6211\u4eec\u6709\uff1a<br \/>\n$$\\begin{align}<br \/>\n1 &amp;= u_a^T u_a \\\\<br \/>\n&amp;= ( \\sum_i \\alpha_i^a x_i) ^T (\\sum_j \\alpha_j^a x_j ) \\\\<br \/>\n&amp;= \\sum_i \\sum_j \\alpha_i^a \\alpha_j^a x_i^T x_j^T \\\\<br \/>\n&amp;=(\\alpha^a)^T K \\alpha_a \\\\<br \/>\n&amp;=(\\alpha^a)^T ( N \\lambda_a \\alpha_a) \\\\<br \/>\n&amp;=N \\lambda_a ({\\alpha^a}^T \\alpha_a )\\\\<br \/>\n&amp;\\Rightarrow \\quad  \\lVert \\alpha^a \\rVert = 1\/\\sqrt{N \\lambda_a} = 1\/\\sqrt{\\tilde{\\lambda}_a}<br \/>\n\\end{align}$$<\/p>\n<p>\u5728\u4e0a\u9762\u7684\u5206\u6790\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u53ea\u4f7f\u7528\u4e86\u5185\u79ef\u3002\u56e0\u6b64\u5f53\u6211\u4eec\u628a[latex]K_{ij} = x_i^T x_j[\/latex]\u63a8\u5e7f\u4e3a[latex]K_{ij} = &lt;\\Phi(x_i), \\Phi(x_j&gt; = \\Phi(x_i)^T \\Phi(x_j)[\/latex]\u65f6\uff0c\u4e0a\u9762\u7684\u5206\u6790\u7ed3\u679c\u5e76\u4e0d\u4f1a\u6539\u53d8\u3002<\/p>\n<p><strong>1.4 \u5982\u4f55\u5728\u4e3b\u6210\u5206\u65b9\u5411\u4e0a\u6295\u5f71\uff1f<\/strong><\/p>\n<p>\u6295\u5f71\u65f6\uff0c\u53ea\u9700\u8981\u4f7f\u7528[latex]U[\/latex]\u77e9\u9635\uff0c\u5047\u8bbe\u6211\u4eec\u5f97\u5230\u7684\u65b0\u6570\u636e\u4e3a[latex]t[\/latex]\uff0c\u90a3\u4e48[latex]t[\/latex]\u5728[latex]u_a[\/latex]\u65b9\u5411\u7684\u6295\u5f71\u662f\uff1a<br \/>\n$$u_a^T t =  \\sum_i \\alpha_i^a x_i^T t =  \\sum_i \\alpha_i^a ( x_i^T t)$$<br \/>\n\u5bf9\u4e8e\u9ad8\u7ef4\u7a7a\u95f4\u7684\u6570\u636e[latex]\\Phi(x_i),\\Phi(t)[\/latex]\uff0c\u6211\u4eec\u53ef\u4ee5\u7528Kernel trick\uff0c\u7528[latex]K(x_i, t)[\/latex]\u6765\u5e26\u5165\u4e0a\u5f0f\uff1a<br \/>\n$$u_a^T t =  \\sum_i \\alpha_i^a K(x_i, t)$$<\/p>\n<p><strong>1.5 \u5982\u4f55Centering \u9ad8\u7ef4\u7a7a\u95f4\u7684\u6570\u636e\uff1f<\/strong><\/p>\n<p>\u5728\u6211\u4eec\u7684\u5206\u6790\u4e2d\uff0c\u534f\u65b9\u5dee\u77e9\u9635\u7684\u5b9a\u4e49\u9700\u8981centered data\u3002\u5728\u9ad8\u7ef4\u7a7a\u95f4\u4e2d\uff0c\u663e\u5f0f\u7684\u5c06[latex]\\Phi(x_i)[\/latex]\u5c45\u4e2d\u5e76\u4e0d\u7b80\u5355,<br \/>\n\u56e0\u4e3a\u6211\u4eec\u5e76\u4e0d\u77e5\u9053[latex]\\Phi[\/latex]\u7684\u663e\u793a\u8868\u8fbe\u3002\u4f46\u4ece\u4e0a\u9762\u4e24\u8282\u53ef\u4ee5\u770b\u51fa\uff0c\u6240\u6709\u7684\u8ba1\u7b97\u53ea\u548c[latex]K[\/latex]\u77e9\u9635\u6709\u5173\u3002\u5177\u4f53\u8ba1\u7b97\u5982\u4e0b\uff1a<br \/>\n\u4ee4[latex]\\Phi_i = \\Phi(x_i)[\/latex]\uff0c\u5c45\u4e2d[latex]\\Phi_i^C = \\Phi_i &#8211; \\frac{1}{N}\\sum_k \\Phi_k[\/latex]<br \/>\n$$\\begin{align}<br \/>\nK_{ij}^C<br \/>\n&amp;= &lt;\\Phi_i^C \\Phi_j^C&gt; \\\\<br \/>\n&amp;= (\\Phi_i &#8211; \\frac{1}{N}\\sum_k \\Phi_k)^T (\\Phi_j &#8211; \\frac{1}{N}\\sum_l \\Phi_l \uff09 \\\\<br \/>\n&amp;=\\Phi_i^T\\Phi_j &#8211;  \\frac{1}{N}\\sum_l \\Phi_i^T \\Phi_l &#8211; \\frac{1}{N}\\sum_k \\Phi_k^T \\Phi_j +  \\frac{1}{N^2}\\sum_k \\sum_l \\Phi_k^T \\Phi_l \\\\<br \/>\n&amp;=K_{ij} &#8211;  \\frac{1}{N}\\sum_l K_{il} &#8211; \\frac{1}{N}\\sum_k K_{kj} +  \\frac{1}{N^2}\\sum_k \\sum_l K_{kl}<br \/>\n\\end{align}$$<br \/>\n\u4e0d\u96be\u770b\u51fa\uff0c<br \/>\n$$K^C = K &#8211; 1_N K &#8211; K 1_N + 1_N K 1_N$$<br \/>\n\u5176\u4e2d[latex]1_N[\/latex] \u4e3a[latex]N \\times N [\/latex]\u7684\u77e9\u9635\uff0c\u5176\u4e2d\u6bcf\u4e00\u4e2a\u5143\u7d20\u90fd\u662f[latex]1\/N[\/latex]<br \/>\n\u5bf9\u4e8e\u65b0\u7684\u6570\u636e\uff0c\u6211\u4eec\u540c\u6837\u53ef\u4ee5<br \/>\n$$\\begin{align}<br \/>\nK(x_i, t)^C<br \/>\n&amp;= &lt;\\Phi_i^C \\Phi_t^C&gt; \\\\<br \/>\n&amp;= (\\Phi_i &#8211; \\frac{1}{N}\\sum_k \\Phi_k)^T (\\Phi_t &#8211; \\frac{1}{N}\\sum_l \\Phi_l \uff09 \\\\<br \/>\n&amp;=\\Phi_i^T\\Phi_t &#8211;  \\frac{1}{N}\\sum_l \\Phi_i^T \\Phi_l &#8211; \\frac{1}{N}\\sum_k \\Phi_k^T \\Phi_t +  \\frac{1}{N^2}\\sum_k \\sum_l \\Phi_k^T \\Phi_l \\\\<br \/>\n&amp;=K(x_i,t) &#8211;  \\frac{1}{N}\\sum_l K_{il} &#8211; \\frac{1}{N}\\sum_k K(x_k,t) +  \\frac{1}{N^2}\\sum_k \\sum_l K_{kl}<br \/>\n\\end{align}$$<\/p>\n<p><strong>2. \u6f14\u793a (R code)<\/strong><\/p>\n<p><strong> <\/strong><br \/>\n\u9996\u5148\u6211\u4eec\u5e94\u8be5\u6ce8\u610f\u8f93\u5165\u6570\u636e\u7684\u683c\u5f0f\uff0c\u4e00\u822c\u5728\u7edf\u8ba1\u4e2d\uff0c\u6211\u4eec\u8981\u6c42[latex]X[\/latex]\u77e9\u9635\u662f[latex]N \\times d[\/latex]\u7684\uff0c\u4f46\u5728\u6211\u4eec\u7684\u63a8\u5bfc\u4e2d\uff0c[latex]X[\/latex]\u77e9\u9635\u662f[latex]d \\times N[\/latex]\u3002<br \/>\n\u8fd9\u4e0e\u7edf\u8ba1\u4e0a\u7684\u6982\u5ff5\u5e76\u4e0d\u77db\u76fe\uff1a\u5728\u524d\u9762\u7684\u5b9a\u4e49\u4e0b\u534f\u65b9\u5dee\u77e9\u9635\u4e3a[latex]X^T X[\/latex]\uff0c\u800c\u5728\u540e\u9762\u7684\u5b9a\u4e49\u4e2d\u662f[latex]X X^T[\/latex]\u3002\u53e6\u5916\u8fd9\u91cc\u7684\u534f\u65b9\u5dee\u77e9\u9635\u662f\u6837\u672c\uff08Sample\uff09\u7684\u534f\u65b9\u5dee\u77e9\u9635\uff0c\u6211\u4eec\u7684\u8ba4\u4e3a\u5927\u5199\u7684X\u4ee3\u8868\u77e9\u9635\uff0c\u800c\u4e0d\u662f\u4ee3\u8868\u4e00\u4e2a\u968f\u673a\u53d8\u91cf\u3002<br \/>\n\u53e6\u5916\uff0c\u5728\u4e0b\u9762\u7684\u7ed3\u679c\u4e2d\uff0cGaussian \u6838\u51fd\u6570\uff08kernel function\uff09\u7684\u6807\u51c6\u5dee\uff08sd\uff09\u4e3a2\u3002\u5728\u5176\u4ed6\u53d6\u503c\u6761\u4ef6\u4e0b\uff0c\u6240\u5f97\u5230\u7684\u56fe\u50cf\u662f\u4e0d\u540c\u7684\u3002<\/p>\n<p>KPCA\u56fe\u7247\uff1a<br \/>\n<a href=\"http:\/\/www.zhanxw.com\/blog\/wp-content\/uploads\/2011\/02\/20110206_1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-103\" title=\"20110206_1\" src=\"http:\/\/www.zhanxw.com\/blog\/wp-content\/uploads\/2011\/02\/20110206_1-300x300.png\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/zhanxw.com\/blog\/wp-content\/uploads\/2011\/02\/20110206_1-300x300.png 300w, https:\/\/zhanxw.com\/blog\/wp-content\/uploads\/2011\/02\/20110206_1-150x150.png 150w, https:\/\/zhanxw.com\/blog\/wp-content\/uploads\/2011\/02\/20110206_1.png 614w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>R \u6e90\u4ee3\u7801\uff08Source Code\uff09\uff1a\u94fe\u63a5\u5230\u5b8c\u6574\u7684\u4ee3\u7801\u00a0<a href=\"http:\/\/www.zhanxw.com\/blog\/wp-content\/uploads\/2011\/02\/KernelPCA.r\">KernelPCA<\/a><\/p>\n<p>Kernel PCA\u90e8\u5206\u4ee3\u7801\uff1a<\/p>\n<pre class=\"brush: r; title: ; notranslate\" title=\"\">\r\n# Kernel PCA\r\n# Polynomial Kernel\r\n# k(x,y) = t(x) %*% y + 1\r\nk1 = function (x,y) { (x&#x5B;1] * y&#x5B;1] + x&#x5B;2] * y&#x5B;2] + 1)^2 }\r\nK = matrix(0, ncol = N_total, nrow = N_total)\r\nfor (i in 1:N_total) {\r\n  for (j in 1:N_total) {\r\n    K&#x5B;i,j] = k1(X&#x5B;i,], X&#x5B;j,])\r\n}}\r\nones = 1\/N_total* matrix(1, N_total, N_total)\r\nK_norm = K - ones %*% K - K %*% ones + ones %*% K %*% ones\r\nres = eigen(K_norm)\r\n\r\nV = res$vectors\r\nD = diag(res$values)\r\n\r\nrank = 0\r\nfor (i in 1:N_total) {\r\n\tif (D&#x5B;i,i] &lt; 1e-6) { break }\r\n      V&#x5B;,i] = V&#x5B;,i] \/ sqrt (D&#x5B;i,i])\r\n\trank = rank + 1\r\n}\r\nY = K_norm %*%  V&#x5B;,1:rank]\r\nplot(Y&#x5B;,1], Y&#x5B;,2], col = rainbow(3)&#x5B;label], main = &quot;Kernel PCA (Poly)&quot;\r\n, xlab=&quot;First component&quot;, ylab=&quot;Second component&quot;)\r\n<\/pre>\n<p><strong>3. \u4e3b\u8981\u53c2\u8003\u8d44\u6599<\/strong><\/p>\n<p><strong><br \/>\n<\/strong><\/p>\n<p>\u30101\u3011A Tutorial on Principal Component Analysis ,Jonathon Shlens\u0003, <a href=\"http:\/\/www.zhanxw.com\/blog\/wp-content\/uploads\/2011\/02\/Shlens03.pdf\">Shlens03<\/a><\/p>\n<p>\u30102\u3011Wikipedia\uff1a http:\/\/en.wikipedia.org\/wiki\/Kernel_principal_component_analysis<\/p>\n<p>\u30103\u3011 Original KPCA Paper\uff1aKernel principal component analysis\uff0cBernhard Sch\u00f6lkopf, Alexander Smola and Klaus-Robert M\u00fcller\u00a0<a href=\"http:\/\/www.springerlink.com\/content\/w0t1756772h41872\/fulltext.pdf\">http:\/\/www.springerlink.com\/content\/w0t1756772h41872\/fulltext.pdf<\/a><\/p>\n<p>\u30104\u3011Max Wellings&#8217;s classes notes for machine learning Kernel Principal Component Analaysis\u00a0<a href=\"http:\/\/www.ics.uci.edu\/~welling\/classnotes\/papers_class\/Kernel-PCA.pdf\">http:\/\/www.ics.uci.edu\/~welling\/classnotes\/papers_class\/Kernel-PCA.pdf<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3b\u6210\u4efd\uff08Principal Component Analysis\uff09\u5206\u6790\u662f\u964d\u7ef4\uff08Dimension Reduction\uff09\u7684\u91cd\u8981\u624b\u6bb5\u3002\u6bcf\u4e00\u4e2a\u4e3b\u6210\u5206\u90fd\u662f\u6570\u636e\u5728\u67d0\u4e00\u4e2a\u65b9\u5411\u4e0a\u7684\u6295\u5f71\uff0c\u5728\u4e0d\u540c\u7684\u65b9\u5411\u4e0a\u8fd9\u4e9b\u6570\u636e\u65b9\u5deeVariance\u7684\u5927\u5c0f\u7531\u5176\u7279\u5f81\u503c\uff08eigenvalue\uff09\u51b3\u5b9a\u3002\u4e00\u822c\u6211\u4eec\u4f1a\u9009\u53d6\u6700\u5927\u7684\u51e0\u4e2a\u7279\u5f81\u503c\u6240\u5728\u7684\u7279\u5f81\u5411\u91cf\uff08eigenvector\uff09\uff0c\u8fd9\u4e9b\u65b9\u5411\u4e0a\u7684\u4fe1\u606f\u4e30\u5bcc\uff0c\u4e00\u822c\u8ba4\u4e3a\u5305\u542b\u4e86\u66f4\u591a\u6211\u4eec\u6240\u611f\u5174\u8da3\u7684\u4fe1\u606f\u3002\u5f53\u7136\uff0c\u8fd9\u91cc\u9762\u6709\u8f83\u5f3a\u7684\u5047\u8bbe\uff1a\uff081\uff09\u7279\u5f81\u6839\u7684\u5927\u5c0f\u51b3\u5b9a\u4e86\u6211\u4eec\u611f\u5174\u8da3\u4fe1\u606f\u7684\u591a\u5c11\u3002\u5373\u5c0f\u7279\u5f81\u6839\u5f80\u5f80\u4ee3\u8868\u4e86\u566a\u58f0\uff0c\u4f46\u5b9e\u9645\u4e0a\uff0c\u5411\u5c0f\u4e00\u70b9\u7684\u7279\u5f81\u6839\u65b9\u5411\u6295\u5f71\u4e5f\u6709\u53ef\u80fd\u5305\u62ec\u6211\u4eec\u611f\u5174\u8da3\u7684\u6570\u636e\uff1b \uff082\uff09\u7279\u5f81\u5411\u91cf\u7684\u65b9\u5411\u662f\u4e92\u76f8\u6b63\u4ea4\uff08orthogonal\uff09\u7684\uff0c\u8fd9\u79cd\u6b63\u4ea4\u6027\u4f7f\u5f97PCA\u5bb9\u6613\u53d7\u5230Outlier\u7684\u5f71\u54cd\uff0c\u4f8b\u5982\u5728\u30101\u3011\u4e2d\u63d0\u5230\u7684\u4f8b\u5b50\uff083\uff09\u96be\u4e8e\u89e3\u91ca\u7ed3\u679c\u3002\u4f8b\u5982\u5728\u5efa\u7acb\u7ebf\u6027\u56de\u5f52\u6a21\u578b\uff08Linear Regression Model\uff09\u5206\u6790\u56e0\u53d8\u91cf\uff08response\uff09\u548c\u7b2c\u4e00\u4e2a\u4e3b\u6210\u4efd\u7684\u5173\u7cfb\u65f6\uff0c\u6211\u4eec\u5f97\u5230\u7684\u56de\u5f52\u7cfb\u6570\uff08Coefficiency\uff09\u4e0d\u662f\u67d0\u4e00\u4e2a\u81ea\u53d8\u91cf\uff08covariate\uff09\u7684\u8d21\u732e\uff0c\u800c\u662f\u5bf9\u6240\u6709\u81ea\u53d8\u91cf\u7684\u67d0\u4e2a\u7ebf\u6027\u7ec4\u5408\uff08Linear Combination\uff09\u7684\u8d21\u732e\u3002 \u5728Kernel PCA\u5206\u6790\u4e4b\u4e2d\uff0c\u6211\u4eec\u540c\u6837\u9700\u8981\u8fd9\u4e9b\u5047\u8bbe\uff0c\u4f46\u4e0d\u540c\u7684\u5730\u65b9\u662f\u6211\u4eec\u8ba4\u4e3a\u539f\u6709\u6570\u636e\u6709\u66f4\u9ad8\u7684\u7ef4\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u66f4\u9ad8\u7ef4\u7684\u7a7a\u95f4\uff08Hilbert Space\uff09\u4e2d\u505aPCA\u5206\u6790\uff08\u5373\u5728\u66f4\u9ad8\u7ef4\u7a7a\u95f4\u91cc\uff0c\u628a\u539f\u59cb\u6570\u636e\u5411\u4e0d\u540c\u7684\u65b9\u5411\u6295\u5f71\uff09\u3002\u8fd9\u6837\u505a\u7684\u4f18\u70b9\u6709\uff1a\u5bf9\u4e8e\u5728\u901a\u5e38\u7ebf\u6027\u7a7a\u95f4\u96be\u4e8e\u7ebf\u6027\u5206\u7c7b\u7684\u6570\u636e\u70b9\uff0c\u6211\u4eec\u6709\u53ef\u80fd\u518d\u66f4\u9ad8\u7ef4\u5ea6\u4e0a\u627e\u5230\u5408\u9002\u7684\u9ad8\u7ef4\u7ebf\u6027\u5206\u7c7b\u5e73\u9762\u3002\u6211\u4eec\u7b2c\u4e8c\u90e8\u5206\u7684\u4f8b\u5b50\u5c31\u8bf4\u660e\u4e86\u8fd9\u4e00\u70b9\u3002 \u672c\u6587\u5199\u4f5c\u7684\u52a8\u673a\u662f\u56e0\u4e3a\u4f5c\u8005\u6ca1\u6709\u627e\u5230\u4e00\u7bc7\u597d\u7684\u6587\u7ae0\uff08\u770b\u4e86wikipedia\u548c\u82e5\u5e72google\u7ed3\u679c\u540e\uff09\u6df1\u5c42\u6b21\u4ecb\u7ecdPCA\u548cKernel PCA\u4e4b\u95f4\u7684\u8054\u7cfb\uff0c\u4ee5\u53ca\u5982\u4f55\u4ee5\u516c\u5f0f\u5f62\u5f0f\u6765\u89e3\u91ca\u5982\u4f55\u5229\u7528Kernel PCA\u6765\u505a\u6295\u5f71\uff0c\u7279\u522b\u6709\u4e9b\u56fe\u7247\u7684\u4f8b\u5b50\u53ea\u662f\u5c55\u793a\u4e86\u7ed3\u679c\u548c\u4e00\u4e9b\u516c\u5f0f\uff0c\u8fd9\u91cc\u9762\u5177\u4f53\u7684\u8fc7\u7a0b\u5e76\u6ca1\u6709\u6d89\u53ca\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u505a\u51fa\u8f83\u597d\u7684\u89e3\u7b54\u3002 1. Kernel Principal Component Analysis \u7684\u77e9\u9635\u57fa\u7840 \u6211\u4eec\u4ece\u89e3\u51b3\u8fd9\u51e0\u4e2a\u95ee\u9898\u5165\u624b\uff1a\u4f20\u7edf\u7684PCA\u5982\u4f55\u505a\uff1f\u5728\u9ad8\u7ef4\u7a7a\u95f4\u91cc\u7684PCA\u5e94\u8be5\u5982\u4f55\u505a\uff1f\u5982\u4f55\u7528Kernel Trick\u5728\u9ad8\u7ef4\u7a7a\u95f4\u505aPCA\uff1f\u5982\u4f55\u5728\u4e3b\u6210\u5206\u65b9\u5411\u4e0a\u6295\u5f71\uff1f\u5982\u4f55Centering \u9ad8\u7ef4\u7a7a\u95f4\u7684\u6570\u636e\uff1f 1.1 \u4f20\u7edf\u7684PCA\u5982\u4f55\u505a\uff1f \u8ba9\u6211\u5148\u5b9a\u4e49\u5982\u4e0b\u53d8\u91cf\uff1a [latex] X= [x_1, x_2, \\ldots, x_N] [\/latex] \u662f\u4e00\u4e2a[latex] d \\times N [\/latex]\u77e9\u9635\uff0c\u4ee3\u8868\u8f93\u5165\u7684\u6570\u636e\u6709[latex] N[\/latex] \u4e2a\uff0c\u6bcf\u4e2asample\u7684\u7ef4\u6570\u662f[latex] d [\/latex]\u3002\u6211\u4eec\u505a\u964d\u7ef4\uff0c\u5c31\u662f\u60f3\u7528[latex] k [\/latex]\u7ef4\u7684\u6570\u636e\u6765\u8868\u793a\u539f\u59cb\u7684[latex]d[\/latex]\u7ef4\u6570\u636e\uff08[latex] k \\le d [\/latex]\uff09\u3002 \u5f53\u6211\u4eec\u4f7f\u7528centered\u7684\u6570\u636e\uff08\u5373[latex]\\sum_i x_i = 0[\/latex]\uff09\u65f6\uff0c\u53ef\u5b9a\u4e49\u534f\u65b9\u5dee\u77e9\u9635[latex]C[\/latex]\u4e3a\uff1a [mathjax] $$C=\\frac{1}{N} x_i [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[18,16,17,19],"class_list":["post-66","post","type-post","status-publish","format-standard","hentry","category-statistics","tag-kernel","tag-machine-learning","tag-pca","tag-statistics-2"],"_links":{"self":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/posts\/66","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/comments?post=66"}],"version-history":[{"count":0,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/posts\/66\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/media?parent=66"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/categories?post=66"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/tags?post=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}