1、缺失率10%
(1)长沙数据
a=xlsread('data.xls');
X1=reshape(a,[12,24,20,13]);
[m,n,k,l]=size(X1);
q=m*n*k*l;
ratio=0.1;%设定随机缺失率,为10%
randoo=randperm(q,fix(q*ratio)); %随机设定缺失点,不重复抽样
rando=randoo(X1(randoo)~=0);%避免提取出的真实数据为0,造成mape值为inf
Count=1;
miss=1;
missing_value{Count,miss}=rando'; %缺失的数据储存并排序
Real{Count,miss}=X1(rando)'; %提取出真实数据
%-------------------直接替换缺失数据--------------%
X1(rando)=0;
X1=tensor(X1);
missing_X1{1,1}=X1;
%--------------cp_als--------------------------------------%
R=5;
[P1,~,F1] = cp_als(X1,R); %随机产生主成份矩阵
Px=double(full(P1));
plot(Px(rando));
hold on;
plot(X1(rando));
1个路段 1天,缺失数据与修复数据对比效果:
c=xlsread('data.xls','sheet1','A1:A288');
plot(c,'o');
X2=double(X1);
aa=X2(:,:,1,1);%原始数据
zz = reshape(aa,288,1);
hold on;
plot(zz,'*');
(1)广州数据
a=xlsread('data.xls');
X1=reshape(a,[12,24,20,13]);
[m,n,k,l]=size(X1);
q=m*n*k*l;
ratio=0.1;%设定随机缺失率,为10%
randoo=randperm(q,fix(q*ratio)); %随机设定缺失点,不重复抽样
rando=randoo(X1(randoo)~=0);%避免提取出的真实数据为0,造成mape值为inf
Count=1;
miss=1;
missing_value{Count,miss}=rando'; %缺失的数据储存并排序
Real{Count,miss}=X1(rando)'; %提取出真实数据
%-------------------直接替换缺失数据--------------%
X1(rando)=0;
X1=tensor(X1);
missing_X1{1,1}=X1;
%--------------cp_als--------------------------------------%
R=5;
[P1,~,F1] = cp_als(X1,R); %随机产生主成份矩阵
Px=double(full(P1));
1个路段 1天,缺失数据与修复数据对比效果:
c=xlsread('data.xls','sheet1','A1:A288');
plot(c,'o');
x2=double(x1);
aa=X2(:,:,1,1);%原始数据
zz = reshape(aa,288,1);
hold on;
plot(zz,'*');
(2)广州数据
a=csvread('tensor.csv');
X1=reshape(a,[214,61,144]);
[m,n,k]=size(X1);
q=m*n*k;
ratio=0.1;
randoo=randperm(q,fix(q*ratio));
rando=randoo(X1(randoo)~=0);
Count=1;
miss=1;
missing_value{Count,miss}=rando';
Real{Count,miss}=X1(rando)';
X1(rando)=0;
X1=tensor(X1);
missing_X1{1,1}=X1;
R=5;
[P1,~,F1] = cp_als(X1,R);
Px=double(full(P1));
X2=double(X1);
aa=X2(:,1,1);
size(aa)
plot(aa,'*')
bb=Px(:,1,1)
hold on
plot(bb,'o')
2、缺失率10-90%
(1) 长沙数据
a=xlsread('data.xls'); %长沙数据
X1=reshape(a,[12,24,20,13]);%形成四阶张量
[m,n,k,l]=size(X1);
q=m*n*k*l;
R=5;
Count=1;%第一次实验
a1=cell(1,9);
for miss=1:9 %%设定随机缺失率,从10%-90%
ratio=miss/10;%数据缺失率
X1=double(X1);
randoo=randperm(q,fix(q*ratio)); %随机设定缺失点,不重复抽样
rando=randoo(X1(randoo)~=0); %避免提取出的真实数据为0,造成mape值为inf
missing_value{1,miss}=rando';%缺失的数据储存并排序
Real{1,miss}=X1(rando)'; %提取出真实数据
%-------------------直接替换缺失数据--------------%
X1(rando)=0;
X1=tensor(X1);
missing_X1{1,miss}=X1;
%--------------cp_als--------------------------------------%
[P1,~,F1] = cp_als(X1,R); %随机产生主成份矩阵
Px=double(full(P1));
a1{miss}=Px(:,:,1,1);
Impute_cpals{1,miss}=Px(rando)'; %保存修复后的张量
X_full=double(X1);
X_full(rando)=Px(rando);
X_full_cpals{1,miss}=X_full;
mape_01(R,miss)=mean(abs(Real{1,miss}-Impute_cpals{1,miss})./Real{1,miss});
mad_01(R,miss)=mean(abs(Real{1,miss}-Impute_cpals{1,miss}));
rmse_01(R,miss)=sqrt(sum((Real{1,miss}-Impute_cpals{1,miss}).^2)/length(Real{1,miss}))
error_cpals{1}=[mape_01;mad_01;rmse_01];
end
做图
aa1 = reshape(a1{1},288,1);
aa2 = reshape(a1{2},288,1);
aa3 = reshape(a1{3},288,1);
aa4 = reshape(a1{4},288,1);
plot(aa1,'*'); %10%缺失估计
hold on;
plot(aa2,'o'); %20%缺失估计
plot(aa3,'+'); %30%缺失估计
plot(aa4,'-'); %40%缺失估计
c=xlsread('data.xls','sheet1','A1:A288');%原始数据
plot(c,'k');
(2)广州数据
a=csvread('tensor.csv');
X1=reshape(a,[214,61,144]);
[m,n,k]=size(X1);
q=m*n*k;
R=5;
Count=1;%第一次实验
a1=cell(1,9);
for miss=1:9 %%设定随机缺失率,从10%-90%
ratio=miss/10;%数据缺失率
X1=double(X1);
randoo=randperm(q,fix(q*ratio)); %随机设定缺失点,不重复抽样
rando=randoo(X1(randoo)~=0); %避免提取出的真实数据为0,造成mape值为inf
missing_value{1,miss}=rando';%缺失的数据储存并排序
Real{1,miss}=X1(rando)'; %提取出真实数据
%-------------------直接替换缺失数据--------------%
X1(rando)=0;
X1=tensor(X1);
missing_X1{1,miss}=X1;
%--------------cp_als--------------------------------------%
[P1,~,F1] = cp_als(X1,R); %随机产生主成份矩阵
Px=double(full(P1));
a1{miss}=Px(:,1,1);
Impute_cpals{1,miss}=Px(rando)'; %保存修复后的张量
X_full=double(X1);
X_full(rando)=Px(rando);
X_full_cpals{1,miss}=X_full;
mape_01(R,miss)=mean(abs(Real{1,miss}-Impute_cpals{1,miss})./Real{1,miss});
mad_01(R,miss)=mean(abs(Real{1,miss}-Impute_cpals{1,miss}));
rmse_01(R,miss)=sqrt(sum((Real{1,miss}-Impute_cpals{1,miss}).^2)/length(Real{1,miss}))
error_cpals{1}=[mape_01;mad_01;rmse_01];
end
plot(a1{1},'*'); %10%缺失估计
hold on;
plot(a1{2},'o'); %20%缺失估计
plot(a1{3},'+'); %30%缺失估计
plot(a1{4},'-'); %40%缺失估计
aa=a(:,1)
plot(aa,'k');
评论0