animonte commited on
Commit
4ba3f04
1 Parent(s): 492d537

Creación de la interfaz gráfica

Browse files
Files changed (1) hide show
  1. house_price.py +29 -11
house_price.py CHANGED
@@ -6,6 +6,8 @@ from datasets import load_dataset
6
  from sklearn.model_selection import train_test_split
7
  from sklearn.metrics import r2_score
8
  from xgboost import XGBRegressor
 
 
9
 
10
 
11
  # Carga del CSV desde huggingface
@@ -18,8 +20,8 @@ df = pd.DataFrame(dataset["train"])
18
 
19
  # Selección de variables para el modelo
20
 
21
- Select = ['GrLivArea', 'TotalBsmtSF', 'MoSold', 'YearBuilt', 'YearRemodAdd', 'LotFrontage', 'YrSold', 'Id', 'BsmtFinSF1','OverallQual']
22
- X = df.loc[:, Select ] # Variables predictoras
23
  y = df['SalePrice'] # Variable objetivo
24
 
25
  # División del dataframe para evitar el sobreajuste
@@ -33,17 +35,33 @@ model_XGB = XGBRegressor(n_estimators=30, max_depth=2, learning_rate=.2, random_
33
  model_XGB.fit(X_train,y_train)
34
 
35
  #Creamos el conjunto de entrenamiento
36
- prediction_XGB = model_XGB.predict(X_test)
 
 
37
 
38
- #Calculamos la puntuación con el conjunto de entrenamiento
39
- scoreR2_XGB = r2_score(y_test, prediction_XGB)
40
 
41
- print("Puntuación:", scoreR2_XGB)
 
42
 
43
- # Interfaz gráfica del demo
 
 
 
 
 
 
 
 
 
 
 
44
 
45
- def greet(name):
46
- return "Hello " + name + "!!"
 
 
 
 
47
 
48
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
49
- iface.launch()
 
6
  from sklearn.model_selection import train_test_split
7
  from sklearn.metrics import r2_score
8
  from xgboost import XGBRegressor
9
+ import datetime
10
+
11
 
12
 
13
  # Carga del CSV desde huggingface
 
20
 
21
  # Selección de variables para el modelo
22
 
23
+ columns = ['GrLivArea', 'TotalBsmtSF', 'MoSold', 'YearBuilt', 'YearRemodAdd', 'LotFrontage', 'YrSold', 'BsmtFinSF1','OverallQual']
24
+ X = df.loc[:, columns ] # Variables predictoras
25
  y = df['SalePrice'] # Variable objetivo
26
 
27
  # División del dataframe para evitar el sobreajuste
 
35
  model_XGB.fit(X_train,y_train)
36
 
37
  #Creamos el conjunto de entrenamiento
38
+ # prediction_XGB = model_XGB.predict(X_test)
39
+
40
+ # Interfaz gráfica del demo
41
 
42
+ def ui_predict(Superficie_casa, Superficie_sotano, Anio_construccion, Anio_remodelacion, Frente_terreno, Superficie_construida_terminada, calidad_construccion):
 
43
 
44
+ # Obtener la fecha y hora actual
45
+ fecha_actual = datetime.datetime.now()
46
 
47
+ # Obtener el mes y el año de la fecha actual
48
+ Mes_venta = fecha_actual.month
49
+ Anio_venta = fecha_actual.year
50
+
51
+ inputs = [[Superficie_casa, Superficie_sotano, Mes_venta, Anio_construccion, Anio_remodelacion, Frente_terreno, Anio_venta, Superficie_construida_terminada, calidad_construccion]]
52
+ inputs = pd.DataFrame(inputs, columns= columns)
53
+ # Predicción
54
+ predicciones = model_XGB.predict(inputs)
55
+
56
+ return predicciones[0]
57
+
58
+ output = components.Textbox(label='Precio obtenido con el XG BOOST Regressor')
59
 
60
+ demo = gr.Interface(
61
+ fn=ui_predict,
62
+ inputs=['number', "number","number","number", "number","number", gr.Slider(1, 10, step=1)],
63
+ outputs=output,
64
+ allow_flagging="never"
65
+ )
66
 
67
+ demo.launch()