# Cargar al environment
library(readr)
HousePriceData <- read_csv("~/Conexión de interfaces/Conexión de interfaces/HousePriceData.csv")
## Rows: 905 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Parking, City_Category
## dbl (8): Observation, Dist_Taxi, Dist_Market, Dist_Hospital, Carpet, Builtup...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# file.choose("~/Conexión de interfaces/Conexión de interfaces/rentadebicis.csv")
data <- HousePriceData
str(data)
## spc_tbl_ [905 × 10] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ Observation : num [1:905] 1 2 3 4 5 6 7 8 9 10 ...
## $ Dist_Taxi : num [1:905] 9796 8294 11001 8301 10510 ...
## $ Dist_Market : num [1:905] 5250 8186 14399 11188 12629 ...
## $ Dist_Hospital: num [1:905] 10703 12694 16991 12289 13921 ...
## $ Carpet : num [1:905] 1659 1461 1340 1451 1770 ...
## $ Builtup : num [1:905] 1961 1752 1609 1748 2111 ...
## $ Parking : chr [1:905] "Open" "Not Provided" "Not Provided" "Covered" ...
## $ City_Category: chr [1:905] "CAT B" "CAT B" "CAT A" "CAT B" ...
## $ Rainfall : num [1:905] 530 210 720 620 450 760 1030 1020 680 1130 ...
## $ House_Price : num [1:905] 6649000 3982000 5401000 5373000 4662000 ...
## - attr(*, "spec")=
## .. cols(
## .. Observation = col_double(),
## .. Dist_Taxi = col_double(),
## .. Dist_Market = col_double(),
## .. Dist_Hospital = col_double(),
## .. Carpet = col_double(),
## .. Builtup = col_double(),
## .. Parking = col_character(),
## .. City_Category = col_character(),
## .. Rainfall = col_double(),
## .. House_Price = col_double()
## .. )
## - attr(*, "problems")=<externalptr>
summary(data)
## Observation Dist_Taxi Dist_Market Dist_Hospital
## Min. : 1.0 Min. : 146 Min. : 1666 Min. : 3227
## 1st Qu.:237.0 1st Qu.: 6477 1st Qu.: 9367 1st Qu.:11302
## Median :469.0 Median : 8228 Median :11149 Median :13189
## Mean :468.4 Mean : 8235 Mean :11022 Mean :13091
## 3rd Qu.:700.0 3rd Qu.: 9939 3rd Qu.:12675 3rd Qu.:14855
## Max. :932.0 Max. :20662 Max. :20945 Max. :23294
##
## Carpet Builtup Parking City_Category
## Min. : 775 Min. : 932 Length:905 Length:905
## 1st Qu.: 1317 1st Qu.: 1579 Class :character Class :character
## Median : 1478 Median : 1774 Mode :character Mode :character
## Mean : 1511 Mean : 1794
## 3rd Qu.: 1654 3rd Qu.: 1985
## Max. :24300 Max. :12730
## NA's :7
## Rainfall House_Price
## Min. :-110.0 Min. : 1492000
## 1st Qu.: 600.0 1st Qu.: 4623000
## Median : 780.0 Median : 5860000
## Mean : 786.9 Mean : 6083992
## 3rd Qu.: 970.0 3rd Qu.: 7200000
## Max. :1560.0 Max. :150000000
##
regresión <- lm(House_Price ~ Carpet + Builtup + factor(Parking) + factor(City_Category), data = data)
summary(regresión)
##
## Call:
## lm(formula = House_Price ~ Carpet + Builtup + factor(Parking) +
## factor(City_Category), data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3430967 -802513 -46915 775070 4263090
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6477702.2 272077.2 23.808 < 2e-16 ***
## Carpet 9968.8 143.3 69.584 < 2e-16 ***
## Builtup -7611.6 243.3 -31.279 < 2e-16 ***
## factor(Parking)No Parking -536301.8 139943.6 -3.832 0.000136 ***
## factor(Parking)Not Provided -457380.4 125020.1 -3.658 0.000269 ***
## factor(Parking)Open -236576.3 114356.8 -2.069 0.038857 *
## factor(City_Category)CAT B -1918518.1 97007.4 -19.777 < 2e-16 ***
## factor(City_Category)CAT C -2908756.6 107359.6 -27.094 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1243000 on 890 degrees of freedom
## (7 observations deleted due to missingness)
## Multiple R-squared: 0.9412, Adjusted R-squared: 0.9407
## F-statistic: 2034 on 7 and 890 DF, p-value: < 2.2e-16
datos_nuevos <- within(data.frame(Carpet=1477, Builtup=1774, Parking="Open", City_Category="CAT A"), { Parking <- factor(Parking, levels=levels(factor(data$Parking))); City_Category <- factor(City_Category, levels=levels(factor(data$City_Category))) })
predict(regresión, newdata = datos_nuevos)
## 1
## 7461982
Es un modelo altamente significativo y con poder explicativo muy alto, con un R² ajustado de 0.9407.
El Parking influye, ya que varias categorías salen con precio menor contra la referencia.
La categoría de ciudad pesa muchísimo, ya que CAT B y CAT C reducen fuerte el precio.