Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
99 views
in Technique[技术] by (71.8m points)

RMSLE looping in R

I have a dataframe consisting of observed and modelled data that I am trying to do a RMSLE metric on. The data is stored in one text file, which I can read in and has the format similar to this:

Group Time Observed Predicted
A 2 190 312
A 3 174 345
A 6 150 290
A 12 85 217
B 4 300 725
B 9 113 426
B 13 120 393
B 23 97 263
question from:https://stackoverflow.com/questions/65877489/rmsle-looping-in-r

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are using the unsplitted full data.frame to assign your y_pred and y_true. You should assign y_pred and y_true inside the for loop using the splitted data.frame.

#Now get statistic for each Group using a for loop
res <- list()
for (n in names (spp.l)){
   dat <- spp.l[[n]]
   y_true = dat$Observed
   y_pred = dat$Predicted
   RMSLE = RMSLE(y_pred = y_pred, y_true = y_true)
   res[[n]] <- data.frame(
      Group=n,
      RMSLE,
      n.samples=nrow(dat)
   )
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...