Skip to main content
edited tags
Link
kjetil b halvorsen
  • 82.8k
  • 32
  • 201
  • 663
Post Reopened by Stephan Kolassa, mkt, StupidWolf, Thomas Lumley, kjetil b halvorsen
Post Closed as "Not suitable for this site" by whuber
made code executable
Source Link
Stephan Kolassa
  • 130.7k
  • 22
  • 264
  • 497

I have an internal model that I unfortunately cannot share, but I've reproduced the issue below. My model has a binary target of 0 and 1. After running the predict function with type = "response", the values are still greater than 1 or less than 0 for some observations:

require(tidyverse)
data("iris")
iris
iris.model <- iris %>%
  mutate(isSetosa = case_when(Species == "setosa" ~ 1,
                             TRUE ~ 0)) %>%
  select(-Species)

mymodel <- glm(isSetosa ~ ., data = iris.model)
pred <- as.data.frame(predict(testmodelmymodel, type = "response")) %>%
  rename("preds" = 1)  %>%
  mutate(newpred = exp(preds)/(1+exp(preds)))

head(pred)

      preds   newpred
1 0.9789278 0.7268954
2 0.8442979 0.6993696
3 0.9021272 0.7113864
4 0.8263080 0.6955737
5 0.9966096 0.7303915
6 1.0169842 0.7343847

Given the fitted values are the same whether I choose "link" or "response" for type, I manually calculated the probabilities for each observation, but they seem lower than I would expect for the iris dataset.

What am I doing wrong here?

I have an internal model that I unfortunately cannot share, but I've reproduced the issue below. My model has a binary target of 0 and 1. After running the predict function with type = "response", the values are still greater than 1 or less than 0 for some observations:

data("iris")
iris
iris.model <- iris %>%
  mutate(isSetosa = case_when(Species == "setosa" ~ 1,
                             TRUE ~ 0)) %>%
  select(-Species)

mymodel <- glm(isSetosa ~ ., data = iris.model)
pred <- as.data.frame(predict(testmodel, type = "response")) %>%
  rename("preds" = 1)  %>%
  mutate(newpred = exp(preds)/(1+exp(preds)))

head(pred)

      preds   newpred
1 0.9789278 0.7268954
2 0.8442979 0.6993696
3 0.9021272 0.7113864
4 0.8263080 0.6955737
5 0.9966096 0.7303915
6 1.0169842 0.7343847

Given the fitted values are the same whether I choose "link" or "response" for type, I manually calculated the probabilities for each observation, but they seem lower than I would expect for the iris dataset.

What am I doing wrong here?

I have an internal model that I unfortunately cannot share, but I've reproduced the issue below. My model has a binary target of 0 and 1. After running the predict function with type = "response", the values are still greater than 1 or less than 0 for some observations:

require(tidyverse)
data("iris")
iris
iris.model <- iris %>%
  mutate(isSetosa = case_when(Species == "setosa" ~ 1,
                             TRUE ~ 0)) %>%
  select(-Species)

mymodel <- glm(isSetosa ~ ., data = iris.model)
pred <- as.data.frame(predict(mymodel, type = "response")) %>%
  rename("preds" = 1)  %>%
  mutate(newpred = exp(preds)/(1+exp(preds)))

head(pred)

      preds   newpred
1 0.9789278 0.7268954
2 0.8442979 0.6993696
3 0.9021272 0.7113864
4 0.8263080 0.6955737
5 0.9966096 0.7303915
6 1.0169842 0.7343847

Given the fitted values are the same whether I choose "link" or "response" for type, I manually calculated the probabilities for each observation, but they seem lower than I would expect for the iris dataset.

What am I doing wrong here?

Source Link

Why are my fitted values returning greater than 1 in GLM?

I have an internal model that I unfortunately cannot share, but I've reproduced the issue below. My model has a binary target of 0 and 1. After running the predict function with type = "response", the values are still greater than 1 or less than 0 for some observations:

data("iris")
iris
iris.model <- iris %>%
  mutate(isSetosa = case_when(Species == "setosa" ~ 1,
                             TRUE ~ 0)) %>%
  select(-Species)

mymodel <- glm(isSetosa ~ ., data = iris.model)
pred <- as.data.frame(predict(testmodel, type = "response")) %>%
  rename("preds" = 1)  %>%
  mutate(newpred = exp(preds)/(1+exp(preds)))

head(pred)

      preds   newpred
1 0.9789278 0.7268954
2 0.8442979 0.6993696
3 0.9021272 0.7113864
4 0.8263080 0.6955737
5 0.9966096 0.7303915
6 1.0169842 0.7343847

Given the fitted values are the same whether I choose "link" or "response" for type, I manually calculated the probabilities for each observation, but they seem lower than I would expect for the iris dataset.

What am I doing wrong here?