Spaces:
Runtime error
Runtime error
File size: 1,089 Bytes
bcf7282 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import gradio as gr
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
# Load dataset (online use kar rahe hain taake HF pe chale)
url = "https://raw.githubusercontent.com/ageron/handson-ml/master/datasets/housing/housing.csv"
df = pd.read_csv(url)
# Select features
df = df[['total_rooms', 'households', 'population', 'total_bedrooms']].dropna()
# Split data
X = df[['total_rooms', 'households', 'population']]
y = df['total_bedrooms']
# Train model
model = LinearRegression()
model.fit(X, y)
# Prediction function
def predict(total_rooms, households, population):
data = np.array([[total_rooms, households, population]])
prediction = model.predict(data)[0]
return float(prediction)
# Gradio UI
interface = gr.Interface(
fn=predict,
inputs=[
gr.Number(label="Total Rooms"),
gr.Number(label="Households"),
gr.Number(label="Population")
],
outputs=gr.Number(label="Predicted Bedrooms"),
title="Housing Bedrooms Prediction",
description="Predict total bedrooms using linear regression"
) |