【发布时间】:2016-11-11 03:54:06
【问题描述】:
enter image description here我正在尝试使用随机森林来生成空间预测图。
我使用随机森林回归开发了我的模型,但在最后一步中遇到了一点困难,即使用最佳预测器来构建预测图。我想创建一个地图预测图。
我的代码:
library(raster)
library(randomForest)
set.seed(12)
s <- stack("Density.tif", "Aqui.tif", "Rech.tif", "Rainfall.tif","Land Use.tif", "Cond.tif", "Nitrogen.tif", "Regions.tif","Soil.tif","Topo.tif", "Climatclass.tif", "Depth.tif")
points <- read.table("Coordonnées3.txt",header=TRUE, sep="\t", dec=",",strip.white=TRUE)
d <- extract(s, points)
rf <-randomForest(nitrate~ . , data=d, importance=TRUE, ntree=500, na.action = na.roughfix)
p <- predict(s, rf)
plot(p)
样本数据:
> head(points)
LAT LONG
1 -13.057007 27.549580
2 -4.255000 15.233745
3 5.300000 -1.983610
4 7.245675 -4.233336
5 12.096330 15.036016
6 -4.255000 15.233745
我运行短代码时的错误是:
Error in eval(expr, envir, enclos) : object 'nitrate' not found.
【问题讨论】:
-
head(d)将有助于更好地调试您的问题,并查看d是否有 nitrate 或 Nitrogen 作为列名。 -
哪一行代码产生了错误?是模型拟合还是预测?
-
我在该步骤运行时出现代码错误:rf
-
我有十二个光栅格式的预测变量。不同的栅格存储在: s
标签: r random prediction