R tutorial 20 - Logistic Regression 逻辑回归 (3)
来源:互联网 发布:云计算 erp 编辑:程序博客网 时间:2024/04/28 01:11
/*Logistic Regression 逻辑回归薪金与房屋补贴的关系。假设月薪是12150、那预测他会不会同时申请房屋补贴。逻辑回归用来预测0与1、是与否的模型。*/salary <- c(5500, 5800, 6400, 6700, 7100, 7500, 8800, 9500, 11000, 11500, 12000, 12500, 13100, 13800, 13900, 15000)# salary <- rnorm(16, 10000, 8000)claimNum <- c(0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1)cat("\n")cat("===============Result===============","\n")result <- data.frame(claimNum, salary)result# Drawplot(salary, claimNum, main="Salary & claimNum", xlab="Salary", ylab="claimNum", col = "red")cat("\n")cat("===============Model===============","\n")model <- glm(formula= claimNum ~ salary, data=result, family=binomial)modelcat("\n")cat("===============Summary Model===============","\n")summary(model)# Drawcurve(predict(model, data.frame(salary = x), type="resp"), add=TRUE)points(salary, fitted(model), pch=20, col = "blue")cat("\n")cat("===============Predict===============","\n")newdata = data.frame(salary = 12150)predict(model, newdata, type="response")
===============Result=============== claimNum salary1 0 55002 0 58003 0 64004 0 67005 0 71006 1 75007 0 88008 1 95009 0 1100010 1 1150011 0 1200012 0 1250013 1 1310014 1 1380015 1 1390016 1 15000===============Model=============== Call: glm(formula = claimNum ~ salary, family = binomial, data = result)Coefficients:(Intercept) salary -5.0425584 0.0004657 Degrees of Freedom: 15 Total (i.e. Null); 14 ResidualNull Deviance: 21.93 Residual Deviance: 16.05 AIC: 20.05===============Summary Model=============== Call:glm(formula = claimNum ~ salary, family = binomial, data = result)Deviance Residuals: Min 1Q Median 3Q Max -1.5208 -0.6299 -0.4147 0.6946 1.8668 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -5.0425584 2.4936676 -2.022 0.0432 *salary 0.0004657 0.0002285 2.038 0.0415 *---Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1(Dispersion parameter for binomial family taken to be 1) Null deviance: 21.930 on 15 degrees of freedomResidual deviance: 16.046 on 14 degrees of freedomAIC: 20.046Number of Fisher Scoring iterations: 4===============Predict=============== 1 0.6492079
0 0
- R tutorial 20 - Logistic Regression 逻辑回归 (3)
- R tutorial 18 - Logistic Regression 逻辑回归 (1)
- R tutorial 19 - handle error in Logistic Regression 逻辑回归 (2)
- logistic regression 逻辑回归
- 逻辑回归(Logistic Regression)
- 逻辑回归(logistic regression)
- 逻辑回归logistic regression
- 逻辑回归(logistic regression)
- 逻辑回归(logistic regression)
- 逻辑回归(Logistic Regression)
- 逻辑回归(logistic regression)
- 逻辑回归Logistic Regression
- 逻辑回归(Logistic Regression)
- Logistic Regression-逻辑回归
- 逻辑回归 logistic regression
- 逻辑回归(Logistic Regression)
- logistic regression 逻辑回归
- 逻辑回归(Logistic Regression)
- 函数之概览
- R tutorial 19 - handle error in Logistic Regression 逻辑回归 (2)
- eclipse出现的问题
- J2EE之反射中的class类(一)
- 自定义浏览器事件,模拟浏览器事件流
- R tutorial 20 - Logistic Regression 逻辑回归 (3)
- C语言动态内存管理
- Ranking
- ecshop数据库表14(ecs_article_cat)文章分类信息表
- 【SQL 基础】SQL的处理流程
- Django RuntimeError: maximum recursion depth exceeded
- 日常小结-经典IPC问题实现
- 数据库——导入数据出现警告/错误解决
- 移动端常见列表项自适应