Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,19 +5,11 @@ import xgboost as xgb
|
|
5 |
from sklearn.metrics import mean_squared_error
|
6 |
from sklearn.model_selection import train_test_split
|
7 |
import optuna
|
8 |
-
|
9 |
-
# Load the data
|
10 |
path = "train.csv"
|
11 |
data = pd.read_csv(path)
|
12 |
-
|
13 |
-
# Get features
|
14 |
y = data['SalePrice']
|
15 |
X = data[["LotArea","OverallQual", "OverallCond", "YearBuilt","TotRmsAbvGrd","GarageArea"]]
|
16 |
-
|
17 |
-
# Split the data
|
18 |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
|
19 |
-
|
20 |
-
# Load the XGBoost model
|
21 |
model = xgb.XGBRegressor(objective ='reg:squarederror',
|
22 |
colsample_bytree = 1,
|
23 |
eta=0.3,
|
@@ -26,7 +18,6 @@ model = xgb.XGBRegressor(objective ='reg:squarederror',
|
|
26 |
alpha = 10,
|
27 |
n_estimators = 700)
|
28 |
model.fit(X_train, y_train)
|
29 |
-
# Create a sidebar with sliders for each feature
|
30 |
sidebar = st.sidebar
|
31 |
sidebar.title("Input Features")
|
32 |
lot_area = sidebar.slider("Lot Area", 1300, 215245, 1300)
|
@@ -35,7 +26,6 @@ overall_cond = sidebar.slider("Overall Condition", 1, 10, 6)
|
|
35 |
year_built = sidebar.slider("Year Built", 1872, 2010, 1980)
|
36 |
tot_rooms_above_grade = sidebar.slider("Total Rooms Above Grade", 2, 14, 5)
|
37 |
garage_area = sidebar.slider("Garage Area", 0, 1418, 462)
|
38 |
-
# Create a Pandas DataFrame with the user's input
|
39 |
input_df = pd.DataFrame({
|
40 |
"LotArea": [lot_area],
|
41 |
"OverallQual": [overall_qual],
|
@@ -44,7 +34,5 @@ input_df = pd.DataFrame({
|
|
44 |
"TotRmsAbvGrd": [tot_rooms_above_grade],
|
45 |
"GarageArea": [garage_area]
|
46 |
})
|
47 |
-
# Use the XGBoost model to predict the house price range for the user's input
|
48 |
prediction = model.predict(input_df)
|
49 |
-
|
50 |
-
st.write(f"The estimated house price range is ${prediction[0]:,.2f}")
|
|
|
5 |
from sklearn.metrics import mean_squared_error
|
6 |
from sklearn.model_selection import train_test_split
|
7 |
import optuna
|
|
|
|
|
8 |
path = "train.csv"
|
9 |
data = pd.read_csv(path)
|
|
|
|
|
10 |
y = data['SalePrice']
|
11 |
X = data[["LotArea","OverallQual", "OverallCond", "YearBuilt","TotRmsAbvGrd","GarageArea"]]
|
|
|
|
|
12 |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
|
|
|
|
|
13 |
model = xgb.XGBRegressor(objective ='reg:squarederror',
|
14 |
colsample_bytree = 1,
|
15 |
eta=0.3,
|
|
|
18 |
alpha = 10,
|
19 |
n_estimators = 700)
|
20 |
model.fit(X_train, y_train)
|
|
|
21 |
sidebar = st.sidebar
|
22 |
sidebar.title("Input Features")
|
23 |
lot_area = sidebar.slider("Lot Area", 1300, 215245, 1300)
|
|
|
26 |
year_built = sidebar.slider("Year Built", 1872, 2010, 1980)
|
27 |
tot_rooms_above_grade = sidebar.slider("Total Rooms Above Grade", 2, 14, 5)
|
28 |
garage_area = sidebar.slider("Garage Area", 0, 1418, 462)
|
|
|
29 |
input_df = pd.DataFrame({
|
30 |
"LotArea": [lot_area],
|
31 |
"OverallQual": [overall_qual],
|
|
|
34 |
"TotRmsAbvGrd": [tot_rooms_above_grade],
|
35 |
"GarageArea": [garage_area]
|
36 |
})
|
|
|
37 |
prediction = model.predict(input_df)
|
38 |
+
st.write(f"The estimated house price range is ${prediction[0]:,.2f}")
|
|