神经网络做“时间管理大师的预测模型”

研究背景:随着时代的发展,时间管理大师越来越多,离婚率也越来越高,如何准确识别时间管理大师有助于降低离婚率。

研究目的:利用神经网络来建立时间管理大师的预测模型

首先介绍一下今天使用的数据集 Affairs数据集,是R的AER包里面的数据集,其中包含的变量是Affairs(出轨次数),gender(性别), age(年龄), yearsmarried(结婚年数) children (是否有娃),religiousness (信仰),education(教育程度),rating(对自己婚姻的评价)​

##加载数据集

library(AER)

library(ggplot2)

data("Affairs")

head(Affairs)

##做一点数据预处理,把文本表示变量和结局变量变成二分类变量

Affairs$gender <- ifelse(Affairs$gender=="female",2,1)

Affairs$children <- ifelse(Affairs$children=="no",0,1)

Affairs$ynaffair[Affairs$affairs>3]<-1

Affairs$ynaffair[Affairs$affairs<=3]<-0

table(Affairs$ynaffair)

##
## 0 1
## 521 80

#出轨3次以上的为“时间管理大师”,否则为“非时间管理大师”

#一共有80个“时间管理大师”和521个“非时间管理大师”

#看一下数据一共有多少行,建立训练集和验证集

nrow(Affairs)

## [1] 601

# 建立训练集和验证集
set.seed(123)
train_sample <- sample(601,200)
Affairs_train <- Affairs[train_sample,]
Affairs_test <- Affairs[-train_sample,]

开始建模

library(neuralnet)
# simple ANN with only a single hidden neuron单个隐藏层
RNGversion("3.5.2")# use an older random number generator to match the book

set.seed(12345) # to guarantee repeatable results
Affairs_trainmodel <- neuralnet(formula =ynaffair~ gender + age +
yearsmarried+ children + religiousness +
education+ occupation + rating,
data = Affairs_train)

#绘图

plot(Affairs_trainmodel)

单个隐藏层还是挺好解读的

模型的验证和具体的参数解读我们留到下期,谢谢大家的支持~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值