Hello, I need help with this. Let's say that I have n features that I want to use to predict which class an observation belongs to. Using training data I try to do the following:> training$result <- as.factor(training$result) > model <- glm(result ~., family=binomial("logit"), data = training)However, when I run the model on my test data I receive predictions that have continuous values. I.e. if I have the classes 0 and 1 in "results" I get predictions of 0.234235 and so on. How do I force the output to be just 0 or 1? What am I missing? Thanks! John
Hello, I need help with this. Let's say that I have n features that I want to use to predict which class an observation belongs to. Using training data I try to do the following:> training$result <- as.factor(training$result) > model <- glm(result ~., family=binomial("logit"), data = training)However, when I run the model on my test data I receive predictions that have continuous values. I.e. if I have the classes 0 and 1 in "results" I get predictions of 0.234235 and so on. How do I force the output to be just 0 or 1? What am I missing? Thanks! John -- View this message in context: http://old.nabble.com/GLM%3A-Classification-problem.-Help%21-tp26416707p26416707.html Sent from the R help mailing list archive at Nabble.com.
> What am I missing?A trip to the help page. predict.glm has details on the "type" argument specific to this situation: "the type of prediction required. The default is on the scale of the linear predictors; the alternative "response" is on the scale of the response variable. Thus for a default binomial model the default predictions are of log-odds (probabilities on logit scale) and type "response" gives the predicted probabilities. The "terms" option returns a matrix giving the fitted values of each term in the model formula on the linear predictor scale." You will have to do the conversion to the class estimate. -- Max
On Nov 18, 2009, at 5:12 PM, J_Laberga wrote:> > Hello, > I need help with this. Let's say that I have n features that I want > to use > to predict which class an observation belongs to. Using training > data I try > to do the following: > >> training$result <- as.factor(training$result) >> model <- glm(result ~., family=binomial("logit"), data = training) > > However, when I run the model on my test data I receive predictions > that > have continuous values. I.e. if I have the classes 0 and 1 in > "results" I > get predictions of 0.234235 and so on. > How do I force the output to be just 0 or 1? What am I missing?The fact that predict gives you probabilities? If you want a decision, then you need to specify a decision rule, i.e. a threshold.>David Winsemius, MD Heritage Laboratories West Hartford, CT