mpgprediction / app.py
decisionscience's picture
Create app.py
207a615
raw history blame
No virus
1.21 kB
import streamlit as st
import numpy as np
# Load your trained model (or you can directly use the model if it's in the same script)
# Write a function to take user inputs
def user_input_features():
cylinders = st.sidebar.slider('Cylinders', 3, 8, 4)
displacement = st.sidebar.number_input('Displacement')
horsepower = st.sidebar.number_input('Horsepower')
weight = st.sidebar.number_input('Weight')
acceleration = st.sidebar.number_input('Acceleration')
model_year = st.sidebar.slider('Model Year', 70, 82, 76)
data = {'cylinders': cylinders,
'displacement': displacement,
'horsepower': horsepower,
'weight': weight,
'acceleration': acceleration,
'model_year': model_year}
features = pd.DataFrame(data, index=[0])
return features
# Main
st.write("""
# Simple MPG Prediction App
This app predicts the **Miles Per Gallon (MPG)** of your car!
""")
# User input features
input_df = user_input_features()
# Display the user input features
st.subheader('User Input features')
st.write(input_df)
# Predict and display the output
st.subheader('Prediction')
prediction = model.predict(input_df)
st.write(prediction)