forked from belgrades/AprendizajeSupervisado
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhogar.R
More file actions
363 lines (339 loc) · 12.4 KB
/
hogar.R
File metadata and controls
363 lines (339 loc) · 12.4 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#install.packages('curl')
#install.packages('xlsx')
library('curl')
library('xlsx')
source('google_api.R')
#Cargamos la data
dataSet = read.xlsx("hogares.xlsx", sheetIndex = 1, startRow = 1, endRow = 104, header = T, encoding = 'UTF-8')
dataSet$Dirección <- as.character(dataSet$Dirección)
dataSet$Distrito <- as.character(dataSet$Distrito)
dataSet$Dirección[11] <- "Galliate"
dataSet$Dirección[33] <- "Via San Roberto Bellarmino"
dataSet$Dirección[61] <- "Via di Monte Verde"
dataSet$Duracion <- 0
googleApiKey <- 'AIzaSyBekPZxKRhaB4kbaa90sx4ZoK4-OJImWAM'
destino <- 'Piazzale Aldo Moro' #Sapienza Universidad de Roma
for (i in 1:nrow(dataSet)){
dataSet$Dirección[i] <- gsub("\n", " ", dataSet$Dirección[i])
dataSet$Distrito[i] <- gsub("\n", " ", dataSet$Distrito[i])
origen <- paste(c(dataSet$Dirección[i]," ",dataSet$Distrito[i]), collapse="")
googleUrl <- get_url(origen, destino, googleApiKey)
googleData <- get_data(googleUrl)
googleJson = parse_data(googleData)
if(googleJson$status == "OK"){
dataSet$Duracion[i] <- googleJson$duration$value
}else{
origen <- dataSet$Dirección[i]
googleUrl <- get_url(origen, destino, googleApiKey)
googleData <- get_data(googleUrl)
googleJson = parse_data(googleData)
if(googleJson$status == "OK"){
#Making split to transform hours to mins
dataSet$Duracion[i] = googleJson$duration$value
}
}
}
dataSet$Tipo.de.Inmueble <- as.character(dataSet$Tipo.de.Inmueble)
dataSet$Tipo.de.Inmueble[grepl("Ap", dataSet$Tipo.de.Inmueble)] <- '0'
dataSet$Tipo.de.Inmueble[grepl("Mini", dataSet$Tipo.de.Inmueble)] <- '1'
dataSet$Tipo.de.Inmueble[grepl("Monolocale", dataSet$Tipo.de.Inmueble)] <- '1'
dataSet$Tipo.de.Inmueble <- as.numeric(dataSet$Tipo.de.Inmueble)
dataSet$Entrada <- 0
dataSet$Entrada[grepl("(ngresso)", dataSet$Descripción)] <- 1
dataSet$Cocina <- 0
dataSet$Cocina[grepl("(cucina)", dataSet$Descripción)] <- 1
dataSet$Bano <- 0
dataSet$Bano[grepl("(bagno)", dataSet$Descripción)] <- 1
dataSet$Bano[grepl("(2.?bagni)", dataSet$Descripción)] <- 2
dataSet$Bano[grepl("(4.?bagni)", dataSet$Descripción)] <- 3
dataSet$Bano[grepl("(3.?bagni)", dataSet$Descripción)] <- 4
dataSet$Calefaccion <- 0
dataSet$Calefaccion[grepl("(riscaldamento)", dataSet$Precio.Mensual)] <- 1
dataSet$condominio <- 0
dataSet$condominio[grepl("(condominio)", dataSet$Precio.Mensual)] <- 1
dataSet$NoServicios <- 0
dataSet$NoServicios[grepl("(escluse)", dataSet$Precio.Mensual)] <- 1
dataSet$Genero.admitido <- -1
dataSet$Genero.admitido[grepl("(ragazzi)", dataSet$Notas)] <- 0
dataSet$Genero.admitido[grepl("(ragazze)", dataSet$Notas)] <- 1
dataSet$Genero.admitido[grepl('(ragazze.i) | (ragazzi.e) | (ragazzi.ragazze) | (ragazze.ragazzi)', dataSet$Notas)] <- 2
dataSet$Genero.admitido[39] <- 2
dataSet$Precio <- -1
dataSet$Habitacion <- -1
dataSet$Habitaciones.Disponibles <- as.character(dataSet$Habitaciones.Disponibles)
dataSet$Precio.Mensual <- as.character(dataSet$Precio.Mensual)
for (i in 1:nrow(dataSet)){
aux <- strsplit(dataSet$Precio.Mensual[i], '[^[:digit:]]')
aux <- matrix(unlist(aux), ncol=1, byrow=TRUE)
aux <- aux[aux!='',]
if (length(aux) == 1){
dataSet$Precio[i] <- as.numeric(aux[1])
if (grepl("(ingol)", dataSet$Habitaciones.Disponibles[i])) dataSet$Habitacion[i] <- 0
if (grepl("(doppi)", dataSet$Habitaciones.Disponibles[i])) dataSet$Habitacion[i] <- 1
if (grepl("(posto)", dataSet$Habitaciones.Disponibles[i])) dataSet$Habitacion[i] <- 2
if (grepl("(ntero)", dataSet$Habitaciones.Disponibles[i])) dataSet$Habitacion[i] <- 3
}
}
#El resto a pata
aux <- dataSet[4,]
aux$Habitacion <- 1
aux$Precio <- as.numeric(450)
dataSet$Habitacion[4] <- 0
dataSet$Precio[4] <- as.numeric(300)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[5,]
aux$Habitacion <- 0
aux$Precio <- as.numeric(450)
dataSet$Habitacion[5] <- 0
dataSet$Precio[5] <- as.numeric(450)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[7,]
aux$Habitacion <- 1
aux$Precio <- as.numeric(450)
dataSet$Habitacion[7] <- 0
dataSet$Precio[7] <- as.numeric(250)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[10,]
aux$Habitacion <- 2
aux$Precio <- as.numeric(350)
dataSet$Habitacion[10] <- 0
dataSet$Precio[10] <- as.numeric(550)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[16,]
dataSet$Habitacion[16] <- 0
dataSet$Precio[16] <- as.numeric(460)
aux$Habitacion <- 0
aux$Precio <- as.numeric(460)
dataSet <- rbind(dataSet, aux)
aux$Precio <- as.numeric(430)
dataSet <- rbind(dataSet, aux)
aux$Precio <- as.numeric(430)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[18,]
aux$Habitacion <- 0
aux$Precio <- as.numeric(450)
dataSet$Habitacion[18] <- 0
dataSet$Precio[18] <- as.numeric(400)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[21,]
aux$Habitacion <- 0
aux$Precio <- as.numeric(475)
dataSet$Habitacion[21] <- 0
dataSet$Precio[21] <- as.numeric(525)
dataSet <- rbind(dataSet, aux)
aux$Precio <- as.numeric(575)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[22,]
aux$Habitacion <- 0
aux$Precio <- as.numeric(525)
dataSet$Habitacion[22] <- 0
dataSet$Precio[22] <- as.numeric(575)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[23,]
aux$Habitacion <- 0
aux$Precio <- as.numeric(475)
dataSet$Habitacion[23] <- 0
dataSet$Precio[23] <- as.numeric(525)
dataSet <- rbind(dataSet, aux)
aux$Precio <- as.numeric(575)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[24,]
aux$Habitacion <- 0
aux$Precio <- as.numeric(380)
dataSet$Habitacion[24] <- 0
dataSet$Precio[24] <- as.numeric(350)
dataSet <- rbind(dataSet, aux)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[26,]
aux$Habitacion <- 0
aux$Precio <- as.numeric(400)
dataSet$Habitacion[26] <- 0
dataSet$Precio[26] <- as.numeric(420)
dataSet <- rbind(dataSet, aux)
aux$Precio <- as.numeric(380)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[31,]
aux$Habitacion <- 2
aux$Precio <- as.numeric(250)
dataSet$Habitacion[31] <- 0
dataSet$Precio[31] <- as.numeric(450)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[41,]
aux$Habitacion <- 0
aux$Precio <- as.numeric(350)
dataSet$Habitacion[41] <- 0
dataSet$Precio[41] <- as.numeric(450)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[42,]
aux$Habitacion <- 0
aux$Precio <- as.numeric(450)
dataSet$Habitacion[42] <- 0
dataSet$Precio[42] <- as.numeric(500)
dataSet <- rbind(dataSet, aux)
dataSet <- rbind(dataSet, aux)
aux$Precio <- as.numeric(420)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[43,]
aux$Habitacion <- 0
aux$Precio <- as.numeric(450)
dataSet$Habitacion[43] <- 0
dataSet$Precio[43] <- as.numeric(500)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[44,]
aux$Habitacion <- 0
aux$Precio <- as.numeric(400)
dataSet$Habitacion[44] <- 0
dataSet$Precio[44] <- as.numeric(370)
dataSet <- rbind(dataSet, aux)
aux$Precio <- as.numeric(340)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[56,]
aux$Habitacion <- 0
aux$Precio <- as.numeric(550)
dataSet$Habitacion[56] <- 0
dataSet$Precio[56] <- as.numeric(500)
dataSet <- rbind(dataSet, aux)
aux$Precio <- as.numeric(450)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[61,]
aux$Habitacion <- 0
aux$Precio <- as.numeric(425)
dataSet$Habitacion[61] <- 0
dataSet$Precio[61] <- as.numeric(450)
dataSet <- rbind(dataSet, aux)
aux$Precio <- as.numeric(475)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[72,]
aux$Habitacion <- 2
aux$Precio <- as.numeric(350)
dataSet$Habitacion[72] <- 0
dataSet$Precio[72] <- as.numeric(430)
dataSet <- rbind(dataSet, aux)
###############################################+++
dataSet$Habitacion[74] <- 0
dataSet$Precio[74] <- as.numeric(450)
###############################################+++
aux <- dataSet[76,]
aux$Habitacion <- 3
aux$Precio <- as.numeric(850)
dataSet$Habitacion[76] <- 0
dataSet$Precio[76] <- as.numeric(425)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[77,]
aux$Habitacion <- 2
aux$Precio <- as.numeric(350)
dataSet$Habitacion[77] <- 0
dataSet$Precio[77] <- as.numeric(550)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[81,]
aux$Habitacion <- 2
aux$Precio <- as.numeric(325)
dataSet$Habitacion[81] <- 0
dataSet$Precio[81] <- as.numeric(550)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[84,]
aux$Habitacion <- 0
aux$Precio <- as.numeric(475)
dataSet$Habitacion[84] <- 2
dataSet$Precio[84] <- as.numeric(375)
dataSet <- rbind(dataSet, aux)
aux$Precio <- as.numeric(525)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[85,]
aux$Habitacion <- 2
aux$Precio <- as.numeric(300)
dataSet$Habitacion[85] <- 0
dataSet$Precio[85] <- as.numeric(450)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[87,]
aux$Habitacion <- 0
aux$Precio <- as.numeric(475)
dataSet$Habitacion[87] <- 0
dataSet$Precio[87] <- as.numeric(450)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[88,]
aux$Habitacion <- 2
aux$Precio <- as.numeric(300)
dataSet$Habitacion[88] <- 0
dataSet$Precio[88] <- as.numeric(450)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[93,]
aux$Habitacion <- 0
aux$Precio <- as.numeric(600)
dataSet$Habitacion[93] <- 0
dataSet$Precio[93] <- as.numeric(500)
dataSet <- rbind(dataSet, aux)
###############################################+++
aux <- dataSet[99,]
aux$Habitacion <- 0
aux$Precio <- as.numeric(600)
dataSet$Habitacion[99] <- 0
dataSet$Precio[99] <- as.numeric(550)
dataSet <- rbind(dataSet, aux)
###############################################
dataSet$Habitacion[45] <- 3
dataSet$Habitacion[90] <- 3
dataSet$Distrito <- NULL
dataSet$Dirección <- NULL
dataSet$Notas <- NULL
dataSet$Descripción <- NULL
dataSet$Foto <- NULL
dataSet$Piso <- NULL
dataSet$Habitaciones.Disponibles <- NULL
dataSet$Precio.Mensual <- NULL
dataSet$Piso <- NULL
regresion <- lm(Precio ~ . , data = dataSet)
myEntrada = as.numeric(readline("Quieres que tenga Entrada? 0 no, 1 si:"))
myTipoImnueble = as.numeric(readline("Quieres que sea tipo estudio? 0 no, 1 si:"))
myCocina = as.numeric(readline("Quieres que tenga Cocina? 0 no, 1 si:"))
myBano = as.numeric(readline("Cuantos baños quieres que tenga?:"))
myCalefaccion = as.numeric(readline("Quieres que tenga calefaccion? 0 no, 1 si:"))
myCondominio = as.numeric(readline("Quieres pagar condominio? 0 no, 1 si:"))
myNoServicios = as.numeric(readline("Quieres que NO incluya cargos por servicios? 0 no, 1 si:"))
myGenero = as.numeric(readline("Quieres que admitan a que genero? 0 para hombres, 1 mujeres y 2 para ambos:"))
myHabitacion = as.numeric(readline("Que tipo de habitacion quieres? 0 para simple, 1 doble, 2 cama en habitacion doble y 3 para apartamento completo:"))
myDireccion = as.character(readline("Direccion aproximada donde quieres el hogar?:"))
aux <- dataSet[1,]
aux$Tipo.de.Inmueble <- myTipoImnueble
aux$Entrada <- myEntrada
aux$Cocina <- myCocina
aux$Bano <- myBano
aux$Calefaccion <- myCalefaccion
aux$condominio <- myCondominio
aux$NoServicios <- myNoServicios
aux$Genero.admitido <- myGenero
aux$Habitacion <- myHabitacion
googleUrl <- get_url(myDireccion, destino, googleApiKey)
googleData <- get_data(googleUrl)
googleJson <- parse_data(googleData)
if(googleJson$status == "OK"){
myDuracion <- googleJson$duration$value
}
aux$Duracion <- myDuracion
prediccion <- predict(regresion, newdata = aux)
prediccion