我有一个包含多列的数据集merge_dataset
,其中一列是预测值(pred
),另一列是观测值(obs
)。
merge_dataset$pred
[1] 36.41901 50.00570 44.41968 43.38756 28.80257 36.39163 37.39804 36.32962 35.00418
[10] 35.00418 37.92272 33.11299 35.82360 34.53261 37.79355 31.70374 41.28555 34.87378
[19] 27.17277 28.04712 31.10107 39.51379 30.72352 30.56177 42.07559 28.97135 38.05332
[28] 31.50711 32.25771 39.06402 40.32990 31.78645 32.17490 40.02865 37.29828 47.60369
[37] 29.95663 41.07608 32.37870 36.39109 34.48480 40.92303 40.66437 38.63980 37.21365
[46] 33.39188 33.87645 32.86183 35.15551 35.19239 33.34504 27.11312 29.90129 31.73539
[55] 34.81175 31.74837 31.87544 29.63221 32.11695 31.53366 43.92894 37.67079 34.15102
[64] 27.68639 34.26138 37.71410 38.53976 42.43867 33.38520 30.08463 21.81946 23.62587
[73] 41.48358 35.59260 40.80595 43.72809 39.26484 33.18791 33.16686 30.35059 41.52940
[82] 29.18899 27.40003 31.25527 29.66598 37.99582 36.22690 36.22690 40.03365 38.48178
[91] 39.08097 37.40256 36.05578 41.64576 41.58584 41.58584 31.10107 31.10107 34.92721
[100] 33.38520 38.48178 32.10891 33.37898 38.83923 36.34332 34.18471 33.25552 29.90313
[109] 49.01674 46.34013 46.34013 35.06786 38.87329 33.79266 40.20175 38.01807 41.66636
[118] 43.67379 42.64595 24.08709 34.39273 38.94325 21.25835 18.86598 26.60233 29.43220
[127] 30.74550 37.39969 28.62814 28.44397 36.36519 29.33948
merge_dataset$obs
[1] 28.1 56.2 39.1 42.9 27.0 34.3 28.1 37.4 32.6 34.7 27.0 32.5 50.4 46.3 25.4 37.9 30.7
[18] 31.1 25.7 34.5 32.3 34.2 28.4 22.1 37.2 25.2 39.3 32.7 29.8 38.1 38.4 26.6 26.6 40.5
[35] 44.2 53.4 27.5 47.1 26.0 26.7 30.2 54.7 58.5 49.5 53.0 38.2 33.4 46.2 27.7 27.8 29.2
[52] 24.0 27.3 31.4 41.3 52.1 32.1 27.7 25.5 40.6 28.2 29.5 29.3 36.9 32.1 33.3 41.3 45.1
[69] 26.6 37.3 23.2 25.5 39.2 40.4 42.8 51.9 39.4 28.1 30.1 24.6 33.6 34.9 23.0 26.3 29.2
[86] 51.2 44.4 43.1 31.3 39.6 48.8 46.3 43.6 51.8 54.5 53.4 31.8 30.8 42.6 35.3 30.6 25.3
[103] 24.6 26.9 41.8 24.6 28.0 28.4 51.2 43.5 45.7 40.4 34.7 33.7 36.6 36.5 34.5 38.6 36.9
[120] 21.0 26.2 39.2 28.1 25.1 23.9 25.3 25.4 33.1 28.1 30.6 37.1 35.4
我想通过Metrics
包来评估rmse,但是,我收到了以下警告(rmse的输出为NA
:
一个二个一个一个
但是,当我使用来自同一个包的mae时,它给出了一个结果:
mae(merge_dataset$obs, merge_dataset$pred)
[1] 5.507646
我脚本中的其他包:
## == Necessary packages == ##
# We will need some packages for (spatial) data processing
library(tidyverse) # wrangling tabular data and plotting
library(sf) # processing spatial vector data - the easy way
library(sp) # processing spatial vector data - the way gstat needs it
library(raster) # processing spatial raster data. !!!overwrites dplyr::select!!!
library(rgdal) #import shapefiles
library(rgeos) #contains gCentroid
library(tidyr) #geometry to apart long/lat
library(dismo) #for kfold
library(lme4) #for mixed models (random effects)
library(stats) #quantile
library(Metrics)
library(caret)
library('parallel')
# Packages for geostatistics
library(gstat) # The most popular R-Package for Kriging
library(automap) # Automatize some (or all) parts of the gstat-workflow
# Finally, some packages to make pretty plots
library(patchwork)
library(viridis)
library(tmap)
library(graphics) #for text
2条答案
按热度按时间vwoqyblh1#
您收到警告消息的原因是您试图访问的数据框中的列不存在。警告消息告诉您merge_dataset数据框中没有名为pred的列。这可能是因为您键入了错误的列名,或者因为数据框中不存在该列。要解决此问题,请执行以下操作:您可以检查列名的拼写以确保其正确,也可以检查数据框中的列列表以确保该列存在。如果该列不存在,您可以通过创建一个具有正确名称的新列并为其赋值来将其添加到数据框中。
wfveoks02#
您似乎正在使用
Metrics
包中的rmse()
函数,但您为该函数提供的输入与该函数不兼容。rmse()
函数需要两个数值向量作为输入,但您提供的是具有两列(merge_dataset$obs和merge_dataset$pred)的数据框。要解决此问题,您需要从数据框中提取数值向量,并将其作为
rmse()
函数的输入。您可以使用$运算符提取所需的列,如下所示:这将为您提供merge_dataset$pred中的预测值与merge_dataset$obs中的观测值相比的RMSE(均方根误差)。