• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Feb 21st, 2020 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. library(ggplot2)
2. library(caret)
3. library(e1071)
4.
6.
7. data1 <- subset(data, data\$Ownership == "Owner")
8. data2 <- subset(data, data\$Ownership == "Nonowner")
9.
10. #A
11. (dim(data1)[1] / dim(data)[1]) * 100
12. summary(data\$Ownership)
13.
14. #B
15. ggplot(data = data, aes(x = data\$Income, y = data\$Lot_Size)) +
16.   geom_point(aes(col = factor(data\$Ownership))) +
17.   theme_bw()
18.
19. logit.reg <- glm(Ownership ~ ., data = data[, 1:3], family = "binomial")
20. summary(logit.reg)
21.
22. pred <- predict(logit.reg, data2, type = "response")
23. valid.predict<-data.frame(actual = data2\$Ownership, predicted = pred)
24. pred_rate <- subset(valid.predict, valid.predict\$predicted < 0.5)
25.
26. #C
27. (dim(pred_rate)[1] / dim(data2)[1]) * 100
28. confusionMatrix(as.factor(ifelse(valid.predict\$predicted < 0.5, "Nonowner", "Owner")), data2\$Ownership) #sensitivity
29.
30.
31. #E, F
32. new <- data.frame(Income = 60.0, Lot_Size = 20.0)
33. pred <- predict(logit.reg, new, type = "response") #nonowner
34. odds <- pred / (1 - pred)
35.
36. #G
37. income_table <- data.frame(Income = seq(50,200,1), Probability = rep(0,151))
38.
39. for (i in seq(50,200,1)){
40.   new_row <- data.frame(Income = i, Lot_Size = 16)
41.   pred <- predict(logit.reg, new_row, type = "response")
42.   income_table[income_table\$Income == i, 2 ] <- pred
43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top