Giter VIP home page Giter VIP logo

Comments (5)

jlooper avatar jlooper commented on June 7, 2024 1

hi @R-icntay could you lend your expertise here please?

from ml-for-beginners.

R-icntay avatar R-icntay commented on June 7, 2024

Hello @TomJang, @jlooper

Firstly, thank you for providing a reproducible example. You were almost there, so good job!
The only thing that was missing is evaluating for a second condition, i.e if lm.cv.r[i] > 0.70. I have modified your example and it works as expected and ensures that R does not accidentally overwrite a similar previous value.

data("USArrests")
head(USArrests)
df.norm <- USArrests

set.seed(100)
lm.cv.mse <- NULL
lm.cv.r <- NULL
k <- 100

for(i in 1:k){

index.cv <- sample(1:nrow(df.norm),round(0.8*nrow(df.norm)))
df.cv.train <- df.norm[index.cv, ]
df.cv.test <- df.norm[-index.cv, ]

lm.cv <- glm(Rape~., data = df.cv.train) 

lm.cv.predicted <- predict(lm.cv, df.cv.test)

lm.cv.mse[i] <- sum((df.cv.test$rape - lm.cv.predicted)^2)/nrow(df.cv.test)
lm.cv.r[i] <- as.numeric(round(cor(lm.cv.predicted, df.cv.test$Rape, method = "pearson"), digits = 3))


if (!is.na(lm.cv.r[i]) && lm.cv.r[i] > 0.70){
  saveRDS(lm.cv, file = paste("lm.cv", i, lm.cv.r[i], ".rds", sep = '_'))
}
}

We invite you to check to check out our R lessons that show you how to build Machine Learning models using the Tidymodels framework: https://github.com/microsoft/ML-For-Beginners.

Do enjoy the ride and feel free to reach out in case of any difficulty.
Happy leaRning!

from ml-for-beginners.

TomJang avatar TomJang commented on June 7, 2024

from ml-for-beginners.

jlooper avatar jlooper commented on June 7, 2024

all set? should I close this? thanks everyone!

from ml-for-beginners.

R-icntay avatar R-icntay commented on June 7, 2024

Yes yes Jen.

All good here!

from ml-for-beginners.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.