files uploaded
Browse files- app.py +32 -0
- best_knn_model.joblib +3 -0
- scaler.joblib +3 -0
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from joblib import load
|
| 3 |
+
|
| 4 |
+
# Load your saved model and scaler
|
| 5 |
+
scaler = load('scaler.joblib')
|
| 6 |
+
best_knn_model = load('best_knn_model.joblib')
|
| 7 |
+
|
| 8 |
+
# Define the prediction function
|
| 9 |
+
def predict_house_price(longitude, latitude, housing_median_age, total_rooms, total_bedrooms, population, households, median_income):
|
| 10 |
+
inputs = [[longitude, latitude, housing_median_age, total_rooms, total_bedrooms, population, households, median_income]]
|
| 11 |
+
scaled_inputs = scaler.transform(inputs)
|
| 12 |
+
prediction = best_knn_model.predict(scaled_inputs)[0]
|
| 13 |
+
return f"${prediction:,.2f}"
|
| 14 |
+
|
| 15 |
+
# Define the Gradio interface
|
| 16 |
+
interface = gr.Interface(
|
| 17 |
+
fn=predict_house_price,
|
| 18 |
+
inputs=[
|
| 19 |
+
gr.Number(label="Longitude"),
|
| 20 |
+
gr.Number(label="Latitude"),
|
| 21 |
+
gr.Number(label="Housing Median Age"),
|
| 22 |
+
gr.Number(label="Total Rooms"),
|
| 23 |
+
gr.Number(label="Total Bedrooms"),
|
| 24 |
+
gr.Number(label="Population"),
|
| 25 |
+
gr.Number(label="Households"),
|
| 26 |
+
gr.Number(label="Median Income")
|
| 27 |
+
],
|
| 28 |
+
outputs=gr.Textbox(label="Predicted House Price")
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# Launch the interface
|
| 32 |
+
interface.launch()
|
best_knn_model.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6fab9669634be48fe9ec884a81daf8e4f64ce547f85077acc9e9587bb65c4e71
|
| 3 |
+
size 2518870
|
scaler.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:da8bc4b70df7dbfec9819d40fb94cc3bc38513731918c03057b06d6bea572dc4
|
| 3 |
+
size 1431
|