{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "00ce0a45", "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "id": "e54b6ee2", "metadata": {}, "outputs": [], "source": [ "df=pd.read_csv(\"E:\\Datasets\\merc.csv\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "9c288a1c", "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", "
modelyearpricetransmissionmileagefuelTypetaxmpgengineSize
0SLK20055200Automatic63000Petrol32532.11.8
1S Class201734948Automatic27000Hybrid2061.42.1
2SL CLASS201649948Automatic6200Petrol55528.05.5
3G Class201661948Automatic16000Petrol32530.44.0
4G Class201673948Automatic4000Petrol32530.14.0
..............................
13114C Class202035999Automatic500Diesel14555.42.0
13115B Class202024699Automatic2500Diesel14555.42.0
13116GLC Class201930999Automatic11612Diesel14541.52.1
13117CLS Class201937990Automatic2426Diesel14545.62.0
13118S Class201954999Automatic2075Diesel14552.32.9
\n", "

13119 rows × 9 columns

\n", "
" ], "text/plain": [ " model year price transmission mileage fuelType tax mpg \\\n", "0 SLK 2005 5200 Automatic 63000 Petrol 325 32.1 \n", "1 S Class 2017 34948 Automatic 27000 Hybrid 20 61.4 \n", "2 SL CLASS 2016 49948 Automatic 6200 Petrol 555 28.0 \n", "3 G Class 2016 61948 Automatic 16000 Petrol 325 30.4 \n", "4 G Class 2016 73948 Automatic 4000 Petrol 325 30.1 \n", "... ... ... ... ... ... ... ... ... \n", "13114 C Class 2020 35999 Automatic 500 Diesel 145 55.4 \n", "13115 B Class 2020 24699 Automatic 2500 Diesel 145 55.4 \n", "13116 GLC Class 2019 30999 Automatic 11612 Diesel 145 41.5 \n", "13117 CLS Class 2019 37990 Automatic 2426 Diesel 145 45.6 \n", "13118 S Class 2019 54999 Automatic 2075 Diesel 145 52.3 \n", "\n", " engineSize \n", "0 1.8 \n", "1 2.1 \n", "2 5.5 \n", "3 4.0 \n", "4 4.0 \n", "... ... \n", "13114 2.0 \n", "13115 2.0 \n", "13116 2.1 \n", "13117 2.0 \n", "13118 2.9 \n", "\n", "[13119 rows x 9 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 4, "id": "c059df79", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "model 0\n", "year 0\n", "price 0\n", "transmission 0\n", "mileage 0\n", "fuelType 0\n", "tax 0\n", "mpg 0\n", "engineSize 0\n", "dtype: int64" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.isnull().sum()" ] }, { "cell_type": "code", "execution_count": 5, "id": "d0b61c22", "metadata": {}, "outputs": [], "source": [ "y=df[\"price\"]" ] }, { "cell_type": "code", "execution_count": 6, "id": "71dd2ddd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 5200\n", "1 34948\n", "2 49948\n", "3 61948\n", "4 73948\n", " ... \n", "13114 35999\n", "13115 24699\n", "13116 30999\n", "13117 37990\n", "13118 54999\n", "Name: price, Length: 13119, dtype: int64" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "y" ] }, { "cell_type": "code", "execution_count": 7, "id": "6fd46ef0", "metadata": {}, "outputs": [], "source": [ "x=df.drop([\"price\"],axis=\"columns\")" ] }, { "cell_type": "code", "execution_count": 8, "id": "bdf64fb9", "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", "
modelyeartransmissionmileagefuelTypetaxmpgengineSize
0SLK2005Automatic63000Petrol32532.11.8
1S Class2017Automatic27000Hybrid2061.42.1
2SL CLASS2016Automatic6200Petrol55528.05.5
3G Class2016Automatic16000Petrol32530.44.0
4G Class2016Automatic4000Petrol32530.14.0
...........................
13114C Class2020Automatic500Diesel14555.42.0
13115B Class2020Automatic2500Diesel14555.42.0
13116GLC Class2019Automatic11612Diesel14541.52.1
13117CLS Class2019Automatic2426Diesel14545.62.0
13118S Class2019Automatic2075Diesel14552.32.9
\n", "

13119 rows × 8 columns

\n", "
" ], "text/plain": [ " model year transmission mileage fuelType tax mpg engineSize\n", "0 SLK 2005 Automatic 63000 Petrol 325 32.1 1.8\n", "1 S Class 2017 Automatic 27000 Hybrid 20 61.4 2.1\n", "2 SL CLASS 2016 Automatic 6200 Petrol 555 28.0 5.5\n", "3 G Class 2016 Automatic 16000 Petrol 325 30.4 4.0\n", "4 G Class 2016 Automatic 4000 Petrol 325 30.1 4.0\n", "... ... ... ... ... ... ... ... ...\n", "13114 C Class 2020 Automatic 500 Diesel 145 55.4 2.0\n", "13115 B Class 2020 Automatic 2500 Diesel 145 55.4 2.0\n", "13116 GLC Class 2019 Automatic 11612 Diesel 145 41.5 2.1\n", "13117 CLS Class 2019 Automatic 2426 Diesel 145 45.6 2.0\n", "13118 S Class 2019 Automatic 2075 Diesel 145 52.3 2.9\n", "\n", "[13119 rows x 8 columns]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x" ] }, { "cell_type": "code", "execution_count": 9, "id": "32d7ec94", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(13119, 8)" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x.shape" ] }, { "cell_type": "code", "execution_count": 10, "id": "50c78c80", "metadata": {}, "outputs": [], "source": [ "x=pd.get_dummies(x)" ] }, { "cell_type": "code", "execution_count": 11, "id": "84a2688b", "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
yearmileagetaxmpgengineSizemodel_ A Classmodel_ B Classmodel_ C Classmodel_ CL Classmodel_ CLA Class...model_220model_230transmission_Automatictransmission_Manualtransmission_Othertransmission_Semi-AutofuelType_DieselfuelType_HybridfuelType_OtherfuelType_Petrol
020056300032532.11.800000...0010000001
12017270002061.42.100000...0010000100
22016620055528.05.500000...0010000001
320161600032530.44.000000...0010000001
42016400032530.14.000000...0010000001
..................................................................
13114202050014555.42.000100...0010001000
131152020250014555.42.001000...0010001000
1311620191161214541.52.100000...0010001000
131172019242614545.62.000000...0010001000
131182019207514552.32.900000...0010001000
\n", "

13119 rows × 40 columns

\n", "
" ], "text/plain": [ " year mileage tax mpg engineSize model_ A Class model_ B Class \\\n", "0 2005 63000 325 32.1 1.8 0 0 \n", "1 2017 27000 20 61.4 2.1 0 0 \n", "2 2016 6200 555 28.0 5.5 0 0 \n", "3 2016 16000 325 30.4 4.0 0 0 \n", "4 2016 4000 325 30.1 4.0 0 0 \n", "... ... ... ... ... ... ... ... \n", "13114 2020 500 145 55.4 2.0 0 0 \n", "13115 2020 2500 145 55.4 2.0 0 1 \n", "13116 2019 11612 145 41.5 2.1 0 0 \n", "13117 2019 2426 145 45.6 2.0 0 0 \n", "13118 2019 2075 145 52.3 2.9 0 0 \n", "\n", " model_ C Class model_ CL Class model_ CLA Class ... model_220 \\\n", "0 0 0 0 ... 0 \n", "1 0 0 0 ... 0 \n", "2 0 0 0 ... 0 \n", "3 0 0 0 ... 0 \n", "4 0 0 0 ... 0 \n", "... ... ... ... ... ... \n", "13114 1 0 0 ... 0 \n", "13115 0 0 0 ... 0 \n", "13116 0 0 0 ... 0 \n", "13117 0 0 0 ... 0 \n", "13118 0 0 0 ... 0 \n", "\n", " model_230 transmission_Automatic transmission_Manual \\\n", "0 0 1 0 \n", "1 0 1 0 \n", "2 0 1 0 \n", "3 0 1 0 \n", "4 0 1 0 \n", "... ... ... ... \n", "13114 0 1 0 \n", "13115 0 1 0 \n", "13116 0 1 0 \n", "13117 0 1 0 \n", "13118 0 1 0 \n", "\n", " transmission_Other transmission_Semi-Auto fuelType_Diesel \\\n", "0 0 0 0 \n", "1 0 0 0 \n", "2 0 0 0 \n", "3 0 0 0 \n", "4 0 0 0 \n", "... ... ... ... \n", "13114 0 0 1 \n", "13115 0 0 1 \n", "13116 0 0 1 \n", "13117 0 0 1 \n", "13118 0 0 1 \n", "\n", " fuelType_Hybrid fuelType_Other fuelType_Petrol \n", "0 0 0 1 \n", "1 1 0 0 \n", "2 0 0 1 \n", "3 0 0 1 \n", "4 0 0 1 \n", "... ... ... ... \n", "13114 0 0 0 \n", "13115 0 0 0 \n", "13116 0 0 0 \n", "13117 0 0 0 \n", "13118 0 0 0 \n", "\n", "[13119 rows x 40 columns]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x" ] }, { "cell_type": "code", "execution_count": 12, "id": "1f215226", "metadata": {}, "outputs": [], "source": [ "from sklearn.model_selection import train_test_split as tts" ] }, { "cell_type": "code", "execution_count": 13, "id": "a5b19be1", "metadata": {}, "outputs": [], "source": [ "xtrain,xtest,ytrain,ytest=tts(x,y,test_size=0.2)" ] }, { "cell_type": "code", "execution_count": 14, "id": "e7fc57b9", "metadata": {}, "outputs": [], "source": [ "from sklearn.linear_model import LogisticRegression as lr" ] }, { "cell_type": "code", "execution_count": 15, "id": "ed36c9cb", "metadata": {}, "outputs": [], "source": [ "model=lr()" ] }, { "cell_type": "code", "execution_count": 16, "id": "e896cfb4", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\Sakthivel\\anaconda3\\lib\\site-packages\\sklearn\\linear_model\\_logistic.py:763: ConvergenceWarning: lbfgs failed to converge (status=1):\n", "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n", "\n", "Increase the number of iterations (max_iter) or scale the data as shown in:\n", " https://scikit-learn.org/stable/modules/preprocessing.html\n", "Please also refer to the documentation for alternative solver options:\n", " https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n", " n_iter_i = _check_optimize_result(\n" ] }, { "data": { "text/plain": [ "LogisticRegression()" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.fit(xtrain,ytrain)" ] }, { "cell_type": "code", "execution_count": 17, "id": "9f65dce0", "metadata": {}, "outputs": [], "source": [ "pred=model.predict(xtest)" ] }, { "cell_type": "code", "execution_count": 18, "id": "497a336b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[19999 19999 19999 ... 24999 15999 15999]\n" ] } ], "source": [ "print(pred)" ] }, { "cell_type": "code", "execution_count": null, "id": "0a94b88a", "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.8.8" } }, "nbformat": 4, "nbformat_minor": 5 }