如何将数据投影到特定方向上

例如,我有两组数据,它们都是二维的。现在的问题是如何将这两组数据投影到一条线性方程上。

%%% Here is the data %%%%%% The data are Gaussian distributed with means m1 and  m2, %%%%%% and have a common covariance matrix C %%%m1 = [0 3]'; %%% mean of data set 1m2 = [3 2.5]';  %%% mean of data set 2C1 = [2 1;1 2]; %%% covariance matrix %%%C2 = [2 1;1 2]; %%% covariance matrix %%%X1 = mvnrnd(m1,C1,N);X2 = mvnrnd(m2,C2,N);plot(X1(:,1),X1(:,2),'bx',X2(:,1),X2(:,2),'ro');grid on

回答:

这里提供了一个解决方案,假设你想要将数据正交投影到一条线上。这可能不是最有效的实现方式,但至少步骤易于理解。

这条线由参数 ab 定义为:y = a*x + b;

N = 3;%%% Here is the data %%%%%% The data are Gaussian distributed with means m1 and  m2, %%%%%% and have a common covariance matrix C %%%m1 = [0 3]'; %%% mean of data set 1m2 = [3 2.5]';  %%% mean of data set 2C1 = [2 1;1 2]; %%% covariance matrix %%%C2 = [2 1;1 2]; %%% covariance matrix %%%X1 = mvnrnd(m1,C1,N);X2 = mvnrnd(m2,C2,N);figureplot(X1(:,1),X1(:,2),'bx',X2(:,1),X2(:,2),'rx');grid onaxis equal% equation of the line% y = a*x + b a = 1;b = 1;% normalized directional vector of the lines = [a, a^2];s = s./norm(s);% translate points for easier workX1(:,2) = X1(:,2)-b;X2(:,2) = X2(:,2)-b;% projectionX1p = (X1*s')*s;X2p = (X2*s')*s;% tranlate the points backX1p(:,2) = X1p(:,2)+b;X2p(:,2) = X2p(:,2)+b;xx = -4:8;hold onplot(xx, a*xx+b, 'green')plot(X1p(:,1),X1p(:,2),'bo',X2p(:,1),X2p(:,2),'ro')xlabel('x')ylabel('y')title('Orthogonal projection')

x 是原始点,而 o 是它的投影。enter image description here

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注