pred_analytics/Lab4.ipynb
2025-01-13 14:42:39 +04:00

44 KiB
Raw Blame History

In [3]:
import pandas as pd

from sklearn import set_config

set_config(transform_output="pandas")

random_state=9

data_car = pd.read_csv('car_price_prediction.csv', index_col="ID")

data_car
Out[3]:
Price Levy Manufacturer Model Prod. year Category Leather interior Fuel type Engine volume Mileage Cylinders Gear box type Drive wheels Doors Wheel Color Airbags
ID
45654403 13328 1399 LEXUS RX 450 2010 Jeep Yes Hybrid 3.5 186005 km 6.0 Automatic 4x4 04-May Left wheel Silver 12
44731507 16621 1018 CHEVROLET Equinox 2011 Jeep No Petrol 3 192000 km 6.0 Tiptronic 4x4 04-May Left wheel Black 8
45774419 8467 - HONDA FIT 2006 Hatchback No Petrol 1.3 200000 km 4.0 Variator Front 04-May Right-hand drive Black 2
45769185 3607 862 FORD Escape 2011 Jeep Yes Hybrid 2.5 168966 km 4.0 Automatic 4x4 04-May Left wheel White 0
45809263 11726 446 HONDA FIT 2014 Hatchback Yes Petrol 1.3 91901 km 4.0 Automatic Front 04-May Left wheel Silver 4
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
45798355 8467 - MERCEDES-BENZ CLK 200 1999 Coupe Yes CNG 2.0 Turbo 300000 km 4.0 Manual Rear 02-Mar Left wheel Silver 5
45778856 15681 831 HYUNDAI Sonata 2011 Sedan Yes Petrol 2.4 161600 km 4.0 Tiptronic Front 04-May Left wheel Red 8
45804997 26108 836 HYUNDAI Tucson 2010 Jeep Yes Diesel 2 116365 km 4.0 Automatic Front 04-May Left wheel Grey 4
45793526 5331 1288 CHEVROLET Captiva 2007 Jeep Yes Diesel 2 51258 km 4.0 Automatic Front 04-May Left wheel Black 4
45813273 470 753 HYUNDAI Sonata 2012 Sedan Yes Hybrid 2.4 186923 km 4.0 Automatic Front 04-May Left wheel White 12

19237 rows × 17 columns

In [5]:
from src.utils import split_stratified_into_train_val_test

X_train, X_val, X_test, y_train, y_val, y_test = split_stratified_into_train_val_test(
    data_car,
    stratify_colname="Airbags",
    frac_train=0.80,
    frac_val=0,
    frac_test=0.20,
    random_state=random_state,
)

display("X_train", X_train)
display("y_train", y_train)

display("X_test", X_test)
display("y_test", y_test)
'X_train'
Price Levy Manufacturer Model Prod. year Category Leather interior Fuel type Engine volume Mileage Cylinders Gear box type Drive wheels Doors Wheel Color Airbags
ID
45788006 17249 - TOYOTA Prius 2014 Sedan No Hybrid 1.8 80000 km 4.0 Automatic Front 04-May Left wheel Black 8
45809459 15988 502 TOYOTA Aqua 2013 Universal Yes Hybrid 1.5 44545 km 4.0 Automatic Front 04-May Left wheel Grey 4
40784381 25089 880 NISSAN Kicks 2018 Jeep No Petrol 1.6 4363 km 4.0 Automatic Front 04-May Left wheel Grey 0
45621750 941 1053 MERCEDES-BENZ E 350 2014 Sedan Yes Diesel 3.5 184467 km 6.0 Automatic Rear 04-May Left wheel White 12
45794605 7213 - TOYOTA Vitz 2005 Hatchback No Petrol 1 0 km 3.0 Automatic Front 04-May Right-hand drive Silver 4
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
45209376 19601 690 FORD Escape 2016 Jeep Yes Petrol 1.5 Turbo 108295 km 4.0 Automatic Front 04-May Left wheel Black 10
45810135 11848 790 CHEVROLET Lacetti 2009 Sedan Yes Petrol 1.6 87250 km 4.0 Automatic Front 04-May Left wheel Grey 4
45801699 1500 - DODGE Durango 2001 Jeep No Petrol 4.7 0 km 8.0 Automatic 4x4 04-May Left wheel Black 7
45788660 35 - TOYOTA Mark X Zio 2005 Sedan Yes Petrol 1.5 50000 km 4.0 Automatic Front 04-May Left wheel White 4
45743014 13485 1018 BMW 328 Xdrive 2011 Sedan Yes Petrol 3 120000 km 6.0 Tiptronic 4x4 04-May Left wheel Black 12

15389 rows × 17 columns

'y_train'
Airbags
ID
45788006 8
45809459 4
40784381 0
45621750 12
45794605 4
... ...
45209376 10
45810135 4
45801699 7
45788660 4
45743014 12

15389 rows × 1 columns

'X_test'
Price Levy Manufacturer Model Prod. year Category Leather interior Fuel type Engine volume Mileage Cylinders Gear box type Drive wheels Doors Wheel Color Airbags
ID
45809681 59834 690 HONDA Civic 2016 Sedan Yes Petrol 1.5 3785 km 4.0 Automatic Front 04-May Left wheel Grey 4
43797018 167781 1292 LAND ROVER Range Rover 2016 Jeep Yes Diesel 3.0 Turbo 81000 km 6.0 Tiptronic 4x4 04-May Left wheel Grey 12
45651960 7997 1850 LEXUS RX 400 2008 Jeep Yes Hybrid 3.5 244731 km 6.0 Automatic Front 04-May Left wheel Black 12
45797083 15289 836 HYUNDAI Genesis 2010 Coupe Yes Petrol 2 115363 km 4.0 Automatic Front 04-May Left wheel Red 4
45765586 627 836 TOYOTA Tacoma 2012 Sedan Yes Petrol 2.7 394069 km 4.0 Automatic Rear 04-May Left wheel Black 12
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
45644398 392 781 TOYOTA Camry 2012 Sedan Yes Hybrid 2.5 314373 km 4.0 Automatic Front 04-May Left wheel Grey 12
45816463 17249 - FORD Transit 1996 Goods wagon No Diesel 2.5 Turbo 230000 km 4.0 Manual Rear 02-Mar Left wheel White 2
45619877 24500 919 BMW X5 2012 Jeep Yes Petrol 3.0 Turbo 1000 km 6.0 Automatic 4x4 04-May Left wheel White 12
45641164 7213 530 NISSAN Juke 2013 Jeep Yes Petrol 1.6 312118 km 4.0 Automatic Front 04-May Left wheel Black 0
45788400 24462 - MERCEDES-BENZ E 350 2008 Sedan Yes Petrol 3.5 142000 km 6.0 Tiptronic 4x4 04-May Left wheel White 12

3848 rows × 17 columns

'y_test'
Airbags
ID
45809681 4
43797018 12
45651960 12
45797083 4
45765586 12
... ...
45644398 12
45816463 2
45619877 12
45641164 0
45788400 12

3848 rows × 1 columns