{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd \n", "from sklearn.model_selection import train_test_split\n", "from sklearn.linear_model import LinearRegression\n", "from sklearn.metrics import r2_score,mean_squared_error\n", "from sklearn.compose import ColumnTransformer\n", "from sklearn.preprocessing import StandardScaler,OneHotEncoder\n", "from sklearn.pipeline import Pipeline\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: xlrd in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (2.0.1)\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "pip install xlrd" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
PriceMileageMakeModelTrimTypeCylinderLiterDoorsCruiseSoundLeather
017314.1031298221BuickCenturySedan 4DSedan63.14111
117542.0360839135BuickCenturySedan 4DSedan63.14110
216218.84786213196BuickCenturySedan 4DSedan63.14110
316336.91314016342BuickCenturySedan 4DSedan63.14100
416339.17032419832BuickCenturySedan 4DSedan63.14101
.......................................
79916507.07026716229SaturnL SeriesL300 Sedan 4DSedan63.04100
80016175.95760419095SaturnL SeriesL300 Sedan 4DSedan63.04110
80115731.13289720484SaturnL SeriesL300 Sedan 4DSedan63.04110
80215118.89322825979SaturnL SeriesL300 Sedan 4DSedan63.04110
80313585.63680235662SaturnL SeriesL300 Sedan 4DSedan63.04100
\n", "

804 rows × 12 columns

\n", "
" ], "text/plain": [ " Price Mileage Make Model Trim Type Cylinder \\\n", "0 17314.103129 8221 Buick Century Sedan 4D Sedan 6 \n", "1 17542.036083 9135 Buick Century Sedan 4D Sedan 6 \n", "2 16218.847862 13196 Buick Century Sedan 4D Sedan 6 \n", "3 16336.913140 16342 Buick Century Sedan 4D Sedan 6 \n", "4 16339.170324 19832 Buick Century Sedan 4D Sedan 6 \n", ".. ... ... ... ... ... ... ... \n", "799 16507.070267 16229 Saturn L Series L300 Sedan 4D Sedan 6 \n", "800 16175.957604 19095 Saturn L Series L300 Sedan 4D Sedan 6 \n", "801 15731.132897 20484 Saturn L Series L300 Sedan 4D Sedan 6 \n", "802 15118.893228 25979 Saturn L Series L300 Sedan 4D Sedan 6 \n", "803 13585.636802 35662 Saturn L Series L300 Sedan 4D Sedan 6 \n", "\n", " Liter Doors Cruise Sound Leather \n", "0 3.1 4 1 1 1 \n", "1 3.1 4 1 1 0 \n", "2 3.1 4 1 1 0 \n", "3 3.1 4 1 0 0 \n", "4 3.1 4 1 0 1 \n", ".. ... ... ... ... ... \n", "799 3.0 4 1 0 0 \n", "800 3.0 4 1 1 0 \n", "801 3.0 4 1 1 0 \n", "802 3.0 4 1 1 0 \n", "803 3.0 4 1 0 0 \n", "\n", "[804 rows x 12 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df=pd.read_excel(\"cars.xls\")\n", "df" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "X=df.drop(\"Price\",axis=1)\n", "y=df[\"Price\"]" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=42)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
MileageMakeModelTrimTypeCylinderLiterDoorsCruiseSoundLeather
34420000ChevroletCorvetteConv 2DConvertible86.02101
3507054ChevroletCorvetteCoupe 2DCoupe86.02101
44315903ChevroletMalibuSedan 4DSedan63.54011
3316709ChevroletCobaltSedan 4DSedan42.24111
29013776ChevroletCobaltCoupe 2DCoupe42.22011
....................................
719795BuickPark AvenueSpecial Ed Ultra 4DSedan63.84110
10624415CadillacDevilleDHS Sedan 4DSedan84.64111
2704922ChevroletCavalierSedan 4DSedan42.24011
43518721ChevroletMalibuMAXX Hback 4DHatchback63.54011
10216041CadillacDevilleDHS Sedan 4DSedan84.64101
\n", "

643 rows × 11 columns

\n", "
" ], "text/plain": [ " Mileage Make Model Trim Type \\\n", "344 20000 Chevrolet Corvette Conv 2D Convertible \n", "350 7054 Chevrolet Corvette Coupe 2D Coupe \n", "443 15903 Chevrolet Malibu Sedan 4D Sedan \n", "331 6709 Chevrolet Cobalt Sedan 4D Sedan \n", "290 13776 Chevrolet Cobalt Coupe 2D Coupe \n", ".. ... ... ... ... ... \n", "71 9795 Buick Park Avenue Special Ed Ultra 4D Sedan \n", "106 24415 Cadillac Deville DHS Sedan 4D Sedan \n", "270 4922 Chevrolet Cavalier Sedan 4D Sedan \n", "435 18721 Chevrolet Malibu MAXX Hback 4D Hatchback \n", "102 16041 Cadillac Deville DHS Sedan 4D Sedan \n", "\n", " Cylinder Liter Doors Cruise Sound Leather \n", "344 8 6.0 2 1 0 1 \n", "350 8 6.0 2 1 0 1 \n", "443 6 3.5 4 0 1 1 \n", "331 4 2.2 4 1 1 1 \n", "290 4 2.2 2 0 1 1 \n", ".. ... ... ... ... ... ... \n", "71 6 3.8 4 1 1 0 \n", "106 8 4.6 4 1 1 1 \n", "270 4 2.2 4 0 1 1 \n", "435 6 3.5 4 0 1 1 \n", "102 8 4.6 4 1 0 1 \n", "\n", "[643 rows x 11 columns]" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "X_train" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
MileageMakeModelTrimTypeCylinderLiterDoorsCruiseSoundLeather
19214627ChevroletAVEOLT Sedan 4DSedan41.64010
71721960SAAB9_5Linear Wagon 4DWagon42.34101
16827906ChevroletAVEOLS Hatchback 4DHatchback41.64000
52211204PontiacG6Sedan 4DSedan63.54110
53620917PontiacGrand AmGT Coupe 2DCoupe63.42111
....................................
65831655SAAB9_3 HOAero Conv 2DConvertible42.02111
35622740ChevroletCorvetteCoupe 2DCoupe86.02101
52521702PontiacG6Sedan 4DSedan63.54100
74814376SaturnIonQuad Coupe 2DCoupe42.22000
51726477PontiacG6GT Sedan 4DSedan63.54101
\n", "

161 rows × 11 columns

\n", "
" ], "text/plain": [ " Mileage Make Model Trim Type Cylinder \\\n", "192 14627 Chevrolet AVEO LT Sedan 4D Sedan 4 \n", "717 21960 SAAB 9_5 Linear Wagon 4D Wagon 4 \n", "168 27906 Chevrolet AVEO LS Hatchback 4D Hatchback 4 \n", "522 11204 Pontiac G6 Sedan 4D Sedan 6 \n", "536 20917 Pontiac Grand Am GT Coupe 2D Coupe 6 \n", ".. ... ... ... ... ... ... \n", "658 31655 SAAB 9_3 HO Aero Conv 2D Convertible 4 \n", "356 22740 Chevrolet Corvette Coupe 2D Coupe 8 \n", "525 21702 Pontiac G6 Sedan 4D Sedan 6 \n", "748 14376 Saturn Ion Quad Coupe 2D Coupe 4 \n", "517 26477 Pontiac G6 GT Sedan 4D Sedan 6 \n", "\n", " Liter Doors Cruise Sound Leather \n", "192 1.6 4 0 1 0 \n", "717 2.3 4 1 0 1 \n", "168 1.6 4 0 0 0 \n", "522 3.5 4 1 1 0 \n", "536 3.4 2 1 1 1 \n", ".. ... ... ... ... ... \n", "658 2.0 2 1 1 1 \n", "356 6.0 2 1 0 1 \n", "525 3.5 4 1 0 0 \n", "748 2.2 2 0 0 0 \n", "517 3.5 4 1 0 1 \n", "\n", "[161 rows x 11 columns]" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "X_test" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Best params: {'colsample_bytree': 0.5, 'learning_rate': 0.09, 'max_depth': 6, 'n_estimators': 200}\n" ] } ], "source": [ "best_params = \"{'colsample_bytree': 0.5, 'learning_rate': 0.09, 'max_depth': 6, 'n_estimators': 200}\"\n", "print(\"Best params: \",best_params)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "RMSE 835.1013862206736\n", "R2 0.9912072687898575\n" ] } ], "source": [ "\n", "preprocess=ColumnTransformer(\n", " transformers=[\n", " ('num',StandardScaler(),['Mileage', 'Cylinder','Liter','Doors']),\n", " ('cat',OneHotEncoder(),['Make','Model','Trim','Type'])\n", " ]\n", ")\n", "my_model=LinearRegression()\n", "\n", "\n", "pipe=Pipeline(steps=[('preprocessor',preprocess),('model',my_model)])\n", "pipe.fit(X_train,y_train)\n", "\n", "y_pred=pipe.predict(X_test)\n", "print('RMSE',mean_squared_error(y_test,y_pred)**0.5)\n", "print('R2',r2_score(y_test,y_pred))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: streamlit in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (1.35.0)\n", "Requirement already satisfied: altair<6,>=4.0 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (5.3.0)\n", "Requirement already satisfied: blinker<2,>=1.0.0 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (1.7.0)\n", "Requirement already satisfied: cachetools<6,>=4.0 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (5.3.3)\n", "Requirement already satisfied: click<9,>=7.0 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (8.1.7)\n", "Requirement already satisfied: numpy<2,>=1.19.3 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (1.26.2)\n", "Requirement already satisfied: packaging<25,>=16.8 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (23.2)\n", "Requirement already satisfied: pandas<3,>=1.3.0 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (2.1.4)\n", "Requirement already satisfied: pillow<11,>=7.1.0 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (10.1.0)\n", "Requirement already satisfied: protobuf<5,>=3.20 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (4.25.3)\n", "Requirement already satisfied: pyarrow>=7.0 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (16.1.0)\n", "Requirement already satisfied: requests<3,>=2.27 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (2.31.0)\n", "Requirement already satisfied: rich<14,>=10.14.0 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (13.7.1)\n", "Requirement already satisfied: tenacity<9,>=8.1.0 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (8.2.3)\n", "Requirement already satisfied: toml<2,>=0.10.1 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (0.10.2)\n", "Requirement already satisfied: typing-extensions<5,>=4.3.0 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (4.9.0)\n", "Requirement already satisfied: gitpython!=3.1.19,<4,>=3.0.7 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (3.1.43)\n", "Requirement already satisfied: pydeck<1,>=0.8.0b4 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (0.9.1)\n", "Requirement already satisfied: tornado<7,>=6.0.3 in c:\\users\\acer\\appdata\\roaming\\python\\python312\\site-packages (from streamlit) (6.4)\n", "Requirement already satisfied: watchdog>=2.1.5 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from streamlit) (4.0.1)\n", "Requirement already satisfied: jinja2 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from altair<6,>=4.0->streamlit) (3.1.2)\n", "Requirement already satisfied: jsonschema>=3.0 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from altair<6,>=4.0->streamlit) (4.22.0)\n", "Requirement already satisfied: toolz in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from altair<6,>=4.0->streamlit) (0.12.1)\n", "Requirement already satisfied: colorama in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from click<9,>=7.0->streamlit) (0.4.6)\n", "Requirement already satisfied: gitdb<5,>=4.0.1 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gitpython!=3.1.19,<4,>=3.0.7->streamlit) (4.0.11)\n", "Requirement already satisfied: python-dateutil>=2.8.2 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from pandas<3,>=1.3.0->streamlit) (2.8.2)\n", "Requirement already satisfied: pytz>=2020.1 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from pandas<3,>=1.3.0->streamlit) (2023.3.post1)\n", "Requirement already satisfied: tzdata>=2022.1 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from pandas<3,>=1.3.0->streamlit) (2023.3)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from requests<3,>=2.27->streamlit) (3.3.2)\n", "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from requests<3,>=2.27->streamlit) (3.6)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from requests<3,>=2.27->streamlit) (2.1.0)\n", "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from requests<3,>=2.27->streamlit) (2023.11.17)\n", "Requirement already satisfied: markdown-it-py>=2.2.0 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from rich<14,>=10.14.0->streamlit) (3.0.0)\n", "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\\users\\acer\\appdata\\roaming\\python\\python312\\site-packages (from rich<14,>=10.14.0->streamlit) (2.17.2)\n", "Requirement already satisfied: smmap<6,>=3.0.1 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from gitdb<5,>=4.0.1->gitpython!=3.1.19,<4,>=3.0.7->streamlit) (5.0.1)\n", "Requirement already satisfied: MarkupSafe>=2.0 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from jinja2->altair<6,>=4.0->streamlit) (2.1.3)\n", "Requirement already satisfied: attrs>=22.2.0 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit) (23.1.0)\n", "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit) (2023.12.1)\n", "Requirement already satisfied: referencing>=0.28.4 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit) (0.35.1)\n", "Requirement already satisfied: rpds-py>=0.7.1 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit) (0.18.1)\n", "Requirement already satisfied: mdurl~=0.1 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from markdown-it-py>=2.2.0->rich<14,>=10.14.0->streamlit) (0.1.2)\n", "Requirement already satisfied: six>=1.5 in c:\\users\\acer\\appdata\\local\\programs\\python\\python312\\lib\\site-packages (from python-dateutil>=2.8.2->pandas<3,>=1.3.0->streamlit) (1.16.0)\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "pip install streamlit" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "#streamlit run C:\\Users\\Acer\\AppData\\Roaming\\Python\\Python312\\site-packages\\ipykernel_launcher.py " ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "import streamlit as st\n", "def price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather):\n", "\tinput_data=pd.DataFrame({\n", "\t\t'Make':[make],\n", "\t\t'Model':[model],\n", "\t\t'Trim':[trim],\n", "\t\t'Mileage':[mileage],\n", "\t\t'Type':[car_type],\n", "\t\t'Car_type':[car_type],\n", "\t\t'Cylinder':[cylinder],\n", "\t\t'Liter':[liter],\n", "\t\t'Doors':[doors],\n", "\t\t'Cruise':[cruise],\n", "\t\t'Sound':[sound],\n", "\t\t'Leather':[leather]\n", "\t\t})\n", "\tprediction=pipe.predict(input_data)[0]\n", "\treturn prediction\n", "st.title(\"Araba Fiyatı Tahmin :red_car: @drmurataltun\")\n", "st.write(\"Arabanın özelliklerini seçin\")\n", "make=st.selectbox(\"Marka\",df['Make'].unique())\n", "model=st.selectbox(\"Model\",df[df['Make']==make]['Model'].unique())\n", "trim=st.selectbox(\"Trim\",df[(df['Make']==make) & (df['Model']==model)]['Trim'].unique())\n", "mileage=st.number_input(\"Kilometre\",200,60000)\n", "car_type=st.selectbox(\"Tipi\",df[(df['Make']==make) & (df['Model']==model) & (df['Trim']==trim )]['Type'].unique())\n", "cylinder=st.selectbox(\"Silindir\",df['Cylinder'].unique())\n", "liter=st.number_input(\"Liter\",1,6)\n", "doors=st.selectbox(\"Kapı\",df['Doors'].unique())\n", "cruise=st.radio(\"Hız S.\",[True,False])\n", "sound=st.radio(\"Ses Sistemi\",[True,False])\n", "leather=st.radio(\"Deri döşeme\",[True,False])\n", "if st.button(\"Tahmin\"):\n", "\tpred=price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather)\n", "\n", "\tst.write(\"11062024:Predicted Price :red_car: $\",round(pred[0],2))\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.12.4" } }, "nbformat": 4, "nbformat_minor": 2 }