PredictiveAnalytics/lab2.ipynb

3143 lines
96 KiB
Plaintext
Raw Normal View History

2025-01-06 23:21:44 +04:00
{
"cells": [
{
"cell_type": "code",
2025-01-06 23:37:51 +04:00
"execution_count": 228,
2025-01-06 23:21:44 +04:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"Index: 1354 entries, 0 to 1369\n",
"Data columns (total 18 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 Name_phone 1354 non-null object \n",
" 1 Rating 1354 non-null float64\n",
" 2 Spec_score 1354 non-null int64 \n",
" 3 No_of_sim 1354 non-null object \n",
" 4 Ram 1354 non-null object \n",
" 5 Battery 1354 non-null object \n",
" 6 Display 1354 non-null object \n",
" 7 Camera 1354 non-null object \n",
" 8 External_Memory 1354 non-null object \n",
" 9 Android_version 914 non-null object \n",
" 10 Price 1354 non-null object \n",
" 11 company 1354 non-null object \n",
" 12 Inbuilt_memory 1335 non-null object \n",
" 13 fast_charging 1267 non-null object \n",
" 14 Screen_resolution 1353 non-null object \n",
" 15 Processor 1327 non-null object \n",
" 16 Processor_name 1354 non-null object \n",
" 17 Class 1354 non-null int64 \n",
"dtypes: float64(1), int64(2), object(15)\n",
"memory usage: 201.0+ KB\n"
]
},
{
"data": {
"text/plain": [
"(1354, 18)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Name_phone</th>\n",
" <th>Rating</th>\n",
" <th>Spec_score</th>\n",
" <th>No_of_sim</th>\n",
" <th>Ram</th>\n",
" <th>Battery</th>\n",
" <th>Display</th>\n",
" <th>Camera</th>\n",
" <th>External_Memory</th>\n",
" <th>Android_version</th>\n",
" <th>Price</th>\n",
" <th>company</th>\n",
" <th>Inbuilt_memory</th>\n",
" <th>fast_charging</th>\n",
" <th>Screen_resolution</th>\n",
" <th>Processor</th>\n",
" <th>Processor_name</th>\n",
" <th>Class</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Id</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Samsung Galaxy F14 5G</td>\n",
" <td>4.65</td>\n",
" <td>68</td>\n",
" <td>Dual Sim, 3G, 4G, 5G, VoLTE,</td>\n",
" <td>4 GB RAM</td>\n",
" <td>6000 mAh Battery</td>\n",
" <td>6.6 inches</td>\n",
" <td>50 MP + 2 MP Dual Rear &amp;amp; 13 MP Front Camera</td>\n",
" <td>Memory Card Supported, upto 1 TB</td>\n",
" <td>13</td>\n",
" <td>9,999</td>\n",
" <td>Samsung</td>\n",
" <td>128 GB inbuilt</td>\n",
" <td>25W Fast Charging</td>\n",
" <td>2408 x 1080 px Display with Water Drop Notch</td>\n",
" <td>Octa Core Processor</td>\n",
" <td>Exynos 1330</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Samsung Galaxy A11</td>\n",
" <td>4.20</td>\n",
" <td>63</td>\n",
" <td>Dual Sim, 3G, 4G, VoLTE,</td>\n",
" <td>2 GB RAM</td>\n",
" <td>4000 mAh Battery</td>\n",
" <td>6.4 inches</td>\n",
" <td>13 MP + 5 MP + 2 MP Triple Rear &amp;amp; 8 MP Fro...</td>\n",
" <td>Memory Card Supported, upto 512 GB</td>\n",
" <td>10</td>\n",
" <td>9,990</td>\n",
" <td>Samsung</td>\n",
" <td>32 GB inbuilt</td>\n",
" <td>15W Fast Charging</td>\n",
" <td>720 x 1560 px Display with Punch Hole</td>\n",
" <td>1.8 GHz Processor</td>\n",
" <td>Octa Core</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Samsung Galaxy F23</td>\n",
" <td>4.10</td>\n",
" <td>73</td>\n",
" <td>Dual Sim, 3G, 4G, VoLTE,</td>\n",
" <td>4 GB RAM</td>\n",
" <td>6000 mAh Battery</td>\n",
" <td>6.4 inches</td>\n",
" <td>48 MP Quad Rear &amp;amp; 13 MP Front Camera</td>\n",
" <td>Memory Card Supported, upto 1 TB</td>\n",
" <td>12</td>\n",
" <td>11,999</td>\n",
" <td>Samsung</td>\n",
" <td>64 GB inbuilt</td>\n",
" <td>NaN</td>\n",
" <td>720 x 1600 px</td>\n",
" <td>Octa Core</td>\n",
" <td>Helio G88</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Samsung Galaxy A03s (4GB RAM + 64GB)</td>\n",
" <td>4.10</td>\n",
" <td>69</td>\n",
" <td>Dual Sim, 3G, 4G, VoLTE,</td>\n",
" <td>4 GB RAM</td>\n",
" <td>5000 mAh Battery</td>\n",
" <td>6.5 inches</td>\n",
" <td>13 MP + 2 MP + 2 MP Triple Rear &amp;amp; 5 MP Fro...</td>\n",
" <td>Memory Card Supported, upto 1 TB</td>\n",
" <td>11</td>\n",
" <td>11,999</td>\n",
" <td>Samsung</td>\n",
" <td>64 GB inbuilt</td>\n",
" <td>15W Fast Charging</td>\n",
" <td>720 x 1600 px Display with Water Drop Notch</td>\n",
" <td>Octa Core</td>\n",
" <td>Helio P35</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Samsung Galaxy M13 5G</td>\n",
" <td>4.40</td>\n",
" <td>75</td>\n",
" <td>Dual Sim, 3G, 4G, 5G, VoLTE,</td>\n",
" <td>6 GB RAM</td>\n",
" <td>5000 mAh Battery</td>\n",
" <td>6.5 inches</td>\n",
" <td>50 MP + 2 MP Dual Rear &amp;amp; 5 MP Front Camera</td>\n",
" <td>Memory Card Supported, upto 1 TB</td>\n",
" <td>12</td>\n",
" <td>11,990</td>\n",
" <td>Samsung</td>\n",
" <td>128 GB inbuilt</td>\n",
" <td>15W Fast Charging</td>\n",
" <td>720 x 1600 px</td>\n",
" <td>Octa Core</td>\n",
" <td>Dimensity 700</td>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Name_phone Rating Spec_score \\\n",
"Id \n",
"0 Samsung Galaxy F14 5G 4.65 68 \n",
"1 Samsung Galaxy A11 4.20 63 \n",
"3 Samsung Galaxy F23 4.10 73 \n",
"4 Samsung Galaxy A03s (4GB RAM + 64GB) 4.10 69 \n",
"5 Samsung Galaxy M13 5G 4.40 75 \n",
"\n",
" No_of_sim Ram Battery Display \\\n",
"Id \n",
"0 Dual Sim, 3G, 4G, 5G, VoLTE, 4 GB RAM 6000 mAh Battery 6.6 inches \n",
"1 Dual Sim, 3G, 4G, VoLTE, 2 GB RAM 4000 mAh Battery 6.4 inches \n",
"3 Dual Sim, 3G, 4G, VoLTE, 4 GB RAM 6000 mAh Battery 6.4 inches \n",
"4 Dual Sim, 3G, 4G, VoLTE, 4 GB RAM 5000 mAh Battery 6.5 inches \n",
"5 Dual Sim, 3G, 4G, 5G, VoLTE, 6 GB RAM 5000 mAh Battery 6.5 inches \n",
"\n",
" Camera \\\n",
"Id \n",
"0 50 MP + 2 MP Dual Rear &amp; 13 MP Front Camera \n",
"1 13 MP + 5 MP + 2 MP Triple Rear &amp; 8 MP Fro... \n",
"3 48 MP Quad Rear &amp; 13 MP Front Camera \n",
"4 13 MP + 2 MP + 2 MP Triple Rear &amp; 5 MP Fro... \n",
"5 50 MP + 2 MP Dual Rear &amp; 5 MP Front Camera \n",
"\n",
" External_Memory Android_version Price company \\\n",
"Id \n",
"0 Memory Card Supported, upto 1 TB 13 9,999 Samsung \n",
"1 Memory Card Supported, upto 512 GB 10 9,990 Samsung \n",
"3 Memory Card Supported, upto 1 TB 12 11,999 Samsung \n",
"4 Memory Card Supported, upto 1 TB 11 11,999 Samsung \n",
"5 Memory Card Supported, upto 1 TB 12 11,990 Samsung \n",
"\n",
" Inbuilt_memory fast_charging \\\n",
"Id \n",
"0 128 GB inbuilt 25W Fast Charging \n",
"1 32 GB inbuilt 15W Fast Charging \n",
"3 64 GB inbuilt NaN \n",
"4 64 GB inbuilt 15W Fast Charging \n",
"5 128 GB inbuilt 15W Fast Charging \n",
"\n",
" Screen_resolution Processor \\\n",
"Id \n",
"0 2408 x 1080 px Display with Water Drop Notch Octa Core Processor \n",
"1 720 x 1560 px Display with Punch Hole 1.8 GHz Processor \n",
"3 720 x 1600 px Octa Core \n",
"4 720 x 1600 px Display with Water Drop Notch Octa Core \n",
"5 720 x 1600 px Octa Core \n",
"\n",
" Processor_name Class \n",
"Id \n",
"0 Exynos 1330 2 \n",
"1 Octa Core 2 \n",
"3 Helio G88 1 \n",
"4 Helio P35 2 \n",
"5 Dimensity 700 1 "
]
},
2025-01-06 23:37:51 +04:00
"execution_count": 228,
2025-01-06 23:21:44 +04:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"phone = pd.read_csv(\"data/phone_price.csv\", index_col=\"Id\")\n",
"\n",
"phone.info()\n",
"\n",
"display(phone.shape)\n",
"\n",
"phone.head()\n"
]
},
{
"cell_type": "code",
2025-01-06 23:37:51 +04:00
"execution_count": 229,
2025-01-06 23:21:44 +04:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 19227 entries, 0 to 19226\n",
"Data columns (total 20 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 Unnamed: 0 19227 non-null int64 \n",
" 1 ID 19227 non-null int64 \n",
" 2 Price 19227 non-null int64 \n",
" 3 Levy 19227 non-null object \n",
" 4 Manufacturer 19227 non-null object \n",
" 5 Model 19227 non-null object \n",
" 6 ProdYear 19227 non-null int64 \n",
" 7 Category 19227 non-null object \n",
" 8 Leather interior 19227 non-null object \n",
" 9 Fuel type 19227 non-null object \n",
" 10 Engine volume 19227 non-null object \n",
" 11 Mileage 19227 non-null object \n",
" 12 Cylinders 19227 non-null float64\n",
" 13 Gear box type 19227 non-null object \n",
" 14 Drive wheels 19227 non-null object \n",
" 15 Doors 19227 non-null object \n",
" 16 Wheel 19227 non-null object \n",
" 17 Color 19227 non-null object \n",
" 18 Airbags 19227 non-null int64 \n",
" 19 LeatherInterior1 19227 non-null int64 \n",
"dtypes: float64(1), int64(6), object(13)\n",
"memory usage: 2.9+ MB\n"
]
},
{
"data": {
"text/plain": [
"(19227, 20)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Unnamed: 0</th>\n",
" <th>ID</th>\n",
" <th>Price</th>\n",
" <th>Levy</th>\n",
" <th>Manufacturer</th>\n",
" <th>Model</th>\n",
" <th>ProdYear</th>\n",
" <th>Category</th>\n",
" <th>Leather interior</th>\n",
" <th>Fuel type</th>\n",
" <th>Engine volume</th>\n",
" <th>Mileage</th>\n",
" <th>Cylinders</th>\n",
" <th>Gear box type</th>\n",
" <th>Drive wheels</th>\n",
" <th>Doors</th>\n",
" <th>Wheel</th>\n",
" <th>Color</th>\n",
" <th>Airbags</th>\n",
" <th>LeatherInterior1</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>45654403</td>\n",
" <td>13328</td>\n",
" <td>1399</td>\n",
" <td>LEXUS</td>\n",
" <td>RX 450</td>\n",
" <td>2010</td>\n",
" <td>Jeep</td>\n",
" <td>Yes</td>\n",
" <td>Hybrid</td>\n",
" <td>3.5</td>\n",
" <td>186005 km</td>\n",
" <td>6.0</td>\n",
" <td>Automatic</td>\n",
" <td>4x4</td>\n",
" <td>04-May</td>\n",
" <td>Left wheel</td>\n",
" <td>Silver</td>\n",
" <td>12</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1</td>\n",
" <td>44731507</td>\n",
" <td>16621</td>\n",
" <td>1018</td>\n",
" <td>CHEVROLET</td>\n",
" <td>Equinox</td>\n",
" <td>2011</td>\n",
" <td>Jeep</td>\n",
" <td>No</td>\n",
" <td>Petrol</td>\n",
" <td>3</td>\n",
" <td>192000 km</td>\n",
" <td>6.0</td>\n",
" <td>Tiptronic</td>\n",
" <td>4x4</td>\n",
" <td>04-May</td>\n",
" <td>Left wheel</td>\n",
" <td>Black</td>\n",
" <td>8</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2</td>\n",
" <td>45774419</td>\n",
" <td>8467</td>\n",
" <td>-</td>\n",
" <td>HONDA</td>\n",
" <td>FIT</td>\n",
" <td>2006</td>\n",
" <td>Hatchback</td>\n",
" <td>No</td>\n",
" <td>Petrol</td>\n",
" <td>1.3</td>\n",
" <td>200000 km</td>\n",
" <td>4.0</td>\n",
" <td>Variator</td>\n",
" <td>Front</td>\n",
" <td>04-May</td>\n",
" <td>Right-hand drive</td>\n",
" <td>Black</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>3</td>\n",
" <td>45769185</td>\n",
" <td>3607</td>\n",
" <td>862</td>\n",
" <td>FORD</td>\n",
" <td>Escape</td>\n",
" <td>2011</td>\n",
" <td>Jeep</td>\n",
" <td>Yes</td>\n",
" <td>Hybrid</td>\n",
" <td>2.5</td>\n",
" <td>168966 km</td>\n",
" <td>4.0</td>\n",
" <td>Automatic</td>\n",
" <td>4x4</td>\n",
" <td>04-May</td>\n",
" <td>Left wheel</td>\n",
" <td>White</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>4</td>\n",
" <td>45809263</td>\n",
" <td>11726</td>\n",
" <td>446</td>\n",
" <td>HONDA</td>\n",
" <td>FIT</td>\n",
" <td>2014</td>\n",
" <td>Hatchback</td>\n",
" <td>Yes</td>\n",
" <td>Petrol</td>\n",
" <td>1.3</td>\n",
" <td>91901 km</td>\n",
" <td>4.0</td>\n",
" <td>Automatic</td>\n",
" <td>Front</td>\n",
" <td>04-May</td>\n",
" <td>Left wheel</td>\n",
" <td>Silver</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Unnamed: 0 ID Price Levy Manufacturer Model ProdYear \\\n",
"0 0 45654403 13328 1399 LEXUS RX 450 2010 \n",
"1 1 44731507 16621 1018 CHEVROLET Equinox 2011 \n",
"2 2 45774419 8467 - HONDA FIT 2006 \n",
"3 3 45769185 3607 862 FORD Escape 2011 \n",
"4 4 45809263 11726 446 HONDA FIT 2014 \n",
"\n",
" Category Leather interior Fuel type Engine volume Mileage Cylinders \\\n",
"0 Jeep Yes Hybrid 3.5 186005 km 6.0 \n",
"1 Jeep No Petrol 3 192000 km 6.0 \n",
"2 Hatchback No Petrol 1.3 200000 km 4.0 \n",
"3 Jeep Yes Hybrid 2.5 168966 km 4.0 \n",
"4 Hatchback Yes Petrol 1.3 91901 km 4.0 \n",
"\n",
" Gear box type Drive wheels Doors Wheel Color Airbags \\\n",
"0 Automatic 4x4 04-May Left wheel Silver 12 \n",
"1 Tiptronic 4x4 04-May Left wheel Black 8 \n",
"2 Variator Front 04-May Right-hand drive Black 2 \n",
"3 Automatic 4x4 04-May Left wheel White 0 \n",
"4 Automatic Front 04-May Left wheel Silver 4 \n",
"\n",
" LeatherInterior1 \n",
"0 1 \n",
"1 0 \n",
"2 0 \n",
"3 1 \n",
"4 1 "
]
},
2025-01-06 23:37:51 +04:00
"execution_count": 229,
2025-01-06 23:21:44 +04:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"car = pd.read_csv(\"data/car_price.csv\")\n",
"\n",
"car.info()\n",
"\n",
"display(car.shape)\n",
"\n",
"car.head()"
]
},
{
"cell_type": "code",
2025-01-06 23:37:51 +04:00
"execution_count": 230,
2025-01-06 23:21:44 +04:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 3299 entries, 0 to 3298\n",
"Data columns (total 21 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 id 3299 non-null int64 \n",
" 1 date 3299 non-null object \n",
" 2 price 3299 non-null float64\n",
" 3 bedrooms 3299 non-null int64 \n",
" 4 bathrooms 3299 non-null float64\n",
" 5 sqft_living 3299 non-null int64 \n",
" 6 sqft_lot 3299 non-null int64 \n",
" 7 floors 3299 non-null float64\n",
" 8 waterfront 3299 non-null int64 \n",
" 9 view 3299 non-null int64 \n",
" 10 condition 3299 non-null int64 \n",
" 11 grade 3299 non-null int64 \n",
" 12 sqft_above 3299 non-null int64 \n",
" 13 sqft_basement 3299 non-null int64 \n",
" 14 yr_built 3299 non-null int64 \n",
" 15 yr_renovated 3299 non-null int64 \n",
" 16 zipcode 3299 non-null int64 \n",
" 17 lat 3299 non-null float64\n",
" 18 long 3299 non-null float64\n",
" 19 sqft_living15 3299 non-null int64 \n",
" 20 sqft_lot15 3299 non-null int64 \n",
"dtypes: float64(5), int64(15), object(1)\n",
"memory usage: 541.4+ KB\n"
]
},
{
"data": {
"text/plain": [
"(3299, 21)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>id</th>\n",
" <th>date</th>\n",
" <th>price</th>\n",
" <th>bedrooms</th>\n",
" <th>bathrooms</th>\n",
" <th>sqft_living</th>\n",
" <th>sqft_lot</th>\n",
" <th>floors</th>\n",
" <th>waterfront</th>\n",
" <th>view</th>\n",
" <th>...</th>\n",
" <th>grade</th>\n",
" <th>sqft_above</th>\n",
" <th>sqft_basement</th>\n",
" <th>yr_built</th>\n",
" <th>yr_renovated</th>\n",
" <th>zipcode</th>\n",
" <th>lat</th>\n",
" <th>long</th>\n",
" <th>sqft_living15</th>\n",
" <th>sqft_lot15</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>7129300520</td>\n",
" <td>20141013T000000</td>\n",
" <td>221900.0</td>\n",
" <td>3</td>\n",
" <td>1.00</td>\n",
" <td>1180</td>\n",
" <td>5650</td>\n",
" <td>1.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>7</td>\n",
" <td>1180</td>\n",
" <td>0</td>\n",
" <td>1955</td>\n",
" <td>0</td>\n",
" <td>98178</td>\n",
" <td>47.5112</td>\n",
" <td>-122.257</td>\n",
" <td>1340</td>\n",
" <td>5650</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>6414100192</td>\n",
" <td>20141209T000000</td>\n",
" <td>538000.0</td>\n",
" <td>3</td>\n",
" <td>2.25</td>\n",
" <td>2570</td>\n",
" <td>7242</td>\n",
" <td>2.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>7</td>\n",
" <td>2170</td>\n",
" <td>400</td>\n",
" <td>1951</td>\n",
" <td>1991</td>\n",
" <td>98125</td>\n",
" <td>47.7210</td>\n",
" <td>-122.319</td>\n",
" <td>1690</td>\n",
" <td>7639</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>5631500400</td>\n",
" <td>20150225T000000</td>\n",
" <td>180000.0</td>\n",
" <td>2</td>\n",
" <td>1.00</td>\n",
" <td>770</td>\n",
" <td>10000</td>\n",
" <td>1.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>6</td>\n",
" <td>770</td>\n",
" <td>0</td>\n",
" <td>1933</td>\n",
" <td>0</td>\n",
" <td>98028</td>\n",
" <td>47.7379</td>\n",
" <td>-122.233</td>\n",
" <td>2720</td>\n",
" <td>8062</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2487200875</td>\n",
" <td>20141209T000000</td>\n",
" <td>604000.0</td>\n",
" <td>4</td>\n",
" <td>3.00</td>\n",
" <td>1960</td>\n",
" <td>5000</td>\n",
" <td>1.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>7</td>\n",
" <td>1050</td>\n",
" <td>910</td>\n",
" <td>1965</td>\n",
" <td>0</td>\n",
" <td>98136</td>\n",
" <td>47.5208</td>\n",
" <td>-122.393</td>\n",
" <td>1360</td>\n",
" <td>5000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1954400510</td>\n",
" <td>20150218T000000</td>\n",
" <td>510000.0</td>\n",
" <td>3</td>\n",
" <td>2.00</td>\n",
" <td>1680</td>\n",
" <td>8080</td>\n",
" <td>1.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>8</td>\n",
" <td>1680</td>\n",
" <td>0</td>\n",
" <td>1987</td>\n",
" <td>0</td>\n",
" <td>98074</td>\n",
" <td>47.6168</td>\n",
" <td>-122.045</td>\n",
" <td>1800</td>\n",
" <td>7503</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 21 columns</p>\n",
"</div>"
],
"text/plain": [
" id date price bedrooms bathrooms sqft_living \\\n",
"0 7129300520 20141013T000000 221900.0 3 1.00 1180 \n",
"1 6414100192 20141209T000000 538000.0 3 2.25 2570 \n",
"2 5631500400 20150225T000000 180000.0 2 1.00 770 \n",
"3 2487200875 20141209T000000 604000.0 4 3.00 1960 \n",
"4 1954400510 20150218T000000 510000.0 3 2.00 1680 \n",
"\n",
" sqft_lot floors waterfront view ... grade sqft_above sqft_basement \\\n",
"0 5650 1.0 0 0 ... 7 1180 0 \n",
"1 7242 2.0 0 0 ... 7 2170 400 \n",
"2 10000 1.0 0 0 ... 6 770 0 \n",
"3 5000 1.0 0 0 ... 7 1050 910 \n",
"4 8080 1.0 0 0 ... 8 1680 0 \n",
"\n",
" yr_built yr_renovated zipcode lat long sqft_living15 \\\n",
"0 1955 0 98178 47.5112 -122.257 1340 \n",
"1 1951 1991 98125 47.7210 -122.319 1690 \n",
"2 1933 0 98028 47.7379 -122.233 2720 \n",
"3 1965 0 98136 47.5208 -122.393 1360 \n",
"4 1987 0 98074 47.6168 -122.045 1800 \n",
"\n",
" sqft_lot15 \n",
"0 5650 \n",
"1 7639 \n",
"2 8062 \n",
"3 5000 \n",
"4 7503 \n",
"\n",
"[5 rows x 21 columns]"
]
},
2025-01-06 23:37:51 +04:00
"execution_count": 230,
2025-01-06 23:21:44 +04:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"house = pd.read_csv(\"data/house_data.csv\")\n",
"\n",
"house.info()\n",
"\n",
"display(house.shape)\n",
"\n",
"house.head()"
]
},
2025-01-06 23:37:51 +04:00
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"1. Продажа домов\n",
"\n",
" Цель: Определение рыночной стоимости домов для оптимизации ценовой политики.\n",
"\n",
" Эффект: Улучшение конкурентоспособности на рынке недвижимости и увеличение объема продаж за счет правильного ценообразования. Возможность точного прогнозирования цен и повышения удовлетворенности клиентов.\n",
"\n",
"2. Цены на автомобили\n",
"\n",
" Цель: Оценка цен на автомобили в зависимости от различных факторов (например, пробег, марка, модель, год выпуска).\n",
"\n",
" Эффект: Увеличение привлекательности предложения за счет адекватного ценообразования и минимизации убытков от продажи автомобилей. Позволяет более точно прогнозировать потребности клиентов и улучшить управление запасами.\n",
"\n",
"3. Цены на мобильные устройства\n",
"\n",
" Цель: Определение причин изменения цен на мобильные устройства и оценка влияния сезонных скидок на спрос.\n",
"\n",
" Эффект: Оптимизация маркетинговых стратегий и акций, что может привести к увеличению объемов продаж. Улучшение прогнозирования спроса и управление ассортиментом на основе ценовых изменений."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"1. Продажа домов\n",
" \n",
" Цель технического проекта: Разработка системы оценки рыночной стоимости недвижимости на основе анализа данных о продажах.\n",
"\n",
" Вход: Набор данных о прошедших продажах домов (цена, площадь, местоположение, количество комнат, год постройки и т.д.).\n",
"\n",
" Целевой признак: Рыночная цена продажи домов.\n",
"\n",
"2. Цены на автомобили\n",
"\n",
" Цель технического проекта: Создание алгоритма, который предсказывает цены на автомобили с учетом различных характеристик и рыночных тенденций.\n",
"\n",
" Вход: Данные о характеристиках автомобилей (марка, модель, год выпуска, пробег, состояние) и цены на аналогичные автомобили.\n",
"\n",
" Целевой признак: Цена автомобиля.\n",
"\n",
"3. Цены на мобильные устройства\n",
"\n",
" Цель технического проекта: Разработка системы, анализирующей влияние маркетинговых акций на цены и спрос на мобильные устройства.\n",
"\n",
" Вход: Данные о ценах на мобильные устройства (с учетом скидок), история продаж, информация о маркетинговых акциях и сезонные колебания.\n",
"\n",
" Целевой признак: Объем продаж мобильных устройств."
]
},
2025-01-06 23:21:44 +04:00
{
"cell_type": "code",
2025-01-06 23:37:51 +04:00
"execution_count": 231,
2025-01-06 23:21:44 +04:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Name_phone 0\n",
"Rating 0\n",
"Spec_score 0\n",
"No_of_sim 0\n",
"Ram 0\n",
"Battery 0\n",
"Display 0\n",
"Camera 0\n",
"External_Memory 0\n",
"Android_version 440\n",
"Price 0\n",
"company 0\n",
"Inbuilt_memory 19\n",
"fast_charging 87\n",
"Screen_resolution 1\n",
"Processor 27\n",
"Processor_name 0\n",
"Class 0\n",
"dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"Name_phone False\n",
"Rating False\n",
"Spec_score False\n",
"No_of_sim False\n",
"Ram False\n",
"Battery False\n",
"Display False\n",
"Camera False\n",
"External_Memory False\n",
"Android_version True\n",
"Price False\n",
"company False\n",
"Inbuilt_memory True\n",
"fast_charging True\n",
"Screen_resolution True\n",
"Processor True\n",
"Processor_name False\n",
"Class False\n",
"dtype: bool"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Android_version процент пустых значений: %32.50'"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Inbuilt_memory процент пустых значений: %1.40'"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'fast_charging процент пустых значений: %6.43'"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Screen_resolution процент пустых значений: %0.07'"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Processor процент пустых значений: %1.99'"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Количество пустых значений признаков\n",
"display(phone.isnull().sum())\n",
"display()\n",
"\n",
"# Есть ли пустые значения признаков\n",
"display(phone.isnull().any())\n",
"display()\n",
"\n",
"# Процент пустых значений признаков\n",
"for i in phone.columns:\n",
" null_rate = phone[i].isnull().sum() / len(phone) * 100\n",
" if null_rate > 0:\n",
" display(f\"{i} процент пустых значений: %{null_rate:.2f}\")"
]
},
{
"cell_type": "code",
2025-01-06 23:37:51 +04:00
"execution_count": 232,
2025-01-06 23:21:44 +04:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Unnamed: 0 0\n",
"ID 0\n",
"Price 0\n",
"Levy 0\n",
"Manufacturer 0\n",
"Model 0\n",
"ProdYear 0\n",
"Category 0\n",
"Leather interior 0\n",
"Fuel type 0\n",
"Engine volume 0\n",
"Mileage 0\n",
"Cylinders 0\n",
"Gear box type 0\n",
"Drive wheels 0\n",
"Doors 0\n",
"Wheel 0\n",
"Color 0\n",
"Airbags 0\n",
"LeatherInterior1 0\n",
"dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"Unnamed: 0 False\n",
"ID False\n",
"Price False\n",
"Levy False\n",
"Manufacturer False\n",
"Model False\n",
"ProdYear False\n",
"Category False\n",
"Leather interior False\n",
"Fuel type False\n",
"Engine volume False\n",
"Mileage False\n",
"Cylinders False\n",
"Gear box type False\n",
"Drive wheels False\n",
"Doors False\n",
"Wheel False\n",
"Color False\n",
"Airbags False\n",
"LeatherInterior1 False\n",
"dtype: bool"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Количество пустых значений признаков\n",
"display(car.isnull().sum())\n",
"display()\n",
"\n",
"# Есть ли пустые значения признаков\n",
"display(car.isnull().any())\n",
"display()\n",
"\n",
"# Процент пустых значений признаков\n",
"for i in car.columns:\n",
" null_rate = car[i].isnull().sum() / len(car) * 100\n",
" if null_rate > 0:\n",
" display(f\"{i} процент пустых значений: %{null_rate:.2f}\")"
]
},
{
"cell_type": "code",
2025-01-06 23:37:51 +04:00
"execution_count": 233,
2025-01-06 23:21:44 +04:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"id 0\n",
"date 0\n",
"price 0\n",
"bedrooms 0\n",
"bathrooms 0\n",
"sqft_living 0\n",
"sqft_lot 0\n",
"floors 0\n",
"waterfront 0\n",
"view 0\n",
"condition 0\n",
"grade 0\n",
"sqft_above 0\n",
"sqft_basement 0\n",
"yr_built 0\n",
"yr_renovated 0\n",
"zipcode 0\n",
"lat 0\n",
"long 0\n",
"sqft_living15 0\n",
"sqft_lot15 0\n",
"dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"id False\n",
"date False\n",
"price False\n",
"bedrooms False\n",
"bathrooms False\n",
"sqft_living False\n",
"sqft_lot False\n",
"floors False\n",
"waterfront False\n",
"view False\n",
"condition False\n",
"grade False\n",
"sqft_above False\n",
"sqft_basement False\n",
"yr_built False\n",
"yr_renovated False\n",
"zipcode False\n",
"lat False\n",
"long False\n",
"sqft_living15 False\n",
"sqft_lot15 False\n",
"dtype: bool"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Количество пустых значений признаков\n",
"display(house.isnull().sum())\n",
"display()\n",
"\n",
"# Есть ли пустые значения признаков\n",
"display(house.isnull().any())\n",
"display()\n",
"\n",
"# Процент пустых значений признаков\n",
"for i in house.columns:\n",
" null_rate = house[i].isnull().sum() / len(house) * 100\n",
" if null_rate > 0:\n",
" display(f\"{i} процент пустых значений: %{null_rate:.2f}\")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"В 1 наборе данных phone имеются пустые значения, в остальных они отсутствуют.\n",
"Заполним пустые значения из 1 датасета."
]
},
{
"cell_type": "code",
2025-01-06 23:37:51 +04:00
"execution_count": 234,
2025-01-06 23:21:44 +04:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(805, 18)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"Name_phone False\n",
"Rating False\n",
"Spec_score False\n",
"No_of_sim False\n",
"Ram False\n",
"Battery False\n",
"Display False\n",
"Camera False\n",
"External_Memory False\n",
"Android_version False\n",
"Price False\n",
"company False\n",
"Inbuilt_memory False\n",
"fast_charging False\n",
"Screen_resolution False\n",
"Processor False\n",
"Processor_name False\n",
"Class False\n",
"dtype: bool"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Name_phone</th>\n",
" <th>Rating</th>\n",
" <th>Spec_score</th>\n",
" <th>No_of_sim</th>\n",
" <th>Ram</th>\n",
" <th>Battery</th>\n",
" <th>Display</th>\n",
" <th>Camera</th>\n",
" <th>External_Memory</th>\n",
" <th>Android_version</th>\n",
" <th>Price</th>\n",
" <th>company</th>\n",
" <th>Inbuilt_memory</th>\n",
" <th>fast_charging</th>\n",
" <th>Screen_resolution</th>\n",
" <th>Processor</th>\n",
" <th>Processor_name</th>\n",
" <th>Class</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Id</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1365</th>\n",
" <td>TCL 40R</td>\n",
" <td>4.05</td>\n",
" <td>75</td>\n",
" <td>Dual Sim, 3G, 4G, 5G, VoLTE,</td>\n",
" <td>4 GB RAM</td>\n",
" <td>5000 mAh Battery</td>\n",
" <td>6.6 inches</td>\n",
" <td>50 MP + 2 MP + 2 MP Triple Rear &amp;amp; 8 MP Fro...</td>\n",
" <td>Memory Card (Hybrid)</td>\n",
" <td>12</td>\n",
" <td>18,999</td>\n",
" <td>TCL</td>\n",
" <td>64 GB inbuilt</td>\n",
" <td>15W Fast Charging</td>\n",
" <td>720 x 1612 px</td>\n",
" <td>Octa Core</td>\n",
" <td>Dimensity 700 5G</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1366</th>\n",
" <td>TCL 50 XL NxtPaper 5G</td>\n",
" <td>4.10</td>\n",
" <td>80</td>\n",
" <td>Dual Sim, 3G, 4G, VoLTE,</td>\n",
" <td>8 GB RAM</td>\n",
" <td>5000 mAh Battery</td>\n",
" <td>6.8 inches</td>\n",
" <td>50 MP + 2 MP Dual Rear &amp;amp; 16 MP Front Camera</td>\n",
" <td>Memory Card (Hybrid)</td>\n",
" <td>14</td>\n",
" <td>24,990</td>\n",
" <td>TCL</td>\n",
" <td>128 GB inbuilt</td>\n",
" <td>33W Fast Charging</td>\n",
" <td>1200 x 2400 px</td>\n",
" <td>Octa Core</td>\n",
" <td>Dimensity 7050</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1367</th>\n",
" <td>TCL 50 XE NxtPaper 5G</td>\n",
" <td>4.00</td>\n",
" <td>80</td>\n",
" <td>Dual Sim, 3G, 4G, 5G, VoLTE,</td>\n",
" <td>6 GB RAM</td>\n",
" <td>5000 mAh Battery</td>\n",
" <td>6.6 inches</td>\n",
" <td>50 MP + 2 MP Dual Rear &amp;amp; 16 MP Front Camera</td>\n",
" <td>Memory Card Supported, upto 1 TB</td>\n",
" <td>13</td>\n",
" <td>23,990</td>\n",
" <td>TCL</td>\n",
" <td>256 GB inbuilt</td>\n",
" <td>18W Fast Charging</td>\n",
" <td>720 x 1612 px</td>\n",
" <td>Octa Core</td>\n",
" <td>Dimensity 6080</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1368</th>\n",
" <td>TCL 40 NxtPaper 5G</td>\n",
" <td>4.50</td>\n",
" <td>79</td>\n",
" <td>Dual Sim, 3G, 4G, 5G, VoLTE,</td>\n",
" <td>6 GB RAM</td>\n",
" <td>5000 mAh Battery</td>\n",
" <td>6.6 inches</td>\n",
" <td>50 MP + 2 MP + 2 MP Triple Rear &amp;amp; 8 MP Fro...</td>\n",
" <td>Memory Card Supported, upto 1 TB</td>\n",
" <td>13</td>\n",
" <td>22,499</td>\n",
" <td>TCL</td>\n",
" <td>256 GB inbuilt</td>\n",
" <td>15W Fast Charging</td>\n",
" <td>720 x 1612 px</td>\n",
" <td>Octa Core</td>\n",
" <td>Dimensity 6020</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1369</th>\n",
" <td>TCL Trifold</td>\n",
" <td>4.65</td>\n",
" <td>93</td>\n",
" <td>Dual Sim, 3G, 4G, 5G, VoLTE, Vo5G,</td>\n",
" <td>12 GB RAM</td>\n",
" <td>4600 mAh Battery</td>\n",
" <td>10 inches</td>\n",
" <td>Foldable Display, Dual Display</td>\n",
" <td>50 MP + 48 MP + 8 MP Triple Rear &amp;amp; 32 MP F...</td>\n",
" <td>13</td>\n",
" <td>1,19,990</td>\n",
" <td>TCL</td>\n",
" <td>256 GB inbuilt</td>\n",
" <td>67W Fast Charging</td>\n",
" <td>1916 x 2160 px</td>\n",
" <td>Octa Core</td>\n",
" <td>Snapdragon 8 Gen2</td>\n",
" <td>2</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Name_phone Rating Spec_score \\\n",
"Id \n",
"1365 TCL 40R 4.05 75 \n",
"1366 TCL 50 XL NxtPaper 5G 4.10 80 \n",
"1367 TCL 50 XE NxtPaper 5G 4.00 80 \n",
"1368 TCL 40 NxtPaper 5G 4.50 79 \n",
"1369 TCL Trifold 4.65 93 \n",
"\n",
" No_of_sim Ram Battery \\\n",
"Id \n",
"1365 Dual Sim, 3G, 4G, 5G, VoLTE, 4 GB RAM 5000 mAh Battery \n",
"1366 Dual Sim, 3G, 4G, VoLTE, 8 GB RAM 5000 mAh Battery \n",
"1367 Dual Sim, 3G, 4G, 5G, VoLTE, 6 GB RAM 5000 mAh Battery \n",
"1368 Dual Sim, 3G, 4G, 5G, VoLTE, 6 GB RAM 5000 mAh Battery \n",
"1369 Dual Sim, 3G, 4G, 5G, VoLTE, Vo5G, 12 GB RAM 4600 mAh Battery \n",
"\n",
" Display Camera \\\n",
"Id \n",
"1365 6.6 inches 50 MP + 2 MP + 2 MP Triple Rear &amp; 8 MP Fro... \n",
"1366 6.8 inches 50 MP + 2 MP Dual Rear &amp; 16 MP Front Camera \n",
"1367 6.6 inches 50 MP + 2 MP Dual Rear &amp; 16 MP Front Camera \n",
"1368 6.6 inches 50 MP + 2 MP + 2 MP Triple Rear &amp; 8 MP Fro... \n",
"1369 10 inches Foldable Display, Dual Display \n",
"\n",
" External_Memory Android_version \\\n",
"Id \n",
"1365 Memory Card (Hybrid) 12 \n",
"1366 Memory Card (Hybrid) 14 \n",
"1367 Memory Card Supported, upto 1 TB 13 \n",
"1368 Memory Card Supported, upto 1 TB 13 \n",
"1369 50 MP + 48 MP + 8 MP Triple Rear &amp; 32 MP F... 13 \n",
"\n",
" Price company Inbuilt_memory fast_charging Screen_resolution \\\n",
"Id \n",
"1365 18,999 TCL 64 GB inbuilt 15W Fast Charging 720 x 1612 px \n",
"1366 24,990 TCL 128 GB inbuilt 33W Fast Charging 1200 x 2400 px \n",
"1367 23,990 TCL 256 GB inbuilt 18W Fast Charging 720 x 1612 px \n",
"1368 22,499 TCL 256 GB inbuilt 15W Fast Charging 720 x 1612 px \n",
"1369 1,19,990 TCL 256 GB inbuilt 67W Fast Charging 1916 x 2160 px \n",
"\n",
" Processor Processor_name Class \n",
"Id \n",
"1365 Octa Core Dimensity 700 5G 2 \n",
"1366 Octa Core Dimensity 7050 1 \n",
"1367 Octa Core Dimensity 6080 2 \n",
"1368 Octa Core Dimensity 6020 2 \n",
"1369 Octa Core Snapdragon 8 Gen2 2 "
]
},
2025-01-06 23:37:51 +04:00
"execution_count": 234,
2025-01-06 23:21:44 +04:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Замена пустых данных на моду (часто встречающееся значение)\n",
"mode_Android = phone['Android_version'].mode() \n",
"phone.fillna({'Android_version':mode_Android}, inplace=True)\n",
"\n",
"Inbuilt_memory = phone['Inbuilt_memory'].mode() \n",
"phone.fillna({'Inbuilt_memory':Inbuilt_memory}, inplace=True)\n",
"\n",
"fillna_df = phone.fillna(0)\n",
"\n",
"dropna_df = phone.dropna()\n",
"\n",
"display(dropna_df.shape)\n",
"\n",
"display(fillna_df.isnull().any())\n",
"\n",
"phone.tail()"
]
},
{
"cell_type": "code",
2025-01-06 23:37:51 +04:00
"execution_count": 235,
2025-01-06 23:21:44 +04:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Class\n",
"1 718\n",
"2 636\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Обучающая выборка: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(812, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"Class\n",
"1 431\n",
"2 381\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Контрольная выборка: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(271, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"Class\n",
"1 144\n",
"2 127\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Тестовая выборка: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(271, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"Class\n",
"1 143\n",
"2 128\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Вывод распределения количества наблюдений по меткам (классам)\n",
"from src.utils import split_stratified_into_train_val_test\n",
"\n",
"\n",
"display(phone.Class.value_counts())\n",
"display()\n",
"\n",
"data = phone[[\"Class\", \"Spec_score\", \"Rating\"]].copy()\n",
"\n",
"df_train, df_val, df_test, y_train, y_val, y_test = split_stratified_into_train_val_test(\n",
" data, stratify_colname=\"Class\", frac_train=0.60, frac_val=0.20, frac_test=0.20\n",
")\n",
"\n",
"display(\"Обучающая выборка: \", df_train.shape)\n",
"display(df_train.Class.value_counts())\n",
"\n",
"display(\"Контрольная выборка: \", df_val.shape)\n",
"display(df_val.Class.value_counts())\n",
"\n",
"display(\"Тестовая выборка: \", df_test.shape)\n",
"display(df_test.Class.value_counts())"
]
},
{
"cell_type": "code",
2025-01-06 23:37:51 +04:00
"execution_count": 236,
2025-01-06 23:21:44 +04:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Обучающая выборка: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(812, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"Class\n",
"1 431\n",
"2 381\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Обучающая выборка после oversampling: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
2025-01-06 23:37:51 +04:00
"(856, 3)"
2025-01-06 23:21:44 +04:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"Class\n",
"1 431\n",
2025-01-06 23:37:51 +04:00
"2 425\n",
2025-01-06 23:21:44 +04:00
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Class</th>\n",
" <th>Spec_score</th>\n",
" <th>Rating</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
2025-01-06 23:37:51 +04:00
" <td>1</td>\n",
" <td>89</td>\n",
" <td>4.600000</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
2025-01-06 23:37:51 +04:00
" <td>2</td>\n",
" <td>95</td>\n",
" <td>4.350000</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2</td>\n",
2025-01-06 23:37:51 +04:00
" <td>84</td>\n",
" <td>4.200000</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
2025-01-06 23:37:51 +04:00
" <td>1</td>\n",
" <td>92</td>\n",
" <td>4.100000</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2</td>\n",
2025-01-06 23:37:51 +04:00
" <td>69</td>\n",
" <td>4.150000</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>851</th>\n",
2025-01-06 23:21:44 +04:00
" <td>2</td>\n",
2025-01-06 23:37:51 +04:00
" <td>53</td>\n",
" <td>4.441967</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>852</th>\n",
2025-01-06 23:21:44 +04:00
" <td>2</td>\n",
2025-01-06 23:37:51 +04:00
" <td>56</td>\n",
" <td>4.295098</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>853</th>\n",
2025-01-06 23:21:44 +04:00
" <td>2</td>\n",
2025-01-06 23:37:51 +04:00
" <td>60</td>\n",
" <td>4.489467</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>854</th>\n",
2025-01-06 23:21:44 +04:00
" <td>2</td>\n",
2025-01-06 23:37:51 +04:00
" <td>60</td>\n",
" <td>4.511445</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>855</th>\n",
2025-01-06 23:21:44 +04:00
" <td>2</td>\n",
2025-01-06 23:37:51 +04:00
" <td>72</td>\n",
" <td>4.207826</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" </tbody>\n",
"</table>\n",
2025-01-06 23:37:51 +04:00
"<p>856 rows × 3 columns</p>\n",
2025-01-06 23:21:44 +04:00
"</div>"
],
"text/plain": [
" Class Spec_score Rating\n",
2025-01-06 23:37:51 +04:00
"0 1 89 4.600000\n",
"1 2 95 4.350000\n",
"2 2 84 4.200000\n",
"3 1 92 4.100000\n",
"4 2 69 4.150000\n",
2025-01-06 23:21:44 +04:00
".. ... ... ...\n",
2025-01-06 23:37:51 +04:00
"851 2 53 4.441967\n",
"852 2 56 4.295098\n",
"853 2 60 4.489467\n",
"854 2 60 4.511445\n",
"855 2 72 4.207826\n",
2025-01-06 23:21:44 +04:00
"\n",
2025-01-06 23:37:51 +04:00
"[856 rows x 3 columns]"
2025-01-06 23:21:44 +04:00
]
},
2025-01-06 23:37:51 +04:00
"execution_count": 236,
2025-01-06 23:21:44 +04:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from imblearn.over_sampling import ADASYN\n",
"\n",
"ada = ADASYN()\n",
"\n",
"display(\"Обучающая выборка: \", df_train.shape)\n",
"display(df_train.Class.value_counts())\n",
"\n",
"X_resampled, y_resampled = ada.fit_resample(df_train, df_train[\"Class\"]) # type: ignore\n",
"df_train_adasyn = pd.DataFrame(X_resampled)\n",
"\n",
"display(\"Обучающая выборка после oversampling: \", df_train_adasyn.shape)\n",
"display(df_train_adasyn.Class.value_counts())\n",
"\n",
"df_train_adasyn"
]
},
{
"cell_type": "code",
2025-01-06 23:37:51 +04:00
"execution_count": 237,
2025-01-06 23:21:44 +04:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Обучающая выборка: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(812, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"Class\n",
"1 431\n",
"2 381\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Обучающая выборка после undersampling: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(762, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"Class\n",
"1 381\n",
"2 381\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Spec_score</th>\n",
" <th>Rating</th>\n",
" <th>Class</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Id</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>786</th>\n",
" <td>80</td>\n",
" <td>4.30</td>\n",
2025-01-06 23:21:44 +04:00
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>670</th>\n",
" <td>91</td>\n",
" <td>4.35</td>\n",
2025-01-06 23:21:44 +04:00
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>96</th>\n",
" <td>72</td>\n",
" <td>4.10</td>\n",
2025-01-06 23:21:44 +04:00
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>1207</th>\n",
" <td>79</td>\n",
" <td>4.75</td>\n",
2025-01-06 23:21:44 +04:00
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>1165</th>\n",
2025-01-06 23:21:44 +04:00
" <td>80</td>\n",
2025-01-06 23:37:51 +04:00
" <td>4.60</td>\n",
2025-01-06 23:21:44 +04:00
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>875</th>\n",
" <td>75</td>\n",
" <td>4.25</td>\n",
2025-01-06 23:21:44 +04:00
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>544</th>\n",
" <td>87</td>\n",
" <td>4.65</td>\n",
2025-01-06 23:21:44 +04:00
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>787</th>\n",
" <td>84</td>\n",
" <td>4.15</td>\n",
2025-01-06 23:21:44 +04:00
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>893</th>\n",
" <td>83</td>\n",
2025-01-06 23:21:44 +04:00
" <td>4.00</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>519</th>\n",
" <td>81</td>\n",
" <td>4.30</td>\n",
2025-01-06 23:21:44 +04:00
" <td>2</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>762 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" Spec_score Rating Class\n",
"Id \n",
2025-01-06 23:37:51 +04:00
"786 80 4.30 1\n",
"670 91 4.35 1\n",
"96 72 4.10 1\n",
"1207 79 4.75 1\n",
"1165 80 4.60 1\n",
2025-01-06 23:21:44 +04:00
"... ... ... ...\n",
2025-01-06 23:37:51 +04:00
"875 75 4.25 2\n",
"544 87 4.65 2\n",
"787 84 4.15 2\n",
"893 83 4.00 2\n",
"519 81 4.30 2\n",
2025-01-06 23:21:44 +04:00
"\n",
"[762 rows x 3 columns]"
]
},
2025-01-06 23:37:51 +04:00
"execution_count": 237,
2025-01-06 23:21:44 +04:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from imblearn.under_sampling import RandomUnderSampler\n",
"import pandas as pd\n",
"\n",
"# Создание экземпляра RandomUnderSampler\n",
"rus = RandomUnderSampler()\n",
"\n",
"# Проверка исходной обучающей выборки\n",
"display(\"Обучающая выборка: \", df_train.shape)\n",
"display(df_train.Class.value_counts())\n",
"\n",
"# Выполнение undersampling\n",
"X_resampled, y_resampled = rus.fit_resample(df_train.drop(columns=[\"Class\"]), df_train[\"Class\"]) # type: ignore\n",
"df_train_undersampled = pd.DataFrame(X_resampled)\n",
"\n",
"# Добавление целевой переменной обратно в выборку\n",
"df_train_undersampled[\"Class\"] = y_resampled\n",
"\n",
"# Проверка обучающей выборки после undersampling\n",
"display(\"Обучающая выборка после undersampling: \", df_train_undersampled.shape)\n",
"display(df_train_undersampled.Class.value_counts())\n",
"\n",
"df_train_undersampled\n"
]
},
{
"cell_type": "code",
2025-01-06 23:37:51 +04:00
"execution_count": 238,
2025-01-06 23:21:44 +04:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"LeatherInterior1\n",
"1 13949\n",
"0 5278\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Обучающая выборка: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(11536, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"LeatherInterior1\n",
"1 8369\n",
"0 3167\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Контрольная выборка: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(3845, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"LeatherInterior1\n",
"1 2790\n",
"0 1055\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Тестовая выборка: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(3846, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"LeatherInterior1\n",
"1 2790\n",
"0 1056\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Вывод распределения количества наблюдений по меткам (классам)\n",
"from src.utils import split_stratified_into_train_val_test\n",
"\n",
"\n",
"display(car.LeatherInterior1.value_counts())\n",
"display()\n",
"\n",
"data = car[[\"LeatherInterior1\", \"Airbags\", \"ProdYear\"]].copy()\n",
"\n",
"df_train, df_val, df_test, y_train, y_val, y_test = split_stratified_into_train_val_test(\n",
" data, stratify_colname=\"LeatherInterior1\", frac_train=0.60, frac_val=0.20, frac_test=0.20\n",
")\n",
"\n",
"display(\"Обучающая выборка: \", df_train.shape)\n",
"display(df_train.LeatherInterior1.value_counts())\n",
"\n",
"display(\"Контрольная выборка: \", df_val.shape)\n",
"display(df_val.LeatherInterior1.value_counts())\n",
"\n",
"display(\"Тестовая выборка: \", df_test.shape)\n",
"display(df_test.LeatherInterior1.value_counts())"
]
},
{
"cell_type": "code",
2025-01-06 23:37:51 +04:00
"execution_count": 239,
2025-01-06 23:21:44 +04:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Обучающая выборка: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(11536, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"LeatherInterior1\n",
"1 8369\n",
"0 3167\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Обучающая выборка после oversampling: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
2025-01-06 23:37:51 +04:00
"(16720, 3)"
2025-01-06 23:21:44 +04:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"LeatherInterior1\n",
"1 8369\n",
2025-01-06 23:37:51 +04:00
"0 8351\n",
2025-01-06 23:21:44 +04:00
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>LeatherInterior1</th>\n",
" <th>Airbags</th>\n",
" <th>ProdYear</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
2025-01-06 23:37:51 +04:00
" <td>0</td>\n",
" <td>2</td>\n",
" <td>2003</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0</td>\n",
2025-01-06 23:37:51 +04:00
" <td>0</td>\n",
" <td>2010</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0</td>\n",
2025-01-06 23:37:51 +04:00
" <td>2</td>\n",
" <td>1995</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
2025-01-06 23:37:51 +04:00
" <td>1</td>\n",
" <td>4</td>\n",
2025-01-06 23:21:44 +04:00
" <td>2010</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1</td>\n",
" <td>4</td>\n",
2025-01-06 23:37:51 +04:00
" <td>2015</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>16715</th>\n",
2025-01-06 23:21:44 +04:00
" <td>0</td>\n",
2025-01-06 23:37:51 +04:00
" <td>12</td>\n",
" <td>1999</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>16716</th>\n",
2025-01-06 23:21:44 +04:00
" <td>0</td>\n",
2025-01-06 23:37:51 +04:00
" <td>12</td>\n",
" <td>2000</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>16717</th>\n",
2025-01-06 23:21:44 +04:00
" <td>0</td>\n",
2025-01-06 23:37:51 +04:00
" <td>11</td>\n",
" <td>1998</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>16718</th>\n",
2025-01-06 23:21:44 +04:00
" <td>0</td>\n",
2025-01-06 23:37:51 +04:00
" <td>12</td>\n",
" <td>2000</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>16719</th>\n",
2025-01-06 23:21:44 +04:00
" <td>0</td>\n",
2025-01-06 23:37:51 +04:00
" <td>11</td>\n",
" <td>1998</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" </tbody>\n",
"</table>\n",
2025-01-06 23:37:51 +04:00
"<p>16720 rows × 3 columns</p>\n",
2025-01-06 23:21:44 +04:00
"</div>"
],
"text/plain": [
" LeatherInterior1 Airbags ProdYear\n",
2025-01-06 23:37:51 +04:00
"0 0 2 2003\n",
"1 0 0 2010\n",
"2 0 2 1995\n",
"3 1 4 2010\n",
"4 1 4 2015\n",
2025-01-06 23:21:44 +04:00
"... ... ... ...\n",
2025-01-06 23:37:51 +04:00
"16715 0 12 1999\n",
"16716 0 12 2000\n",
"16717 0 11 1998\n",
"16718 0 12 2000\n",
"16719 0 11 1998\n",
2025-01-06 23:21:44 +04:00
"\n",
2025-01-06 23:37:51 +04:00
"[16720 rows x 3 columns]"
2025-01-06 23:21:44 +04:00
]
},
2025-01-06 23:37:51 +04:00
"execution_count": 239,
2025-01-06 23:21:44 +04:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from imblearn.over_sampling import ADASYN\n",
"\n",
"ada = ADASYN()\n",
"\n",
"display(\"Обучающая выборка: \", df_train.shape)\n",
"display(df_train.LeatherInterior1.value_counts())\n",
"\n",
"X_resampled, y_resampled = ada.fit_resample(df_train, df_train[\"LeatherInterior1\"]) # type: ignore\n",
"df_train_adasyn = pd.DataFrame(X_resampled)\n",
"\n",
"display(\"Обучающая выборка после oversampling: \", df_train_adasyn.shape)\n",
"display(df_train_adasyn.LeatherInterior1.value_counts())\n",
"\n",
"df_train_adasyn"
]
},
{
"cell_type": "code",
2025-01-06 23:37:51 +04:00
"execution_count": 240,
2025-01-06 23:21:44 +04:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Обучающая выборка: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(11536, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"LeatherInterior1\n",
"1 8369\n",
"0 3167\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Обучающая выборка после undersampling: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(6334, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"LeatherInterior1\n",
"0 3167\n",
"1 3167\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Airbags</th>\n",
" <th>ProdYear</th>\n",
" <th>LeatherInterior1</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>1271</th>\n",
" <td>2</td>\n",
" <td>2003</td>\n",
2025-01-06 23:21:44 +04:00
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>9524</th>\n",
" <td>0</td>\n",
" <td>2010</td>\n",
2025-01-06 23:21:44 +04:00
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>9985</th>\n",
" <td>2</td>\n",
" <td>1995</td>\n",
2025-01-06 23:21:44 +04:00
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>12285</th>\n",
" <td>8</td>\n",
" <td>2012</td>\n",
2025-01-06 23:21:44 +04:00
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>14259</th>\n",
" <td>12</td>\n",
" <td>2014</td>\n",
2025-01-06 23:21:44 +04:00
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>1243</th>\n",
" <td>6</td>\n",
" <td>2006</td>\n",
2025-01-06 23:21:44 +04:00
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>10022</th>\n",
" <td>10</td>\n",
" <td>2010</td>\n",
2025-01-06 23:21:44 +04:00
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>18753</th>\n",
" <td>12</td>\n",
" <td>2018</td>\n",
2025-01-06 23:21:44 +04:00
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>14272</th>\n",
2025-01-06 23:21:44 +04:00
" <td>4</td>\n",
2025-01-06 23:37:51 +04:00
" <td>2013</td>\n",
2025-01-06 23:21:44 +04:00
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>16792</th>\n",
2025-01-06 23:21:44 +04:00
" <td>4</td>\n",
2025-01-06 23:37:51 +04:00
" <td>2010</td>\n",
2025-01-06 23:21:44 +04:00
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>6334 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" Airbags ProdYear LeatherInterior1\n",
2025-01-06 23:37:51 +04:00
"1271 2 2003 0\n",
"9524 0 2010 0\n",
"9985 2 1995 0\n",
"12285 8 2012 0\n",
"14259 12 2014 0\n",
2025-01-06 23:21:44 +04:00
"... ... ... ...\n",
2025-01-06 23:37:51 +04:00
"1243 6 2006 1\n",
"10022 10 2010 1\n",
"18753 12 2018 1\n",
"14272 4 2013 1\n",
"16792 4 2010 1\n",
2025-01-06 23:21:44 +04:00
"\n",
"[6334 rows x 3 columns]"
]
},
2025-01-06 23:37:51 +04:00
"execution_count": 240,
2025-01-06 23:21:44 +04:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from imblearn.under_sampling import RandomUnderSampler\n",
"import pandas as pd\n",
"\n",
"# Создание экземпляра RandomUnderSampler\n",
"rus = RandomUnderSampler()\n",
"\n",
"# Проверка исходной обучающей выборки\n",
"display(\"Обучающая выборка: \", df_train.shape)\n",
"display(df_train.LeatherInterior1.value_counts())\n",
"\n",
"# Выполнение undersampling\n",
"X_resampled, y_resampled = rus.fit_resample(df_train.drop(columns=[\"LeatherInterior1\"]), df_train[\"LeatherInterior1\"]) # type: ignore\n",
"df_train_undersampled = pd.DataFrame(X_resampled)\n",
"\n",
"# Добавление целевой переменной обратно в выборку\n",
"df_train_undersampled[\"LeatherInterior1\"] = y_resampled\n",
"\n",
"# Проверка обучающей выборки после undersampling\n",
"display(\"Обучающая выборка после undersampling: \", df_train_undersampled.shape)\n",
"display(df_train_undersampled.LeatherInterior1.value_counts())\n",
"\n",
"df_train_undersampled"
]
},
{
"cell_type": "code",
2025-01-06 23:37:51 +04:00
"execution_count": 241,
2025-01-06 23:21:44 +04:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"bedrooms\n",
"3 1518\n",
"4 1058\n",
"2 404\n",
"5 234\n",
"6 55\n",
"1 30\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Обучающая выборка: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(1979, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"bedrooms\n",
"3 911\n",
"4 635\n",
"2 242\n",
"5 140\n",
"6 33\n",
"1 18\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Контрольная выборка: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(660, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"bedrooms\n",
"3 303\n",
"4 212\n",
"2 81\n",
"5 47\n",
"6 11\n",
"1 6\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Тестовая выборка: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(660, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"bedrooms\n",
"3 304\n",
"4 211\n",
"2 81\n",
"5 47\n",
"6 11\n",
"1 6\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Вывод распределения количества наблюдений по меткам (классам)\n",
"from src.utils import split_stratified_into_train_val_test\n",
"\n",
"\n",
"display(house.bedrooms.value_counts())\n",
"display()\n",
"\n",
"data = house[[\"bedrooms\", \"sqft_living\", \"sqft_lot\"]].copy()\n",
"\n",
"df_train, df_val, df_test, y_train, y_val, y_test = split_stratified_into_train_val_test(\n",
" data, stratify_colname=\"bedrooms\", frac_train=0.60, frac_val=0.20, frac_test=0.20\n",
")\n",
"\n",
"display(\"Обучающая выборка: \", df_train.shape)\n",
"display(df_train.bedrooms.value_counts())\n",
"\n",
"display(\"Контрольная выборка: \", df_val.shape)\n",
"display(df_val.bedrooms.value_counts())\n",
"\n",
"display(\"Тестовая выборка: \", df_test.shape)\n",
"display(df_test.bedrooms.value_counts())"
]
},
{
"cell_type": "code",
2025-01-06 23:37:51 +04:00
"execution_count": 242,
2025-01-06 23:21:44 +04:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Обучающая выборка: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(1979, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"bedrooms\n",
"3 911\n",
"4 635\n",
"2 242\n",
"5 140\n",
"6 33\n",
"1 18\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Обучающая выборка после oversampling: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
2025-01-06 23:37:51 +04:00
"(5332, 3)"
2025-01-06 23:21:44 +04:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"bedrooms\n",
"3 911\n",
2025-01-06 23:37:51 +04:00
"6 907\n",
"1 907\n",
"5 892\n",
"2 887\n",
"4 828\n",
2025-01-06 23:21:44 +04:00
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>bedrooms</th>\n",
" <th>sqft_living</th>\n",
" <th>sqft_lot</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
2025-01-06 23:37:51 +04:00
" <td>2</td>\n",
" <td>620</td>\n",
" <td>4760</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
2025-01-06 23:37:51 +04:00
" <td>2</td>\n",
" <td>1760</td>\n",
" <td>2275</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
2025-01-06 23:37:51 +04:00
" <td>6</td>\n",
" <td>3840</td>\n",
" <td>14040</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4</td>\n",
2025-01-06 23:37:51 +04:00
" <td>2230</td>\n",
" <td>6791</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
2025-01-06 23:37:51 +04:00
" <td>4</td>\n",
" <td>1850</td>\n",
" <td>5040</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>5327</th>\n",
2025-01-06 23:21:44 +04:00
" <td>6</td>\n",
2025-01-06 23:37:51 +04:00
" <td>3272</td>\n",
" <td>5227</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>5328</th>\n",
2025-01-06 23:21:44 +04:00
" <td>6</td>\n",
2025-01-06 23:37:51 +04:00
" <td>3007</td>\n",
" <td>4422</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>5329</th>\n",
2025-01-06 23:21:44 +04:00
" <td>6</td>\n",
2025-01-06 23:37:51 +04:00
" <td>3147</td>\n",
" <td>4818</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>5330</th>\n",
2025-01-06 23:21:44 +04:00
" <td>6</td>\n",
2025-01-06 23:37:51 +04:00
" <td>3021</td>\n",
" <td>4954</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>5331</th>\n",
2025-01-06 23:21:44 +04:00
" <td>6</td>\n",
2025-01-06 23:37:51 +04:00
" <td>3010</td>\n",
" <td>5088</td>\n",
2025-01-06 23:21:44 +04:00
" </tr>\n",
" </tbody>\n",
"</table>\n",
2025-01-06 23:37:51 +04:00
"<p>5332 rows × 3 columns</p>\n",
2025-01-06 23:21:44 +04:00
"</div>"
],
"text/plain": [
" bedrooms sqft_living sqft_lot\n",
2025-01-06 23:37:51 +04:00
"0 2 620 4760\n",
"1 2 1760 2275\n",
"2 6 3840 14040\n",
"3 4 2230 6791\n",
"4 4 1850 5040\n",
2025-01-06 23:21:44 +04:00
"... ... ... ...\n",
2025-01-06 23:37:51 +04:00
"5327 6 3272 5227\n",
"5328 6 3007 4422\n",
"5329 6 3147 4818\n",
"5330 6 3021 4954\n",
"5331 6 3010 5088\n",
2025-01-06 23:21:44 +04:00
"\n",
2025-01-06 23:37:51 +04:00
"[5332 rows x 3 columns]"
2025-01-06 23:21:44 +04:00
]
},
2025-01-06 23:37:51 +04:00
"execution_count": 242,
2025-01-06 23:21:44 +04:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from imblearn.over_sampling import ADASYN\n",
"\n",
"ada = ADASYN()\n",
"\n",
"display(\"Обучающая выборка: \", df_train.shape)\n",
"display(df_train.bedrooms.value_counts())\n",
"\n",
"X_resampled, y_resampled = ada.fit_resample(df_train, df_train[\"bedrooms\"]) # type: ignore\n",
"df_train_adasyn = pd.DataFrame(X_resampled)\n",
"\n",
"display(\"Обучающая выборка после oversampling: \", df_train_adasyn.shape)\n",
"display(df_train_adasyn.bedrooms.value_counts())\n",
"\n",
"df_train_adasyn"
]
},
{
"cell_type": "code",
2025-01-06 23:37:51 +04:00
"execution_count": 243,
2025-01-06 23:21:44 +04:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Обучающая выборка: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(1979, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"bedrooms\n",
"3 911\n",
"4 635\n",
"2 242\n",
"5 140\n",
"6 33\n",
"1 18\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'Обучающая выборка после undersampling: '"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(108, 3)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"bedrooms\n",
"1 18\n",
"2 18\n",
"3 18\n",
"4 18\n",
"5 18\n",
"6 18\n",
"Name: count, dtype: int64"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>sqft_living</th>\n",
" <th>sqft_lot</th>\n",
" <th>bedrooms</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>1729</th>\n",
" <td>680</td>\n",
" <td>1638</td>\n",
2025-01-06 23:21:44 +04:00
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1453</th>\n",
" <td>660</td>\n",
" <td>2600</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>1649</th>\n",
" <td>3000</td>\n",
" <td>204732</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2151</th>\n",
" <td>1010</td>\n",
" <td>5750</td>\n",
2025-01-06 23:21:44 +04:00
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>154</th>\n",
" <td>700</td>\n",
" <td>5100</td>\n",
2025-01-06 23:21:44 +04:00
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>2069</th>\n",
" <td>2410</td>\n",
" <td>6000</td>\n",
2025-01-06 23:21:44 +04:00
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>1192</th>\n",
" <td>2560</td>\n",
" <td>8320</td>\n",
2025-01-06 23:21:44 +04:00
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>2065</th>\n",
" <td>3240</td>\n",
" <td>5750</td>\n",
2025-01-06 23:21:44 +04:00
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>2492</th>\n",
" <td>2400</td>\n",
" <td>9373</td>\n",
2025-01-06 23:21:44 +04:00
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
2025-01-06 23:37:51 +04:00
" <th>232</th>\n",
" <td>2940</td>\n",
" <td>7350</td>\n",
2025-01-06 23:21:44 +04:00
" <td>6</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>108 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" sqft_living sqft_lot bedrooms\n",
2025-01-06 23:37:51 +04:00
"1729 680 1638 1\n",
2025-01-06 23:21:44 +04:00
"1453 660 2600 1\n",
2025-01-06 23:37:51 +04:00
"1649 3000 204732 1\n",
"2151 1010 5750 1\n",
"154 700 5100 1\n",
2025-01-06 23:21:44 +04:00
"... ... ... ...\n",
2025-01-06 23:37:51 +04:00
"2069 2410 6000 6\n",
"1192 2560 8320 6\n",
"2065 3240 5750 6\n",
"2492 2400 9373 6\n",
"232 2940 7350 6\n",
2025-01-06 23:21:44 +04:00
"\n",
"[108 rows x 3 columns]"
]
},
2025-01-06 23:37:51 +04:00
"execution_count": 243,
2025-01-06 23:21:44 +04:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from imblearn.under_sampling import RandomUnderSampler\n",
"import pandas as pd\n",
"\n",
"# Создание экземпляра RandomUnderSampler\n",
"rus = RandomUnderSampler()\n",
"\n",
"# Проверка исходной обучающей выборки\n",
"display(\"Обучающая выборка: \", df_train.shape)\n",
"display(df_train.bedrooms.value_counts())\n",
"\n",
"# Выполнение undersampling\n",
"X_resampled, y_resampled = rus.fit_resample(df_train.drop(columns=[\"bedrooms\"]), df_train[\"bedrooms\"]) # type: ignore\n",
"df_train_undersampled = pd.DataFrame(X_resampled)\n",
"\n",
"# Добавление целевой переменной обратно в выборку\n",
"df_train_undersampled[\"bedrooms\"] = y_resampled\n",
"\n",
"# Проверка обучающей выборки после undersampling\n",
"display(\"Обучающая выборка после undersampling: \", df_train_undersampled.shape)\n",
"display(df_train_undersampled.bedrooms.value_counts())\n",
"\n",
"df_train_undersampled"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"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.5"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}