File size: 1,606 Bytes
2d6366a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
import gradio as gr

# ... (Rest of your code remains the same)
# # Select features and target
# Load the dataset
df = pd.read_csv('california_housing_train.csv')

col=['population', 'households', 'median_income']


features = df[col]  # replace with actual feature names
target = df['median_house_value']
# Split the data
X_train, X_test, y_train, y_test = train_test_split(features, target, test_size=0.2, random_state=42)

# Standardize the data
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)

# Train the model
model = LinearRegression()
model.fit(X_train_scaled, y_train)

# Evaluate the model
predictions = model.predict(X_test_scaled)
mse = mean_squared_error(y_test, predictions)
print(f'Mean Squared Error: {mse}')

# Function to make predictions
def predict_house_price(feature1, feature2, feature3):
    input_data = scaler.transform([[feature1, feature2, feature3]])
    prediction = model.predict(input_data)
    return prediction[0]

# Create Gradio interface
iface = gr.Interface(
    fn=predict_house_price,
    inputs=[gr.Number(label="population"), gr.Number(label="households"), gr.Number(label="median_income")],  # Use gr.Number directly
    outputs="text",
    title="House Price Prediction",
    description="Enter the features to get the predicted house price."
)

# Launch the app
iface.launch()