Skip to main content
deleted 8 characters in body
Source Link
gung - Reinstate Monica
  • 147.5k
  • 89
  • 406
  • 717

(For the record, I agree with @dsaxton. But just to give you something, here is a quick demonstration of using LDA to optimally bin a continuous variable based on a factor.)

library(MASS)

Iris  = iris[,c(1,5)]
model = lda(Species~Sepal.Length, Iris)
range(Iris$Sepal.Length)  # [1] 4.3 7.9
cbind(seq(4, 8, .1), 
      predict(model, data.frame(Sepal.Length=seq(4, 8, .1)))$$Sepal.Length)  # [1] 4.3 7.9
cbind(seq(4, 8, .1), 
  predict(model, data.frame(Sepal.Length=seq(4, 8, .1)))$class)
#       [,1] [,2]
#  [1,]  4.0    1
#  [2,]  4.1    1
#        ...
# [15,]  5.4    1
# [16,]  5.5    2
# [17,]  5.6    2
#        ...
# [23,]  6.2    2
# [24,]  6.3    3
# [25,]  6.4    3
#        ...
# [41,]  8.0    3

(For the record, I agree with @dsaxton. But just to give you something, here is a quick demonstration of using LDA to optimally bin a continuous variable based on a factor.)

library(MASS)

Iris  = iris[,c(1,5)]
model = lda(Species~Sepal.Length, Iris)
range(Iris$Sepal.Length)  # [1] 4.3 7.9
cbind(seq(4, 8, .1), 
      predict(model, data.frame(Sepal.Length=seq(4, 8, .1)))$class)
#       [,1] [,2]
#  [1,]  4.0    1
#  [2,]  4.1    1
#        ...
# [15,]  5.4    1
# [16,]  5.5    2
# [17,]  5.6    2
#        ...
# [23,]  6.2    2
# [24,]  6.3    3
# [25,]  6.4    3
#        ...
# [41,]  8.0    3

(For the record, I agree with @dsaxton. But just to give you something, here is a quick demonstration of using LDA to optimally bin a continuous variable based on a factor.)

library(MASS)

Iris  = iris[,c(1,5)]
model = lda(Species~Sepal.Length, Iris)
range(Iris$Sepal.Length)  # [1] 4.3 7.9
cbind(seq(4, 8, .1), 
  predict(model, data.frame(Sepal.Length=seq(4, 8, .1)))$class)
#       [,1] [,2]
#  [1,]  4.0    1
#  [2,]  4.1    1
#        ...
# [15,]  5.4    1
# [16,]  5.5    2
# [17,]  5.6    2
#        ...
# [23,]  6.2    2
# [24,]  6.3    3
# [25,]  6.4    3
#        ...
# [41,]  8.0    3
Source Link
gung - Reinstate Monica
  • 147.5k
  • 89
  • 406
  • 717

(For the record, I agree with @dsaxton. But just to give you something, here is a quick demonstration of using LDA to optimally bin a continuous variable based on a factor.)

library(MASS)

Iris  = iris[,c(1,5)]
model = lda(Species~Sepal.Length, Iris)
range(Iris$Sepal.Length)  # [1] 4.3 7.9
cbind(seq(4, 8, .1), 
      predict(model, data.frame(Sepal.Length=seq(4, 8, .1)))$class)
#       [,1] [,2]
#  [1,]  4.0    1
#  [2,]  4.1    1
#        ...
# [15,]  5.4    1
# [16,]  5.5    2
# [17,]  5.6    2
#        ...
# [23,]  6.2    2
# [24,]  6.3    3
# [25,]  6.4    3
#        ...
# [41,]  8.0    3