#分类表,logistic回归分析时
fitt.pi<-fitted(glm.safe1)#同predict(glm.safe1,data.frame(x2=x2),type="resp")
ypred<-1*(fitt.pi>0.5) #1*逻辑变量就变成了0和1变量
ypred
length(ypred)
n<-table(safe$is_run,ypred)
n
Percantage<-c(n[1,1]/sum(n[1,]),n[2,2]/sum(n[2,]))
Percantage
fitt.pi<-fitted(glm.safe1)#同predict(glm.safe1,data.frame(x2=x2),type="resp")
ypred<-1*(fitt.pi>0.5) #1*逻辑变量就变成了0和1变量
ypred
length(ypred)
n<-table(safe$is_run,ypred)
n
Percantage<-c(n[1,1]/sum(n[1,]),n[2,2]/sum(n[2,]))
Percantage
rbind(Category,Percantage)
#预测的好坏,做分类树时
predictScore<-data.frame(pred.tree.both)
rownames(predictScore) #看这个矩阵行的名字
colnames(predictScore)#看这个矩阵列的名字
predictScore$是否转化<-'ok' #在预测的矩阵后面多加一列‘是否转化’2,全部都是2
predictScore[predictScore$FALSE.>predictScore$TRUE.,][,"是否转化"]=FALSE #如果false的概率大于true的概率,那么判断为false
predictScore[predictScore$FALSE.<=predictScore$TRUE.,][,"是否转化"]=TRUE
n<-table(data_test$是否转化,predictScore$是否转化)
n #看分布情况
percantage<-c(n[1,1]/sum(n[1,]),n[2,2]/sum(n[2,]))
percantage