File size: 2,846 Bytes
a831d9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "728431f5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "fd56baf1",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2023-12-25 15:31:55.354 \n",
      "  \u001b[33m\u001b[1mWarning:\u001b[0m to view this Streamlit app on a browser, run it with the following\n",
      "  command:\n",
      "\n",
      "    streamlit run C:\\Users\\user\\anaconda3\\Lib\\site-packages\\ipykernel_launcher.py [ARGUMENTS]\n"
     ]
    }
   ],
   "source": [
    "import streamlit as st\n",
    "import pandas as pd\n",
    "import joblib\n",
    "\n",
    "# Load trained model\n",
    "model = joblib.load('mpg_model.pkl')  # Ensure this path is correct\n",
    "\n",
    "def user_input_features():\n",
    "    cylinders = st.sidebar.slider('Cylinders', 3, 8, 4)\n",
    "    displacement = st.sidebar.number_input('Displacement')\n",
    "    horsepower = st.sidebar.number_input('Horsepower')\n",
    "    weight = st.sidebar.number_input('Weight')\n",
    "    acceleration = st.sidebar.number_input('Acceleration')\n",
    "    model_year = st.sidebar.slider('Model Year', 70, 82, 76)\n",
    "    data = {'cylinders': cylinders,\n",
    "            'displacement': displacement,\n",
    "            'horsepower': horsepower,\n",
    "            'weight': weight,\n",
    "            'acceleration': acceleration,\n",
    "            'model_year': model_year}\n",
    "    features = pd.DataFrame(data, index=[0])\n",
    "    return features\n",
    "\n",
    "# Main Streamlit app interface\n",
    "st.write(\"\"\"\n",
    "# Simple MPG Prediction App\n",
    "This app predicts the **Miles Per Gallon (MPG)** of your car!\n",
    "\"\"\")\n",
    "\n",
    "# User input features\n",
    "input_df = user_input_features()\n",
    "\n",
    "# Display the user input features\n",
    "st.subheader('User Input features')\n",
    "st.write(input_df)\n",
    "\n",
    "# Predict and display the output\n",
    "st.subheader('Prediction')\n",
    "prediction = model.predict(input_df)\n",
    "st.write(f'Predicted MPG: {prediction[0]:.2f}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f8836f1f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}