Closed unmanned15 closed 5 years ago
Hello @unmanned15
I think there must be a quote missing there.. at least when you start defining the model_name
parameter! Can you share your particular example so I can replicate it?
Glad you're using my library! 👍
Below is the data that I am using along with the code so you can reproduce what I am trying. I would like to use your package to measure and graphically show error with the best model. Thanks for your help!
data <- lapply(excel_sheets("DATA.xlsx"), read_excel, path = "DATA.xlsx")
sediment_data <- data[[1]]
ratios <- data[[2]]
d015cm <- cbind(sediment_data$d015cm, ratios)
names(d015cm)[1] <- "y"
d061cm <- cbind(sediment_data$d061cm, ratios)
names(d061cm)[1] <- "y"
d091cm <- cbind(sediment_data$d091cm, ratios)
names(d091cm)[1] <- "y"
d0182cm <- cbind(sediment_data$d0182cm, ratios)
names(d0182cm)[1] <- "y"
depth_list <- list(d015cm, d061cm, d091cm, d0182cm)
#creating labels for the lists
names(depth_list) <- c('d015cm','d061cm','d091cm','d0182cm')
#parameters to put in model
pp_method <- c("scale", "center")
# main metric used in model to evaluate
metric <- "Rsquared"
#do you want to maximize or minimize the metric
m <- TRUE
#cross validation method
cv_method <- "repeatedcv"
#if using k-fold or repeatedcv, number of folds to produce (ex. 5, 10)
fold <- 10
#number of repeats for cross validation (if applicable)
num_repeat <- 100
for (depth in depth_list){
#linear least squares regression
model <- train(y~., method = "lm", data = depth, preProcess = pp_method, metric = metric, maximize = m, trControl = trainControl(method = cv_method, number = fold, repeats = num_repeat))
results <- as.data.frame(model$trainingData[1])
results2 <- as.data.frame(model$finalModel$fitted.values)
lares::mplot_lineal(tag = results$.outcome, score = results2$`model$finalModel$fitted.values`, subtitle = "regression", model_name = "regression linear 6ft",regression = TRUE)
}
I managed to replicate your script. You should also share the following so I, or any other person whose had the same issue, can replicate.
library(lares)
library(readxl)
library(caret)
Also, you misses a }
at the end. I'd also recommend plotting the results outside the for
segment.
Ok, so: if you suppress the regression = TRUE
part, it will work for you. I'll check why it is that not working but, generally, you shouldn't need that for getting/understanding your results. Actually, I think I might chop that off as a (dumb) fix!
Btw, this is what you should get:
Done with my last commit: https://github.com/laresbernardo/lares/commit/bc931f1de2c6dcb10f65f8397660e16ccb36406b
@laresbernardo Hi,
I am trying to use the function
lares::mplot_lineal(tag = results$.outcome, score = results2$model$finalModel$fitted.values, subtitle = "regression", model_name = "regression linear ,regression = TRUE)
The data for the
tag
are the actual values and the data forscore
are the predicted values from the model. I keep getting an Error:Error: 'mapping' must be created by 'aes()'
Any idea on why it is causing this? I just downloaded your R package and am trying to learn how to use it.
Thanks!