0
$\begingroup$

I want to apply support vector regression (SVR) model parameters to a higher spatial scale using the predict function, but the results are wrong. Here is how the resulting raster is: svr_res

The steps I followed were:

  1. perform regression using the svm function at a coarser spatial scale
  2. using the predict function and a fine resolution raster I produced the raster showing in the image above.

Here is the code:

library(e1071)
library(terra)
library(raster)

ntl = rast("path/ntl.tif") # coarse resolution raster
tirs = rast("path/tirs.tif") # fine resolution raster
tirs_res = resample(tirs, ntl, method = "bilinear")

a = c(ntl, tirs_res)

# Regression with SVM
modelsvm = svm(ntl ~ tirs, data = a)

# Predict using SVM regression
predYsvm = as.data.frame(predict(modelsvm, tirs))

# here I am just converting the result of the predict to a raster
tirsdf = as.data.frame(tirs, xy = TRUE)
svrpred = as.data.frame(cbind(tirsdf, as.data.frame(predYsvm)))
svr_pred = subset(svrpred, select = -tirs)
colnames(svr_pred)[3] = "tirs"
svr_pred <- SpatialPointsDataFrame(data = svr_pred, coords = cbind(svr_pred$x, svr_pred$y)) 
gridded(svr_pred) <- TRUE
svr_pred <- raster(svr_pred)
raster::crs(svr_pred) <- "EPSG:7767"
plot(svr_pred)

Any ideas why the resulting raster looks like this?

The data:

ntl = rast(ncols=11, nrows=21, nlyrs=1, xmin=581428.888, xmax=603703.888, ymin=1004925.5202, ymax=1047450.5202, names=c('ntl'), crs='EPSG:7767')

tirs = rast(ncols=48, nrows=93, nlyrs=1, xmin=582525, xmax=604125, ymin=1005525, ymax=1047375, names=c('tirs'), crs='EPSG:7767')
$\endgroup$

1 Answer 1

0
$\begingroup$
library(terra)
library(raster)
library(e1071)

ntl = rast("path/ntl.tif")
tirs = rast("path/tirs.tif")
tirsres = resample(tirs, ntl, method = "bilinear")

s = c(ntl, tirsres)

m = svm(ntl~., data = s)
p = as.data.frame(predict(m, tirs))

df = as.data.frame(tirs, xy = TRUE)
df2 = as.data.frame(cbind(df, p))
df2 <- df2[-3]
colnames(df2)[3] = "tirs"
r <- rasterFromXYZ(df2)
plot(r)

svr_pred

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.