Spaces:
Sleeping
Sleeping
Creación y entrenamiento del modelo XGBReggressor
Browse files- house_price.py +22 -0
house_price.py
CHANGED
@@ -3,6 +3,10 @@ from gradio import components
|
|
3 |
import pandas as pd
|
4 |
import numpy as np
|
5 |
from datasets import load_dataset
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Carga del CSV desde huggingface
|
8 |
|
@@ -18,6 +22,24 @@ Select = ['GrLivArea', 'TotalBsmtSF', 'MoSold', 'YearBuilt', 'YearRemodAdd', 'Lo
|
|
18 |
X = df.loc[:, Select ] # Variables predictoras
|
19 |
y = df['SalePrice'] # Variable objetivo
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
# Interfaz gráfica del demo
|
22 |
|
23 |
def greet(name):
|
|
|
3 |
import pandas as pd
|
4 |
import numpy as np
|
5 |
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
|
12 |
|
|
|
22 |
X = df.loc[:, Select ] # Variables predictoras
|
23 |
y = df['SalePrice'] # Variable objetivo
|
24 |
|
25 |
+
# División del dataframe para evitar el sobreajuste
|
26 |
+
|
27 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
|
28 |
+
|
29 |
+
#Creamos una instancia con XGBClassifier
|
30 |
+
model_XGB = XGBRegressor(n_estimators=30, max_depth=2, learning_rate=.2, random_state=42)
|
31 |
+
|
32 |
+
#Entrenamos el modelo con los datos de entrenamiento
|
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):
|