## Warning: package 'dplyr' was built under R version 4.1.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
## ï..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
##
## Parking n
## 1 Open 355
## 2 Not Provided 225
## 3 Covered 184
## 4 No Parking 141
## City_Category n
## 1 CAT B 351
## 2 CAT A 320
## 3 CAT C 234
Observación; 1. El precio de la casa esta con datos atipicos 2. Rainfall tiene valores negativos 3. carpet tiene 7 NA
## [1] 7
## ï..Observation Dist_Taxi Dist_Market Dist_Hospital Carpet
## 0 0 0 0 7
## Builtup Parking City_Category Rainfall House_Price
## 0 0 0 0 0
# Eliminar NA
df<- na.omit(df)
#Eliminar el registro del precio atípico
df<- df[df$House_Price<12000000,]
# eliminar el registro de lluvia atípico
df<- df[df$Rainfall>=0,]
#Gráficas
boxplot(df$House_Price, horizontal=TRUE)regresion <- lm(House_Price ~ Dist_Taxi + Dist_Market +Dist_Hospital +Carpet + City_Category + Rainfall +Builtup +Parking, data=df )
summary(regresion)##
## Call:
## lm(formula = House_Price ~ Dist_Taxi + Dist_Market + Dist_Hospital +
## Carpet + City_Category + Rainfall + Builtup + Parking, data = df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3572009 -800792 -65720 761534 4401585
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.599e+06 3.672e+05 15.246 < 2e-16 ***
## Dist_Taxi 3.009e+01 2.682e+01 1.122 0.2622
## Dist_Market 1.285e+01 2.081e+01 0.618 0.5370
## Dist_Hospital 4.864e+01 3.008e+01 1.617 0.1062
## Carpet -7.997e+02 3.476e+03 -0.230 0.8181
## City_CategoryCAT B -1.877e+06 9.598e+04 -19.554 < 2e-16 ***
## City_CategoryCAT C -2.890e+06 1.059e+05 -27.300 < 2e-16 ***
## Rainfall -1.175e+02 1.550e+02 -0.758 0.4484
## Builtup 1.339e+03 2.901e+03 0.462 0.6444
## ParkingNo Parking -6.040e+05 1.389e+05 -4.348 1.53e-05 ***
## ParkingNot Provided -4.924e+05 1.235e+05 -3.988 7.22e-05 ***
## ParkingOpen -2.632e+05 1.126e+05 -2.338 0.0196 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1222000 on 884 degrees of freedom
## Multiple R-squared: 0.5007, Adjusted R-squared: 0.4945
## F-statistic: 80.58 on 11 and 884 DF, p-value: < 2.2e-16
regresion <- lm(House_Price ~ Dist_Taxi + Dist_Market +Dist_Hospital +Carpet + City_Category + Rainfall +Builtup +Parking, data=df )
summary(regresion)##
## Call:
## lm(formula = House_Price ~ Dist_Taxi + Dist_Market + Dist_Hospital +
## Carpet + City_Category + Rainfall + Builtup + Parking, data = df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3572009 -800792 -65720 761534 4401585
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.599e+06 3.672e+05 15.246 < 2e-16 ***
## Dist_Taxi 3.009e+01 2.682e+01 1.122 0.2622
## Dist_Market 1.285e+01 2.081e+01 0.618 0.5370
## Dist_Hospital 4.864e+01 3.008e+01 1.617 0.1062
## Carpet -7.997e+02 3.476e+03 -0.230 0.8181
## City_CategoryCAT B -1.877e+06 9.598e+04 -19.554 < 2e-16 ***
## City_CategoryCAT C -2.890e+06 1.059e+05 -27.300 < 2e-16 ***
## Rainfall -1.175e+02 1.550e+02 -0.758 0.4484
## Builtup 1.339e+03 2.901e+03 0.462 0.6444
## ParkingNo Parking -6.040e+05 1.389e+05 -4.348 1.53e-05 ***
## ParkingNot Provided -4.924e+05 1.235e+05 -3.988 7.22e-05 ***
## ParkingOpen -2.632e+05 1.126e+05 -2.338 0.0196 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1222000 on 884 degrees of freedom
## Multiple R-squared: 0.5007, Adjusted R-squared: 0.4945
## F-statistic: 80.58 on 11 and 884 DF, p-value: < 2.2e-16
datos<- data.frame(Dist_Taxi=8278, Dist_Market=16251, Dist_Hospital=13857, Carpet=1455, Builtup=1764, Parking="Covered", City_Category="CAT A", Rainfall=390)
predict(regresion,datos)## 1
## 7883860
## [1] 7
## ï..Observation Dist_Taxi Dist_Market Dist_Hospital Carpet
## 0 0 0 0 7
## Builtup Parking City_Category Rainfall House_Price
## 0 0 0 0 0
# Eliminar NA
df<- na.omit(df)
#Eliminar el registro del precio atípico
df<- df[df$House_Price<12000000,]
# eliminar el registro de lluvia atípico
df<- df[df$Rainfall>=0,]# Instala y carga la biblioteca Shiny
if (!require(shiny)) {
install.packages("shiny")
library(shiny)
}## Loading required package: shiny
# Define la interfaz de la aplicación Shiny
ui <- fluidPage(
titlePanel("Predicción de Precio de Casa"),
sidebarLayout(
sidebarPanel(
numericInput("Dist_Taxi", "Distancia al Taxi:", value = 8278),
numericInput("Dist_Market", "Distancia al Mercado:", value = 16251),
numericInput("Dist_Hospital", "Distancia al Hospital:", value = 13857),
numericInput("Carpet", "Área de la Alfombra:", value = 1455),
selectInput("Parking", "Tipo de Estacionamiento:",
choices = unique(df$Parking)),
selectInput("City_Category", "Categoría de la Ciudad:",
choices = unique(df$City_Category)),
numericInput("Rainfall", "Lluvia:", value = 390),
numericInput("Builtup", "Área Construida:", value = 1764), # Agrega el input para Builtup
actionButton("submitBtn", "Obtener Precio"),
hr()
),
mainPanel(
verbatimTextOutput("predictionText")
)
)
)
# Define la función de servidor para la aplicación Shiny
server <- function(input, output) {
model <- NULL
observeEvent(input$submitBtn, {
datos <- data.frame(
Dist_Taxi = input$Dist_Taxi,
Dist_Market = input$Dist_Market,
Dist_Hospital = input$Dist_Hospital,
Carpet = input$Carpet,
Parking = input$Parking,
City_Category = input$City_Category,
Rainfall = input$Rainfall,
Builtup = input$Builtup # Utiliza el valor ingresado por el usuario para Builtup
)
# Generar el modelo de regresión lineal con los datos actuales
model <- lm(House_Price ~ Dist_Taxi + Dist_Market + Dist_Hospital +
Carpet + Parking + City_Category + Rainfall + Builtup, data = df)
prediction <- predict(model, datos)
output$predictionText <- renderText({
paste("Precio de la Casa Estimado:", round(prediction, 2))
})
})
}
# Crea la aplicación Shiny
shinyApp(ui, server)