{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "execution_count": 6, "metadata": { "id": "RdGj5r4ilCXW" }, "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 OneHotEncoder, StandardScaler\n", "from sklearn.pipeline import Pipeline" ] }, { "cell_type": "markdown", "source": [ "import pandas as pd = Verileri tablolama ve ön işleme aşamalarında kullanıldı.from sklearn.model_selection import train_test_split: Ana veri setini eğitim ve test verilerine ayırmak için kullanıldı.\n", "from sklearn.linear_model import LinearRegression : Doğrusal regresyon\n", "from sklearn.metrics import r2_score,mean_squared_error : modelimizin performansını ölçmek için\n", "from sklearn.compose import ColumnTransformer :Sütun dönüşüm işlemleri\n", "from sklearn.preprocessing import OneHotEncoder, StandardScaler : kategori - sayısal dönüşüm ve ölçeklendirme\n", "from sklearn.pipeline import Pipeline : Veri işleme hattı" ], "metadata": { "id": "xOSP5tvYlhT8" } }, { "cell_type": "code", "source": [ "pip install xldr" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "collapsed": true, "id": "RB7HDScwl5fB", "outputId": "33075e92-e29d-4ad6-a849-474362666f11" }, "execution_count": 7, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "\u001b[31mERROR: Could not find a version that satisfies the requirement xldr (from versions: none)\u001b[0m\u001b[31m\n", "\u001b[0m\u001b[31mERROR: No matching distribution found for xldr\u001b[0m\u001b[31m\n", "\u001b[0m" ] } ] }, { "cell_type": "markdown", "source": [ "Proje excel dosyası olduğu için" ], "metadata": { "id": "kj4-OtBBmFuG" } }, { "cell_type": "code", "source": [ "df=pd.read_excel('cars.xls')\n", "df" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 423 }, "id": "95ASq-kSnjIB", "outputId": "3a194963-1a64-4919-c089-3611fd6402de" }, "execution_count": 9, "outputs": [ { "output_type": "execute_result", "data": { "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]" ], "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", " \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", "
\n", "
\n", "\n", "
\n", " \n", "\n", " \n", "\n", " \n", "
\n", "\n", "\n", "
\n", " \n", "\n", "\n", "\n", " \n", "
\n", "\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", "
\n" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "dataframe", "variable_name": "df", "summary": "{\n \"name\": \"df\",\n \"rows\": 804,\n \"fields\": [\n {\n \"column\": \"Price\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 9884.852800898008,\n \"min\": 8638.930895260657,\n \"max\": 70755.46671654288,\n \"num_unique_values\": 798,\n \"samples\": [\n 28432.824212532152,\n 24852.495280683135,\n 22661.048485078372\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Mileage\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 8196,\n \"min\": 266,\n \"max\": 50387,\n \"num_unique_values\": 791,\n \"samples\": [\n 21386,\n 29649,\n 29368\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Make\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 6,\n \"samples\": [\n \"Buick\",\n \"Cadillac\",\n \"Saturn\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Model\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 32,\n \"samples\": [\n \"9-2X AWD\",\n \"Impala\",\n \"Vibe\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Trim\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 47,\n \"samples\": [\n \"GXP Sedan 4D\",\n \"Aero Sedan 4D\",\n \"SS Coupe 2D\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Type\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 5,\n \"samples\": [\n \"Convertible\",\n \"Wagon\",\n \"Hatchback\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Cylinder\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1,\n \"min\": 4,\n \"max\": 8,\n \"num_unique_values\": 3,\n \"samples\": [\n 6,\n 8,\n 4\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Liter\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1.1055619585094583,\n \"min\": 1.6,\n \"max\": 6.0,\n \"num_unique_values\": 16,\n \"samples\": [\n 3.1,\n 3.6,\n 4.6\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Doors\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": 2,\n \"max\": 4,\n \"num_unique_values\": 2,\n \"samples\": [\n 2,\n 4\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Cruise\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": 0,\n \"max\": 1,\n \"num_unique_values\": 2,\n \"samples\": [\n 0,\n 1\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Sound\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": 0,\n \"max\": 1,\n \"num_unique_values\": 2,\n \"samples\": [\n 0,\n 1\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Leather\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": 0,\n \"max\": 1,\n \"num_unique_values\": 2,\n \"samples\": [\n 0,\n 1\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" } }, "metadata": {}, "execution_count": 9 } ] }, { "cell_type": "markdown", "source": [ "Proje yüklendi." ], "metadata": { "id": "RIYLZX0KoufQ" } }, { "cell_type": "code", "source": [ "df.info()" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "V3ONZtVtovzg", "outputId": "ba9d149d-dd08-4d15-a149-cf948fe3153a" }, "execution_count": 10, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "\n", "RangeIndex: 804 entries, 0 to 803\n", "Data columns (total 12 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 Price 804 non-null float64\n", " 1 Mileage 804 non-null int64 \n", " 2 Make 804 non-null object \n", " 3 Model 804 non-null object \n", " 4 Trim 804 non-null object \n", " 5 Type 804 non-null object \n", " 6 Cylinder 804 non-null int64 \n", " 7 Liter 804 non-null float64\n", " 8 Doors 804 non-null int64 \n", " 9 Cruise 804 non-null int64 \n", " 10 Sound 804 non-null int64 \n", " 11 Leather 804 non-null int64 \n", "dtypes: float64(2), int64(6), object(4)\n", "memory usage: 75.5+ KB\n" ] } ] }, { "cell_type": "markdown", "source": [ "Proje hakkında bilgi edinildi." ], "metadata": { "id": "KMMxJh4epowO" } }, { "cell_type": "code", "source": [ "df.head(5)\n" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 206 }, "id": "4KR2FxY6qKgk", "outputId": "1112a6b1-a1ea-49b7-e8b1-04c2f7e69350" }, "execution_count": 11, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " Price Mileage Make Model Trim Type Cylinder Liter \\\n", "0 17314.103129 8221 Buick Century Sedan 4D Sedan 6 3.1 \n", "1 17542.036083 9135 Buick Century Sedan 4D Sedan 6 3.1 \n", "2 16218.847862 13196 Buick Century Sedan 4D Sedan 6 3.1 \n", "3 16336.913140 16342 Buick Century Sedan 4D Sedan 6 3.1 \n", "4 16339.170324 19832 Buick Century Sedan 4D Sedan 6 3.1 \n", "\n", " Doors Cruise Sound Leather \n", "0 4 1 1 1 \n", "1 4 1 1 0 \n", "2 4 1 1 0 \n", "3 4 1 0 0 \n", "4 4 1 0 1 " ], "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", "
PriceMileageMakeModelTrimTypeCylinderLiterDoorsCruiseSoundLeather
017314.1031298221BuickCenturySedan 4DSedan63.14111
117542.0360839135BuickCenturySedan 4DSedan63.14110
216218.84786213196BuickCenturySedan 4DSedan63.14110
316336.91314016342BuickCenturySedan 4DSedan63.14100
416339.17032419832BuickCenturySedan 4DSedan63.14101
\n", "
\n", "
\n", "\n", "
\n", " \n", "\n", " \n", "\n", " \n", "
\n", "\n", "\n", "
\n", " \n", "\n", "\n", "\n", " \n", "
\n", "\n", "
\n", "
\n" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "dataframe", "variable_name": "df", "summary": "{\n \"name\": \"df\",\n \"rows\": 804,\n \"fields\": [\n {\n \"column\": \"Price\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 9884.852800898008,\n \"min\": 8638.930895260657,\n \"max\": 70755.46671654288,\n \"num_unique_values\": 798,\n \"samples\": [\n 28432.824212532152,\n 24852.495280683135,\n 22661.048485078372\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Mileage\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 8196,\n \"min\": 266,\n \"max\": 50387,\n \"num_unique_values\": 791,\n \"samples\": [\n 21386,\n 29649,\n 29368\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Make\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 6,\n \"samples\": [\n \"Buick\",\n \"Cadillac\",\n \"Saturn\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Model\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 32,\n \"samples\": [\n \"9-2X AWD\",\n \"Impala\",\n \"Vibe\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Trim\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 47,\n \"samples\": [\n \"GXP Sedan 4D\",\n \"Aero Sedan 4D\",\n \"SS Coupe 2D\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Type\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 5,\n \"samples\": [\n \"Convertible\",\n \"Wagon\",\n \"Hatchback\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Cylinder\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1,\n \"min\": 4,\n \"max\": 8,\n \"num_unique_values\": 3,\n \"samples\": [\n 6,\n 8,\n 4\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Liter\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1.1055619585094583,\n \"min\": 1.6,\n \"max\": 6.0,\n \"num_unique_values\": 16,\n \"samples\": [\n 3.1,\n 3.6,\n 4.6\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Doors\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": 2,\n \"max\": 4,\n \"num_unique_values\": 2,\n \"samples\": [\n 2,\n 4\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Cruise\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": 0,\n \"max\": 1,\n \"num_unique_values\": 2,\n \"samples\": [\n 0,\n 1\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Sound\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": 0,\n \"max\": 1,\n \"num_unique_values\": 2,\n \"samples\": [\n 0,\n 1\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Leather\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": 0,\n \"max\": 1,\n \"num_unique_values\": 2,\n \"samples\": [\n 0,\n 1\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" } }, "metadata": {}, "execution_count": 11 } ] }, { "cell_type": "markdown", "source": [ "Veri setinin ilk 5 satırını getirir ve verinin yapısı hakkında ön bilgi verir." ], "metadata": { "id": "0jgxLWZEqQi1" } }, { "cell_type": "code", "source": [ "df.shape" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "-SjR6JBUqVQC", "outputId": "c19b8e18-355d-4f69-a1af-3e939fa981a6" }, "execution_count": 12, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "(804, 12)" ] }, "metadata": {}, "execution_count": 12 } ] }, { "cell_type": "markdown", "source": [ "Veri setinin kaç satır ve sütundan oluştuğunu gösterir.\n", "\n" ], "metadata": { "id": "TcvqOd2kqa7a" } }, { "cell_type": "code", "source": [ "X=df.drop('Price',axis=1)\n", "y=df['Price']" ], "metadata": { "id": "vTLh077kqfni" }, "execution_count": 13, "outputs": [] }, { "cell_type": "markdown", "source": [ "Fiyat sütunuyla veri ön işleme başladı." ], "metadata": { "id": "rsqvPvJ5q1rI" } }, { "cell_type": "code", "source": [ "X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=42)" ], "metadata": { "id": "RJGA1qKTsJST" }, "execution_count": 14, "outputs": [] }, { "cell_type": "code", "source": [ "preprocess=ColumnTransformer(\n", " transformers=[\n", " ('num',StandardScaler(),['Mileage', 'Cylinder','Liter','Doors']),\n", " ('cat',OneHotEncoder(),['Make','Model','Trim','Type'])\n", " ]\n", ")" ], "metadata": { "id": "wSwPfUZhshha" }, "execution_count": 15, "outputs": [] }, { "cell_type": "code", "source": [ "cars_model= LinearRegression()" ], "metadata": { "id": "YdOchgVqtvLc" }, "execution_count": 16, "outputs": [] }, { "cell_type": "code", "source": [ "pipe=Pipeline(steps=[('preprocessor',preprocess),('model',cars_model)])" ], "metadata": { "id": "-tpAChVrv8th" }, "execution_count": 18, "outputs": [] }, { "cell_type": "markdown", "source": [ "Pipeline tanımlandı" ], "metadata": { "id": "15e56QlVwC-q" } }, { "cell_type": "code", "source": [ "pipe.fit(X_train,y_train)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 191 }, "id": "f0TO4rAEwOZG", "outputId": "29cb6d66-f9ce-4b0a-d76a-443bc2523929" }, "execution_count": 19, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "Pipeline(steps=[('preprocessor',\n", " ColumnTransformer(transformers=[('num', StandardScaler(),\n", " ['Mileage', 'Cylinder',\n", " 'Liter', 'Doors']),\n", " ('cat', OneHotEncoder(),\n", " ['Make', 'Model', 'Trim',\n", " 'Type'])])),\n", " ('model', LinearRegression())])" ], "text/html": [ "
Pipeline(steps=[('preprocessor',\n",
              "                 ColumnTransformer(transformers=[('num', StandardScaler(),\n",
              "                                                  ['Mileage', 'Cylinder',\n",
              "                                                   'Liter', 'Doors']),\n",
              "                                                 ('cat', OneHotEncoder(),\n",
              "                                                  ['Make', 'Model', 'Trim',\n",
              "                                                   'Type'])])),\n",
              "                ('model', LinearRegression())])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ] }, "metadata": {}, "execution_count": 19 } ] }, { "cell_type": "code", "source": [ "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))" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "41ntEyZOwpMG", "outputId": "719ead68-c3a8-458e-d09d-0f36d3138d95" }, "execution_count": 20, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "RMSE 835.1007875600316\n", "R2 0.9912072813963753\n" ] } ] }, { "cell_type": "markdown", "source": [ "Skorlar kaydedildi." ], "metadata": { "id": "Vc9d9Ch4xEXe" } }, { "cell_type": "code", "source": [ "pipe.fit(X,y)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 191 }, "id": "-i3lnaj_xMNW", "outputId": "b82306d3-50b0-4cad-b7a9-5128891be4c2" }, "execution_count": 21, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "Pipeline(steps=[('preprocessor',\n", " ColumnTransformer(transformers=[('num', StandardScaler(),\n", " ['Mileage', 'Cylinder',\n", " 'Liter', 'Doors']),\n", " ('cat', OneHotEncoder(),\n", " ['Make', 'Model', 'Trim',\n", " 'Type'])])),\n", " ('model', LinearRegression())])" ], "text/html": [ "
Pipeline(steps=[('preprocessor',\n",
              "                 ColumnTransformer(transformers=[('num', StandardScaler(),\n",
              "                                                  ['Mileage', 'Cylinder',\n",
              "                                                   'Liter', 'Doors']),\n",
              "                                                 ('cat', OneHotEncoder(),\n",
              "                                                  ['Make', 'Model', 'Trim',\n",
              "                                                   'Type'])])),\n",
              "                ('model', LinearRegression())])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ] }, "metadata": {}, "execution_count": 21 } ] }, { "cell_type": "markdown", "source": [ "Veri setiyle tekrar eğitim yapıldı." ], "metadata": { "id": "bEKsz1pExU7o" } }, { "cell_type": "code", "source": [ "!pip install streamlit" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "hP5OsYaZxa5I", "outputId": "d32a7d22-551d-40b2-fdab-93c2f666dd44" }, "execution_count": 22, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Collecting streamlit\n", " Downloading streamlit-1.35.0-py2.py3-none-any.whl (8.6 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m8.6/8.6 MB\u001b[0m \u001b[31m46.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hRequirement already satisfied: altair<6,>=4.0 in /usr/local/lib/python3.10/dist-packages (from streamlit) (4.2.2)\n", "Requirement already satisfied: blinker<2,>=1.0.0 in /usr/lib/python3/dist-packages (from streamlit) (1.4)\n", "Requirement already satisfied: cachetools<6,>=4.0 in /usr/local/lib/python3.10/dist-packages (from streamlit) (5.3.3)\n", "Requirement already satisfied: click<9,>=7.0 in /usr/local/lib/python3.10/dist-packages (from streamlit) (8.1.7)\n", "Requirement already satisfied: numpy<2,>=1.19.3 in /usr/local/lib/python3.10/dist-packages (from streamlit) (1.25.2)\n", "Requirement already satisfied: packaging<25,>=16.8 in /usr/local/lib/python3.10/dist-packages (from streamlit) (24.1)\n", "Requirement already satisfied: pandas<3,>=1.3.0 in /usr/local/lib/python3.10/dist-packages (from streamlit) (2.0.3)\n", "Requirement already satisfied: pillow<11,>=7.1.0 in /usr/local/lib/python3.10/dist-packages (from streamlit) (9.4.0)\n", "Requirement already satisfied: protobuf<5,>=3.20 in /usr/local/lib/python3.10/dist-packages (from streamlit) (3.20.3)\n", "Requirement already satisfied: pyarrow>=7.0 in /usr/local/lib/python3.10/dist-packages (from streamlit) (14.0.2)\n", "Requirement already satisfied: requests<3,>=2.27 in /usr/local/lib/python3.10/dist-packages (from streamlit) (2.31.0)\n", "Requirement already satisfied: rich<14,>=10.14.0 in /usr/local/lib/python3.10/dist-packages (from streamlit) (13.7.1)\n", "Requirement already satisfied: tenacity<9,>=8.1.0 in /usr/local/lib/python3.10/dist-packages (from streamlit) (8.3.0)\n", "Requirement already satisfied: toml<2,>=0.10.1 in /usr/local/lib/python3.10/dist-packages (from streamlit) (0.10.2)\n", "Requirement already satisfied: typing-extensions<5,>=4.3.0 in /usr/local/lib/python3.10/dist-packages (from streamlit) (4.12.2)\n", "Collecting gitpython!=3.1.19,<4,>=3.0.7 (from streamlit)\n", " Downloading GitPython-3.1.43-py3-none-any.whl (207 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m207.3/207.3 kB\u001b[0m \u001b[31m26.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hCollecting pydeck<1,>=0.8.0b4 (from streamlit)\n", " Downloading pydeck-0.9.1-py2.py3-none-any.whl (6.9 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m6.9/6.9 MB\u001b[0m \u001b[31m88.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hRequirement already satisfied: tornado<7,>=6.0.3 in /usr/local/lib/python3.10/dist-packages (from streamlit) (6.3.3)\n", "Collecting watchdog>=2.1.5 (from streamlit)\n", " Downloading watchdog-4.0.1-py3-none-manylinux2014_x86_64.whl (83 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m83.0/83.0 kB\u001b[0m \u001b[31m11.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hRequirement already satisfied: entrypoints in /usr/local/lib/python3.10/dist-packages (from altair<6,>=4.0->streamlit) (0.4)\n", "Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from altair<6,>=4.0->streamlit) (3.1.4)\n", "Requirement already satisfied: jsonschema>=3.0 in /usr/local/lib/python3.10/dist-packages (from altair<6,>=4.0->streamlit) (4.19.2)\n", "Requirement already satisfied: toolz in /usr/local/lib/python3.10/dist-packages (from altair<6,>=4.0->streamlit) (0.12.1)\n", "Collecting gitdb<5,>=4.0.1 (from gitpython!=3.1.19,<4,>=3.0.7->streamlit)\n", " Downloading gitdb-4.0.11-py3-none-any.whl (62 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.7/62.7 kB\u001b[0m \u001b[31m8.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hRequirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas<3,>=1.3.0->streamlit) (2.8.2)\n", "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3,>=1.3.0->streamlit) (2023.4)\n", "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3,>=1.3.0->streamlit) (2024.1)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.27->streamlit) (3.3.2)\n", "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.27->streamlit) (3.7)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.27->streamlit) (2.0.7)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.27->streamlit) (2024.6.2)\n", "Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.10/dist-packages (from rich<14,>=10.14.0->streamlit) (3.0.0)\n", "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/dist-packages (from rich<14,>=10.14.0->streamlit) (2.16.1)\n", "Collecting smmap<6,>=3.0.1 (from gitdb<5,>=4.0.1->gitpython!=3.1.19,<4,>=3.0.7->streamlit)\n", " Downloading smmap-5.0.1-py3-none-any.whl (24 kB)\n", "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->altair<6,>=4.0->streamlit) (2.1.5)\n", "Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit) (23.2.0)\n", "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit) (2023.12.1)\n", "Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit) (0.35.1)\n", "Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit) (0.18.1)\n", "Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.10/dist-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 /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas<3,>=1.3.0->streamlit) (1.16.0)\n", "Installing collected packages: watchdog, smmap, pydeck, gitdb, gitpython, streamlit\n", "Successfully installed gitdb-4.0.11 gitpython-3.1.43 pydeck-0.9.1 smmap-5.0.1 streamlit-1.35.0 watchdog-4.0.1\n" ] } ] }, { "cell_type": "code", "source": [ "import streamlit as st\n", "\n", "def price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather):\n", " input_data=pd.DataFrame({'Make':[make],\n", " 'Model':[model],\n", " 'Trim':[trim],\n", " 'Mileage':[mileage],\n", " 'Type':[car_type],\n", " 'Cylinder':[cylinder],\n", " 'Liter':[liter],\n", " 'Doors':[doors],\n", " 'Cruise':[cruise],\n", " 'Sound':[sound],\n", " 'Leather':[leather]})\n", " prediction=pipe.predict(input_data)[0]\n", " return prediction\n", "st.title(\"II. El Araba Fiyatı Tahmin:red_car: @drmurataltun\")\n", "st.write('Arabanın özelliklerini seçiniz')\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',100,200000)\n", "car_type=st.selectbox('Araç Tipi',df[(df['Make']==make) &(df['Model']==model)&(df['Trim']==trim)]['Type'].unique())\n", "cylinder=st.selectbox('Cylinder',df['Cylinder'].unique())\n", "liter=st.number_input('Yakıt hacmi',1,10)\n", "doors=st.selectbox('Kapı sayısı',df['Doors'].unique())\n", "cruise=st.radio('Hız Sbt.',[True,False])\n", "sound=st.radio('Ses Sis.',[True,False])\n", "leather=st.radio('Deri döşeme.',[True,False])\n", "if st.button('Tahmin'):\n", " pred=price(make,model,trim,mileage,car_type,cylinder,liter,doors,cruise,sound,leather)\n", " st.write('Fiyat:$', round(pred[0],2))" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "xC3w9NK_3Lmh", "outputId": "f232a770-f806-4362-dce1-ea2ea73e79cf" }, "execution_count": 23, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "2024-06-18 15:00:30.503 \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 /usr/local/lib/python3.10/dist-packages/colab_kernel_launcher.py [ARGUMENTS]\n", "2024-06-18 15:00:30.507 Session state does not function when running a script without `streamlit run`\n" ] } ] } ] }