---
title: "墨尔本房价分析报告"
author: "Jean"
date: "`r Sys.Date()`"
header-includes:
  - \usepackage{ctex}
output: 
  pdf_document:
    latex_engine: xelatex
params:
  algo: NA
  threshold: NA
  rows: NA
  perf: NA
  train: NA
  valid: NA
  outliers: NA
---

# 各回归算法性能数据：

```{r}
perf<-params$perf                # 传入参数被锁定不能改变，赋值其它变量。
perf[,-1]<- round(perf[,-1],3)   # 除第一列算法名称外，舍入至小数点后3位。
names(perf)<-c("算法","训练集","验证集","耗时(秒)")
knitr::kable(perf)
```



# 算法：`r params$algo` ，异常值阀值：`r params$threshold`%。


## 训练集拟合效果


```{r fig.showtext = TRUE}
library(ggplot2)
library(showtext)
# Rmarkdown安装配置、输出PDF正文中文以及图片中文配置
# https://blog.csdn.net/weixin_46128755/article/details/125825935
# 设置showtext_auto()，打开ggplot2中文支持。 
showtext_auto() 



data<-params$train
ggplot(data = data)+
      geom_point(mapping = aes(x = index, y = predict, color = "blue"), size=0.1)+
      geom_line(mapping = aes(x = index, y = origin, color = "red"))+
      geom_ribbon(aes(index, ymax=upper, ymin=lower, fill="yellow"), alpha=0.25)+
      ggtitle("训练集拟合效果图")+
      xlab("样本")+
      ylab("ln(房价)")+
      scale_fill_identity(name = '异常值区间', guide = 'legend',labels = c('正常值')) +
      scale_colour_manual(name = '颜色', 
            values =c('blue'='blue','red'='red'), labels = c('预测值','实际值'))
```









## 验证集拟合效果

```{r fig.showtext = TRUE}
data<-params$valid
ggplot(data = data)+
      geom_point(mapping = aes(x = index, y = predict, color = "blue"), size=0.1)+
      geom_line(mapping = aes(x = index, y = origin, color = "red"))+
      geom_ribbon(aes(index, ymax=upper, ymin=lower, fill="yellow"), alpha=0.25)+
      ggtitle("验证集拟合效果图")+
      xlab("样本")+
      ylab("ln(房价)")+
      scale_fill_identity(name = '异常值区间', guide = 'legend',labels = c('正常值')) +
      scale_colour_manual(name = '颜色', 
                          values =c('blue'='blue','red'='red'), labels = c('预测值','实际值'))

```

## 异常值列表

```{r}
outliers<-head(params$outliers,10) # 演示性质，只打印前10行。
names(outliers)<-c("纬度","经度","距离","建筑面积","占地面积","建成","交易","类型",
                   "价格","预测","偏差")
knitr::kable(outliers)
```


## 选中的异常值行号：`r params$rows`。


