library(TFTSA) library(ggplot2)
tmlzzloess <- read.csv("D://data//thesis//201610//tmlzzloess.csv",header = T) tmlzznew <- read.csv("D://data//thesis//201610//tmlzznew.csv",header = T) rownames(tmlzzloess) <- tmlzzloess[,1] tmlzzloess <- tmlzzloess[,-1] rownames(tmlzznew) <- tmlzznew[,1] tmlzznew <- tmlzznew[,-1]
tmlzz和tmlzznew的第一列均为日期,需要将其换为行名。
tmlobj <- tmlzznew[6,] tmlbase <- tmlzzloess[-6,]
选择预测序列为10月6日,其余的序列作为样本库
pre_imbalance <- flow_knn(obj = tmlobj,base = tmlbase,start = 73,k = 5,lag_duration = 30,fore_duration = 8, save_detail = "D:\\交大云同步\\论文\\大论文\\实验\\结果表\\imbalance2.csv",imbalance=T)
flow_forecastplot(tmlobj,pre_imbalance)
ggsave("D:\\王致远\\论文\\大论文\\实验\\绘图\\K近邻imbalance预测.jpg",width=7.29,height=4.5,dpi=600)
ggsave(file="plot/05_imbalance_loess.jpg",width=7.29,height=4.5,dpi=600)
flow_evaluate(tmlobj,pre_imbalance)
残差分析
res_imbalance <- tmlobj[73:288] - pre_imbalance[73:288] x <- plot(73:288,res_imbalance) x <- abline(h=0)
pre1006 <- TFTSA::flow_knn(tmlobj,tmlbase,start = 73,k = 3,lag_duration = 22,fore_duration = 6)
preall <- rbind(tmlobj,pre1006,pre_imbalance) preall <- t(preall) preall <- as.data.frame(preall) preall[4] <- 1:288 names(preall) <- c("real value","normal","asymmetric","timestamp") preall <- melt(preall,id.vars = "timestamp") ggplot(preall,aes(x=timestamp,y=value,group=variable,color=variable))+ geom_line()+geom_point()+ scale_colour_manual(values=c("steelblue","orange","red"))+ xlab("Timestamp")+ylab("Traffic volume")+labs(color="Legend")+ scale_x_continuous(breaks = seq(0,288,24))+ scale_y_continuous(breaks = seq(0,120,20))+ theme_bw()
ggsave("D:\\交大云同步\\论文\\小论文\\4_基于KNN方法的短时交通流序列非对称损失预测\\绘图\\K近邻全家福2V2.jpg",width=7.29,height=4.5,dpi=600)
ggsave(file="plot/05_balance_imbalance_loess.jpg",width=7.29,height=4.5,dpi=600)
ggplot(preall,aes(1:288,preall$real))+geom_point(colour="steelblue")+geom_line(colour="steelblue")+ geom_line(aes(1:288,preall$balance),colour="orange",size=1)+ geom_line(aes(1:288,preall$imbalance),colour="red",size=1)+ xlab("Timestamp")+ylab("Traffic flow rate")+ scale_x_continuous(breaks = seq(0,288,24))+ scale_y_continuous(breaks = seq(0,120,20))
ggsave("D:\\王致远\\论文\\大论文\\实验\\绘图\\K近邻全家福.jpg",width=7.29,height=4.5,dpi=600)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.