decisionscience/trial1
0
1{2 "cells": [3 {4 "cell_type": "code",5 "execution_count": null,6 "id": "728431f5",7 "metadata": {},8 "outputs": [],9 "source": []10 },11 {12 "cell_type": "code",13 "execution_count": 1,14 "id": "fd56baf1",15 "metadata": {},16 "outputs": [17 {18 "name": "stderr",19 "output_type": "stream",20 "text": [21 "2023-12-25 15:31:55.354 \n",22 " \u001b[33m\u001b[1mWarning:\u001b[0m to view this Streamlit app on a browser, run it with the following\n",23 " command:\n",24 "\n",25 " streamlit run C:\\Users\\user\\anaconda3\\Lib\\site-packages\\ipykernel_launcher.py [ARGUMENTS]\n"26 ]27 }28 ],29 "source": [30 "import streamlit as st\n",31 "import pandas as pd\n",32 "import joblib\n",33 "\n",34 "# Load trained model\n",35 "model = joblib.load('mpg_model.pkl') # Ensure this path is correct\n",36 "\n",37 "def user_input_features():\n",38 " cylinders = st.sidebar.slider('Cylinders', 3, 8, 4)\n",39 " displacement = st.sidebar.number_input('Displacement')\n",40 " horsepower = st.sidebar.number_input('Horsepower')\n",41 " weight = st.sidebar.number_input('Weight')\n",42 " acceleration = st.sidebar.number_input('Acceleration')\n",43 " model_year = st.sidebar.slider('Model Year', 70, 82, 76)\n",44 " data = {'cylinders': cylinders,\n",45 " 'displacement': displacement,\n",46 " 'horsepower': horsepower,\n",47 " 'weight': weight,\n",48 " 'acceleration': acceleration,\n",49 " 'model_year': model_year}\n",50 " features = pd.DataFrame(data, index=[0])\n",51 " return features\n",52 "\n",53 "# Main Streamlit app interface\n",54 "st.write(\"\"\"\n",55 "# Simple MPG Prediction App\n",56 "This app predicts the **Miles Per Gallon (MPG)** of your car!\n",57 "\"\"\")\n",58 "\n",59 "# User input features\n",60 "input_df = user_input_features()\n",61 "\n",62 "# Display the user input features\n",63 "st.subheader('User Input features')\n",64 "st.write(input_df)\n",65 "\n",66 "# Predict and display the output\n",67 "st.subheader('Prediction')\n",68 "prediction = model.predict(input_df)\n",69 "st.write(f'Predicted MPG: {prediction[0]:.2f}')"70 ]71 },72 {73 "cell_type": "code",74 "execution_count": null,75 "id": "f8836f1f",76 "metadata": {},77 "outputs": [],78 "source": []79 }80 ],81 "metadata": {82 "kernelspec": {83 "display_name": "Python 3 (ipykernel)",84 "language": "python",85 "name": "python3"86 },87 "language_info": {88 "codemirror_mode": {89 "name": "ipython",90 "version": 391 },92 "file_extension": ".py",93 "mimetype": "text/x-python",94 "name": "python",95 "nbconvert_exporter": "python",96 "pygments_lexer": "ipython3",97 "version": "3.11.5"98 }99 },100 "nbformat": 4,101 "nbformat_minor": 5102}103 