[R] Gains package installation error
I am trying to install the Gains package in R Studio Version 3.1.2 like this: install.packages("gains")The following warnings appear: InternetOpenUrl failed: 'The server name or address could not be resolved'Warning in install.packages : unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.1Warning in install.packages : package ‘gains’ is not available (for R version 3.1.2) Does anyone know how can I fix this?Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Export chaid decision tree rules
Hello, Can the decisions tree rules be exported? Along with the probabilities associated with each node?For example, I've created a CHAID decision with a target variable RESPONSE (YES/NO). I have 17 inner nodes with 19 terminal nodes. How which terminal node has the highest probability of YES and which is the probability? An example of a terminal node output is below:clicks_flag in YES: NO (n = 1142, err = 5.3%) Thanks!Rodica [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Export chaid decision tree rules
Thanks! It answered my question. Rodica - Original Message - From: Achim Zeileis To: David Winsemius Cc: Rodica Coderie ; "r-help@r-project.org" Sent: Saturday, January 3, 2015 10:58 PM Subject: Re: [R] Export chaid decision tree rules On Sat, 3 Jan 2015, David Winsemius wrote: > On Jan 3, 2015, at 1:21 AM, Rodica Coderie via R-help wrote: > >> Hello, >> Can the decisions tree rules be exported? Along with the probabilities >> associated with each node?For example, I've created a CHAID decision with a >> target variable RESPONSE (YES/NO). I have 17 inner nodes with 19 terminal >> nodes. How which terminal node has the highest probability of YES and which >> is the probability? >> An example of a terminal node output is below:clicks_flag in YES: NO (n = >> 1142, err = 5.3%) >> Thanks!Rodica >> [[alternative HTML version deleted]] > > When posting on the weekends it is particularly important to follow the > guidelines in the Posting Guide. Many of us who regularly monitor the > list will ignore questions that do not have library calls to the > packages needed and code to produce a reproducible example. (And you > should learn to post in plain text rather than HTML.) Yes, a reproducible example would have been good. I assume you are talking about the "CHAID" package from R-Forge. We haven't got a nice and ready to use function in "partykit" (which "CHAID" is built upon) but we have an unexported .list.rules.party function which does a good part of what you want to do. ## package and data library("CHAID") ucb <- as.data.frame(UCBAdmissions) ucb <- ucb[rep(1:nrow(ucb), ucb$Freq), 1:3] ## fit tree ch <- chaid(Admit ~ Gender + Dept, data = ucb) plot(ch) print(ch) ## get rule path partykit:::.list.rules.party(ch) And with that information it is not too hard to set something up that is close to what you want, I think: format_rules <- function(object, ...) { ft <- fitted(object) ns <- tapply(ft[[2]], ft[[1]], length) pr <- tapply(ft[[2]], ft[[1]], function(y) min(prop.table(table(y lb <- tapply(ft[[2]], ft[[1]], function(y) names(sort(table(y), decreasing = TRUE))[1]) rl <- partykit:::.list.rules.party(object) paste0(rl, ": ", lb, " (n = ", ns, ", ", round(100 * pr, 2), "%)") } writeLines(format_rules(ch)) hth, Z > -- > > David Winsemius > Alameda, CA, USA > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] #library("CHAID") - Cross validation for chaid
Hello, Is there an option of cross validation for CHAID decision tree? An example of CHAID is below: library("CHAID") example("chaid", package = "CHAID") How can I use a 10 fold cross-validation for CHAID? I've read that caret package is to cross-validate on many times of models, but model CHAID is not in caret's built-in library. library(caret) model <- train(vote3 ~., data = USvoteS, method='CHAID', tuneLength=10,trControl=trainControl(method='cv', number=10, classProbs=TRUE, summaryFunction=twoClassSummary)) Thanks, Rodica __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] #library(CHAID) - export associated probabilities and rules for each row
Hello, How can I export the sample data frame below -USvoteS with the associated probabilities and rules for each row? library("CHAID") example("chaid", package = "CHAID") To be more specific, for each of 1000 rows of the USvoteS data frame I want to see in which node is that row in (what are the rules associated with it) and with which probability. This may refer to any kind of decision tree, not only CHAID. Thanks, Rodica __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] #library("CHAID") - Cross validation for chaid
Thanks Max! You are right! I used the train function below and no model was built. Do you know what can I use instead? library(caret) mod <- train(x = USvoteS[,-1], y = USvoteS$vote3, method = modelInfo, trControl = trainControl(method = "cv")) Thanks! Rodica From: Max Kuhn Cc: "r-help@r-project.org" Sent: Monday, January 5, 2015 6:56 PM Subject: Re: [R] #library("CHAID") - Cross validation for chaid You can create your own: http://topepo.github.io/caret/custom_models.html I put a prototype together. Source this file: https://github.com/topepo/caret/blob/master/models/files/chaid.R then try this: library("CHAID") ### fit tree to subsample set.seed(290875) USvoteS <- USvote[sample(1:nrow(USvote), 1000),] ## You probably don't want to use `train.formula` as ## it will convert the factors to dummy variables mod <- train(x = USvoteS[,-1], y = USvoteS$vote3, method = modelInfo, trControl = trainControl(method = "cv")) Max On Mon, Jan 5, 2015 at 7:11 AM, Rodica Coderie via R-help wrote: > Hello, > > Is there an option of cross validation for CHAID decision tree? An example of > CHAID is below: > library("CHAID") > example("chaid", package = "CHAID") > > How can I use a 10 fold cross-validation for CHAID? > I've read that caret package is to cross-validate on many times of models, > but model CHAID is not in caret's built-in library. > > library(caret) > model <- train(vote3 ~., data = USvoteS, method='CHAID', > tuneLength=10,trControl=trainControl(method='cv', number=10, classProbs=TRUE, > summaryFunction=twoClassSummary)) > > Thanks, > Rodica > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] #library("CHAID") - Cross validation for chaid
So, if I understood correctly, the mod$finalModel should be the resulted tree after cross-validation, right? It's the same as the original one. names(mod) mod$finalModel chaidUS Thanks! Rodica - Original Message - From: Rodica Coderie To: Max Kuhn Cc: "r-help@r-project.org" Sent: Wednesday, January 7, 2015 1:32 PM Subject: Re: [R] #library("CHAID") - Cross validation for chaid Thanks Max! You are right! I used the train function below and no model was built. Do you know what can I use instead? library(caret) mod <- train(x = USvoteS[,-1], y = USvoteS$vote3, method = modelInfo, trControl = trainControl(method = "cv")) Thanks! Rodica From: Max Kuhn Cc: "r-help@r-project.org" Sent: Monday, January 5, 2015 6:56 PM Subject: Re: [R] #library("CHAID") - Cross validation for chaid You can create your own: http://topepo.github.io/caret/custom_models.html I put a prototype together. Source this file: https://github.com/topepo/caret/blob/master/models/files/chaid.R then try this: library("CHAID") ### fit tree to subsample set.seed(290875) USvoteS <- USvote[sample(1:nrow(USvote), 1000),] ## You probably don't want to use `train.formula` as ## it will convert the factors to dummy variables mod <- train(x = USvoteS[,-1], y = USvoteS$vote3, method = modelInfo, trControl = trainControl(method = "cv")) Max On Mon, Jan 5, 2015 at 7:11 AM, Rodica Coderie via R-help wrote: > Hello, > > Is there an option of cross validation for CHAID decision tree? An example of > CHAID is below: > library("CHAID") > example("chaid", package = "CHAID") > > How can I use a 10 fold cross-validation for CHAID? > I've read that caret package is to cross-validate on many times of models, > but model CHAID is not in caret's built-in library. > > library(caret) > model <- train(vote3 ~., data = USvoteS, method='CHAID', > tuneLength=10,trControl=trainControl(method='cv', number=10, classProbs=TRUE, > summaryFunction=twoClassSummary)) > > Thanks, > Rodica > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] #library(party) - Compare predicted results for ctree
Hello, I've created a ctree model called fit using 15 input variables for a factor predicted variable Response (YES/NO). When I run the following : table(predict(fit2), training_data$response) I get the following result: NO YES NO 48694 480 YES 0 0 It appears that the NO responses are predicted with 100% accuracy and the YES response are predicted with 0% accuracy. Why is this happening? It's because of my data or it's something in ctree algorithm? Thanks! Rodica __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.