-
Notifications
You must be signed in to change notification settings - Fork 0
/
conteo.R
115 lines (77 loc) · 2.2 KB
/
conteo.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
### Binaria
library(tidyverse)
library(BMA)
library(pROC)
train=read.csv('../data/raw/datacountstudents.csv')%>%
dplyr::select(-id)%>%
rename(y=yC)%>%
filter(!is.na(y))
y=train%>%
dplyr::select(y)%>%
as.matrix()
x=train%>%
dplyr::select(-y)%>%
as.matrix()
source('funciones.R')
t=Sys.time()
semillas=as.list(1:100)
las=lapply(semillas,lasso_c,x,y)
saveRDS(las, "las_lasso_con.rds")
spip=prob_inc(las)
betas=get_betas(las)
colnames(betas)=colnames(x)
ok=colnames(x)[spip>0.5]
data.frame(betas)%>%
dplyr::select(ok)%>%
mutate(seed=1:nrow(betas))%>%
gather(beta,coef,-seed)%>%
filter(coef!=0)%>%
ggplot(aes(x=coef,fill=beta))+geom_histogram()+facet_wrap(~beta,scales = 'free')
x_red=data.frame(x)%>% ##quitamos x1 por el cambio de signo??
dplyr::select(x14,x22,x24,x25,x26,x3,x32,x4)%>%
as.matrix()
evals=lapply(semillas,eval_c,x_red,y) ##esta con round y dio mejor
train=data.frame(x_red)%>%
mutate(y=y)
model=glm(y~.,family="poisson",data = train)
summary(model)
mets=get_met(evals)
data.frame(spec=mets$spec,global=mets$global)%>%
mutate(seed=1:length(mets$spec))%>%
gather(metrica,value,-seed)%>%
filter(value<10)%>%
ggplot(aes(x=metrica,y=value,fill=metrica))+
geom_boxplot()+
facet_wrap(~metrica,scales = 'free')
median(mets$global)
print(Sys.time()-t)
t=Sys.time()
las=lapply(semillas,bics_c,x,y)
saveRDS(las, "las_bic_con.rds")
spip=prob_inc(las)
betas=get_betas(las)
colnames(betas)=colnames(x)
ok=colnames(x)[spip>0.5]
data.frame(betas)%>%
dplyr::select(ok)%>%
mutate(seed=1:nrow(betas))%>%
gather(beta,coef,-seed)%>%
filter(coef!=0)%>%
ggplot(aes(x=coef,fill=beta))+geom_histogram()+facet_wrap(~beta,scales = 'free')
x_red=data.frame(x)%>% ##quitamos x1 por el cambio de signo??
dplyr::select(x22,x24,x25,x3)%>%
as.matrix()
evals=lapply(semillas,eval_c,x_red,y)
train=data.frame(x_red)%>%
mutate(y=y)
model=glm(y~.,family="poisson",data = train)
summary(model)
mets=get_met(evals)
data.frame(spec=mets$spec,global=mets$global)%>%
mutate(seed=1:length(mets$spec))%>%
gather(metrica,value,-seed)%>%
filter(value<10)%>%
ggplot(aes(x=metrica,y=value,fill=metrica))+
geom_boxplot()+
facet_wrap(~metrica,scales = 'free')
print(Sys.time()-t)