| | import gradio as gr |
| | import pickle |
| |
|
| | |
| | with open('best_tree.pkl', 'rb') as file: |
| | model = pickle.load(file) |
| |
|
| | |
| | def predict(latitude, longitude, housing_median_age, total_rooms, total_bedrooms, population, households, median_income): |
| | |
| | features = [[longitude, latitude, housing_median_age, total_rooms, total_bedrooms, population, households, median_income]] |
| | |
| | |
| | prediction = model.predict(features) |
| | |
| | |
| | return prediction[0] |
| |
|
| | |
| | inputs = [ |
| | gr.inputs.Number(label="Longitude"), |
| | gr.inputs.Number(label="Latitude"), |
| | gr.inputs.Number(label="Housing Median Age"), |
| | gr.inputs.Number(label="Total Rooms"), |
| | gr.inputs.Number(label="Total Bedrooms"), |
| | gr.inputs.Number(label="Population"), |
| | gr.inputs.Number(label="Households"), |
| | gr.inputs.Number(label="Median Income") |
| | ] |
| |
|
| | |
| | output = gr.outputs.Label(num_top_classes=1) |
| |
|
| | |
| | examples = [ |
| | [37.88, -122.23, 41, 880, 129, 322, 126, 8.3252], |
| | [37.84, -122.27, 48, 1922, 409, 1026, 335, 1.7969], |
| | [37.83, -122.26, 52, 1656, 420, 718, 382, 2.6768] |
| | ] |
| |
|
| | |
| | interface = gr.Interface(fn=predict, inputs=inputs, outputs=output, title="Decision Tree Predictor", examples=examples).launch() |