본문 바로가기
Kaggle

Mobile Price Classification

by ornni 2024. 10. 30.
728x90
반응형

파일 정리

(데이터 파일)

- data

- preprocessed_data

- result_data

(코드 파일)

- preprocessing_code

- modeling_code

 

0. import library


1. load data

데이터 불러오기


2. data preprocessing

2-1. data check

 

- 각 변수 의미 확인

'battery_power': total energy a battery can store in one time measured in mAh

'blue': has Bluetooth or not

'clock_speed': speed at which microprocessor executes instructions

'dual_sim': has dual sim support or not

'fc': front camera mega pixels

'four_g': has 4G or not

'int_memory': internal memory in giga bytes

'm_dep': mobile depth in cm

'mobile_wt': weight of mobile phone

'n_cores': number of cores of processor

'pc': primary camera mega pixels

'px_height': pixel resolution height

'px_width': pixel resolution width

'ram': Random Access memory in mega bytes

'sc_h': screen height of mobile in cm

'sc_w': screen height of mobile in cm

'talk_time': longest time that a single battery charge will last when you are

'three_g': has 3G or not

'touch_screen': has touch screen or not

'wifi': has wifi or not

'price_range': (target) 0: low cost, 1: medium cost, 2: high cost, 3: very high cost

 

- 범주형/연속형 변수 정리

beta 정리

범주형 변수: blue, dual_sim, four_g, n_cores, three_g, touch_screen, wifi, price_range

연속형 변수: 제외한 나머지 모두

 

- 데이터 시각화

전체 변수에 대한 히스토그램 작성 후 범주형/연속형 변수 명확히 정리

균형/불균형 데이터 확인

 

input data

 

Q1) m_dep의 경우 0.1, 0.2, ..., 1.0으로 구분되어 범주형 변수?

A1) 스마트폰 두께를 의미하며 본질적으로 연속형 변수이므로 연속형 변수로 구분

 

Q2) three_g 변수의 경우 불균형 데이터, 얼마나? 

A2) 0: 477, 1:1523으로 각각 24%, 76% 차이, 대략 1이 0에 비해 3배 정도 존재

 

target data

 

모두 500개씩 존재하여 균형 데이터임 확인 가능


2-2. data visualization

 

- 이상치 확인

전체 변수에 대해 boxplot 작성

큰 이상치는 없다고 판단

 

- 가설 확인을 위한 시각화

변수끼리 관계 확인

 

hypothesis1) 4G 핸드폰 가격이 더 비싸지 않을까?

three_g, four_g에 따른 price_range 확인

3G, 4G 모두 안되는 경우 가격이 더 싸고 3G, 4G 모두 되는 경우 비쌈

A1) 3G, 4G의 명확한 가격 구분은 되지 않음


hypothesis2) 핸드폰일수록 비쌀수록 배터리가 오래가지 않을까?

battery_power에 따른 price_range 확인

A2) 가격이 비싼 핸드폰일수록 배터리가 오래감


hypothesis3) 핸드폰일수록 비쌀수록 전면 카메라 픽셀이 많지 않을까?

fc 에 따른 price_range 확인

A3) 둘 사이 큰 관계가 존재하지 않음


hypothesis4) CPU가 많을수록 핸드폰일수록 비싸지 않을까?

n_cores에 따른 price_range 확인

A4) 둘 사이 큰 관계가 존재하지 않음


hypothesis5) 가벼울수록 더 핸드폰이 더 비싸지 않을까? (경량화된 핸드폰!)

m_dep에 따른 price_range 확인

A5) 둘 사이 큰 관계가 존재하지 않음


hypothesis6) 터치 스크린이 되는 핸드폰이 더 비싸지 않을까? (아닌건 폴더폰이 아닐까..?)

touch_screen에 따른 price_range 확인

A6) 터치 스크린이 아닌 경우의 핸드폰이 더 비쌈

엥 그럼 이전의  폴더폰이 아니구나...?


...pc, clock_speed, int_memory에 대해서도 진행해 보았지만 핸드폰 가격과 큰 영향을 보이지 않음...


hypothesis7) 스크린 크기에 따른 핸드폰 가격은 어떻게 될까?

sc_w, sc_h에 따른 price_range 확인

A7) 스크린의 크기는 가격에 영향을 크게 미치지 않는 것 같다


hypothesis8) 픽셀 크기에 따른  핸드폰 가격은 어떻게 될까??

px_width, px_height에 따른 price_range 확인

A8) 픽셀 크기는 가격에 영향을 크게 미치지 않는 것 같다


hypothesis9) 배터리 용량 별 ram에 따른  핸드폰 가격은 어떻게 될까??

battery_power, ram에 따른 price_range 확인

A9) 핸드폰 가격과 ram 사이 큰 상관관계가 존재한다!

 

더 명확한 확인을 위해 boxplot을 그려보자!


2-3. defining data

- 범주형/연속형 변수 정리 확정

범주형 변수: blue, dual_sim, four_g, n_cores, three_g, touch_screen, wifi, price_range

연속형 변수: 제외한 나머지 모두


2-4. data preprocessing

 

- 결측치 없음

- 이상치 없음

 

- 범주형 변수 → dummies encoding

- 연속형 변수 → standard encoding

 

~~ 여기까지 진행한 후 preprocessed_train.csv, preprocessed_test로 저장~~

 

- 데이터 분할

train : valid = 7 : 3


3. modeling

 

- logistic regression

    ACCURACY : 0.9616666666666667

    MAE : 0.03833333333333333

    RMSE : 0.19578900207451216

price_range

3    259

2    255

0    254

1    232


- SVC

ACCURACY : 0.9316666666666666

    MAE : 0.06833333333333333

    RMSE : 0.2614064523559687

price_range

3    258

2    252

0    250

1    240


- KNN

    ACCURACY : 0.5966666666666667

    MAE : 0.5966666666666667

    RMSE : 0.5966666666666667

price_range

1    318

0    252

2    246

3    184

 

적절한 k값을 찾기 위해 그래프를 그려보았지만, 적절한 k를 찾기 좋지 않아 보인다....


- TREE

ACCURACY : 0.825

    MAE : 0.175

    RMSE : 0.4183300132670378

price_range
3    260
1    255
2    247
0    238


- RANDOM FOREST
    ACCRACY : 0.8566666666666667
    MAE : 0.14333333333333334
    RMSE : 0.37859388972001823

price_range

3    263

1    255

0    251

2    231


4. Result

 

logistic regression, SVM이 선형 분리 문제에서 특히 좋은 성능을 보인다.

아마 해당 데이터의 경우 선형 분리에 적절한 형태를 갖고 있었던 것 같다.

 

복잡한 비선형 모델(KNN, DT, RF)보다 더 좋은 성능을 보인다.

또한 차원이 높아서 비선형 모델보다 결과가 더 좋을수도 있을 것 같다는 판단이 보였다. 

 

test data에 대해 적용한 후 얼마나 맞췄는지 정확도를 확인할 수는 없었지만, 선형 모델에 적합한 데이터 같다.


링크

https://github.com/ornni/kaggle/tree/main/Mobile%20Price%20Classification

 

kaggle/Mobile Price Classification at main · ornni/kaggle

repository for recording kaggle codes. Contribute to ornni/kaggle development by creating an account on GitHub.

github.com

 

반응형

'Kaggle' 카테고리의 다른 글

Titanic - Machine Learning from Disaster  (0) 2024.06.15
Regression with a Flood Prediction Dataset  (0) 2024.05.25