Data

[Kaggle/EDA]House Prices - Advanced Regression Techniques

박한결 2021. 4. 28. 21:57

[Kaggle]House Prices Competition으로 이동

 

캐글의 입문 문제인 House Prices 데이터로 EDA를 해봤습니다. 

1.   데이터 탐색

 

(1)  데이터 기본 속성

 

-      81개의 변수와 1460개의 관측치로 구성되었습니다.

-      ‘SalePrice’는 종속 변수로 보이며, 단위는 달러로 추정됩니다.

 

 

(2)  결측치

 

[Figure 1]결측치 개수

 

19개의 변수에 결측 값이 있습니다. 대부분의 경우 NA는 Alley, BsmtQual, FireplaceQu와 같이 해당 변수가 존재하지 않음을 의미합니다.

 

 

 

 

변수 이름

내용

타입

결측 개수(%)

Alley

Type of alley access to property

범주형(명목)

1369 (94%)

MasVnrType

Masonry veneer type

범주형(명목)

8(0.5%)

MasVnrArea

Masonry veneer area in square feet

연속형

8(0.5%)

BsmtQual

Evaluates the height of the basement

범주형(순위)

37(3%)

BsmtCond

Evaluates the general condition of the basement

범주형(순위)

37(3%)

BsmtFinType1

Rating of basement finished area

범주형(순위)

37(3%)

BsmtExposure

Refers to walkout or garden level walls

범주형(순위)

38(3%)

BsmtFinType2

Rating of basement finished area (if multiple types)

범주형(순위)

37(3%)

Electrical

Electrical system

범주형(명목)

38(3%)

FireplaceQu

Fireplace quality

범주형(순위)

1(0.06%)

LotFrontage

the horizontal distance between the side lot lines

연속형

259(18%)

GarageType

Garage location

범주형(명목)

81(6%)

GarageYrBlt

Year garage was built

범주형(명목)

GarageFinish

Interior finish of the garage

범주형(명목)

GarageCond

Garage condition

범주형(순서)

GarageQual

Garage quality

범주형(순서)

PoolQC

Pool quality

범주형(순서)

1453(96%)

Fence

Fence quality

범주형(명목)

1179(81%)

MiscFeature

Miscellaneous feature not covered in other categories

범주형(명목)

1406(96%)

[Table 1] 결측치

 

 

2.   변수 분류

 

(1)  수치형(연속성/이산형) 변수

 

변수 이름

내용

타입

결측 개수

이상값(개수)

1stFlrSF

First Floor square feet

연속형

0

4692(1)

BedroomAbvGr

Bedrooms above grade(does not include basement bedrooms)

이산형

0

 

BsmtFinSF1

Type 1 finished square feet

연속형

0

5644(1)

BsmtFullBath

Basement full bathrooms

이산형

0

 

BsmtUnfSF

Unfinished square feet of basement area

연속형

0

 

Fireplaces

Number of fireplaces

연속형

0

 

FullBath

Full bathrooms above grade

이산형

0

 

GarageArea

Size of garage in square feet

연속형

0

 

GarageCars

Size of garage in car capacity

이산형

0

 

GrLivArea

Above grade(ground) living area square feet

연속형

0

5642(1)

HalfBath

Half baths above grade

이산형

0

 

LotArea

Lot size in square feet

연속형

0

100000이상(4)

LotFrontage

Linear feet of street connected to property

연속형

259

313(2)

OpenPorchSF

Open porch area in square feet

연속형

0

500이상(3)

SalePrice

Sale Price

연속형

0

700000이상(2)

TotalBsmtSF

Total square feet of basement area

연속형

0

6110(1)

TotRmsAbvGrd

Total rooms above grade(does not include bathrooms)

이산형

0

 

[Table 2] 수치형 변수

 

[Figure 2]SalePrice  분포

후에 회귀 모델을 사용해서 SalePrice를 예측하기위해서는 정규분포화가 필요해보입니다. 

 

 

(2) 범주형(명목형/순위형) 변수

 

변수 이름

내용

타입

결측 개수

Exterior1st

Exterior covering on house

명목형

0

Exterior2st

Exterior covering on house(if more than one material)

명목형

0

Foundation

Type of foundation

명목형

0

GarageType

Garage location

명목형

81

HouseStyle

Style of dwelling

명목형

0

LotConfig

Lot configuration

명목형

0

LotShape

General shape of property

명목형

0

MasVnrType

Masonry veneer type

명목형

0

MSSubClass

Identifies the type of dwelling involved in the sale

명목형

0

MSZoning

Identifies the general zoning classification tof the sale

명목형

0

Neighborhood

Physical locations within Ames city limits

명목형

0

RoofStyle

Type of roof

명목형

0

BsmtExposure

Refers to walkout or garden level walls

순서형

38

BsmtFinType1

Rating of basement finished area

순서형

37

BsmtQual

Evaluates the height of the basement

순서형

37

ExterCond

Evaluates the present condition of the material on the exterior

순서형

0

ExterQual

Evaluates the present condition of the material on the exterior

순서형

690

FireplaceQu

Fireplace quality

순서형

81

GarageFinish

Interior finish of the garage

순서형

81

GarageYrBlt

Year garage was built

순서형

0

HeatingQC

Heating quality and condition

순서형

0

KitchenQUal

Kitchen quality

순서형

0

MoSold

Month Sold(MM)

순서형

0

OverallCond

Rates the overall condition of the house

순서형

0

OverallQual

Rates the overall material and finish of the house

순서형

0

YearBuilt

Original construction date

순서형

0

YearRemodAdd

Remodel date(same as construction date if no remodeling or additions)

순서형

0

YrSold

Year Sold(YYYY)

순서형

0

[Table 3] 범주형 변수

 

 

(3)  특정 값에 치우친 변수

 

특정한 값에 치우친 변수는 사용하지 않을 가능성이 있기 때문에 별도로 분류하였습니다.

 

변수 이름

내용

타입

결측 개수

치우친값(개수)

이상값(개수)

2ndFlrSF

Second floor square feet

연속형

0

0(829)

 

3SsnPorch

Three season porch area in square feet

연속형

0

0(1436)

 

BldgType

Type of dwelling

명목형

0

1Farm(1220)

 

BsmtCond

Evaluates the general condition of the basement

순위형

37

TA(1311)

 

BsmtFinSF2

Type 2 finished square feet

연속형

0

0(1293)

 

BsmtFinType2

Rating of basement finished area(if multiple types)

순위형

38

Unf(1256)

 

BsmtHalfBath

Basement half bathrooms

이산형

0

0(1378)

 

CentralAir

Central air conditioning

명목형

0

Y(1365)

 

Condition1

Proximity to various conditions

명목형

0

Norm(1260)

 

Condition2

Proximity to various conditions(if more than one if present)

명목형

0

Norm(1445)

 

Electrical

Electrical system

순위형

1

SBrkr(1334)

 

EnclosedPorch

Enclosed porch area in square feet

연속형

0

0(1252)

552(1)

Functional

Home functionality(Assume typical unless deductions are warranted)

명목형

0

Typ(1360)

 

GarageCond

Garage condition

순위형

81

TA(1326)

 

GarageQual

Garage quality

순위형

81

TA(1311)

 

Heating

Type of heating

명목형

0

GasA(1428)

 

KitchenAbvGr

Kitchens above grade

순위형

0

1(1392)

 

LandContour

Flatness of the property

순위형

0

Lvl(1311)

 

LandSlope

Slope of property

순위형

0

Gtl(1382)

 

LowQualFinSF

Low quality finished square feet(all floors)

연속형

0

0(1434)

 

MasVnrArea

Masonry veneer area in square feet

연속형

8

0.0(861)

 

MiscFeature

Miscellaneous feature not covered in other categories

명목형

1406

Shed(49)

 

MiscVal

Value of miscellaneous feature

연속형

0

0(1408)

 

PavedDrive

Paved driveway

명목형

0

P(1340)

 

PoolArea

Pool area in square feet

연속형

0

0(1453)

 

RoofMatl

Roof material

명목형

0

CompShg(1434)

 

SaleCondition

Condition of sale

명목형

0

Normal(1198)

 

SaleType

Type of Sale

명목형

0

WD(1267)

 

ScreenPorch

Screen porch area in square feet

연속형

0

0(1344)

 

Street

Type of road access to property

명목형

0

Pave(1454)

 

Utilities

Type of utilities available

명목형

0

AllPub(1459)

 

Alley

Type of alley access to property

명목형

1369

NA

 

Fence

Fence quality

순위형

1179

NA

 

PoolQC

Pool quality

순위형

1453

NA

 

[Table 4] 특정 값에 치우친 변수

 

 

3.   관찰

 

(1)  수치형 변수

 

[Figure 3]  연속형 변수 피어슨 상관분석 그래프

-      연속형 변수는 대부분 양의 관계를 가지고 있습니다. 연속형 변수에 대해 상관분석을 진행하면, ‘GrLivArea > GarageArea > 1stFlrSF = TotalBsmtSF’ 변수 순으로 ‘SalePrice’에 높은 영향을 준다는 것을 알 수 있습니다.

-      이산형 변수에 대해 상관분석을 진행하면, ‘GarageCars > FullBath > TotRmsAdvGrd’ 변수 순으로 ‘SalePrice’에 많은 영향을 준다는 것을 알 수 있습니다.

 

 

 

[2] 범주형 변수

 

[Figure 4] 월 별 집 판매량

-      ‘MoSold’ 빈도 그래프를 그려 월별 판매량을 확인하면, 5-7월에 집 판매량이 많은 것을 확인할 수 있습니다. 어떤 유형의 집이 많이 팔렸는지, 공통점이 있는지 확인해볼 필요가 있습니다.

 

[Figure 5]  범주형 변수 ‘SalePrice-OverallCond’ 상자 수염 그림

 

-      ‘OverallCond’는 높을 수록 좋은 변수인데, 5점대에 높은 가격대가 형성되어 있습니다. 5점대 집의 특징을 살펴볼 필요가 있습니다.

 

 

4.   데이터 전처리

 

(1)  결측치 처리

 

변수 이름

타입

결측 개수(%)

원인

처리

Alley

범주형(명목)

1369 (94%)

관련 시설이 없음

NA → None

MasVnrType

범주형(명목)

8(0.5%)

응답 누락

NA → 0

MasVnrArea

연속형

8(0.5%)

관련 시설이 없음

NA → None

BsmtQual

범주형(순위)

37(3%)

관련 시설이 없음

NA → None

BsmtCond

범주형(순위)

37(3%)

관련 시설이 없음

NA → None

BsmtFinType1

범주형(순위)

37(3%)

관련 시설이 없음

NA → None

BsmtFinType2

범주형(순위)

37(3%)

관련 시설이 없음

NA → None

Electrical

범주형(명목)

38(3%)

알 수 없음

NA → SBrkr(91%)

FireplaceQu

범주형(순위)

1(0.06%)

관련 시설이 없음

NA → None

LotFrontage

연속형

259(18%)

알 수 없음

사용 제외

GarageType

범주형(명목)

81(6%)

관련 시설이 없음

NA → None

GarageYrBlt

범주형(명목)

관련 시설이 없음

NA → None

GarageFinish

범주형(명목)

관련 시설이 없음

NA → None

GarageCond

범주형(순서)

관련 시설이 없음

NA → None

GarageQual

범주형(순서)

관련 시설이 없음

NA → None

PoolQC

범주형(순서)

1453(96%)

관련 시설이 없음

NA → None

Fence

범주형(명목)

1179(81%)

관련 시설이 없음

NA → None

MiscFeature

범주형(명목)

1406(96%)

관련 시설이 없음

NA → None

[Table 5] 결측치 처리 결과

 

(2)  특정 값에 치우친 변수 제거

 

변수 이름

내용

타입

결측 개수

치우친값(개수)

이상값(개수)

2ndFlrSF

Second floor square feet

연속형

0

0(829)

 

3SsnPorch

Three season porch area in square feet

연속형

0

0(1436)

 

BldgType

Type of dwelling

명목형

0

1Farm(1220)

 

BsmtCond

Evaluates the general condition of the basement

순위형

37

TA(1311)

 

BsmtFinSF2

Type 2 finished square feet

연속형

0

0(1293)

 

BsmtFinType2

Rating of basement finished area(if multiple types)

순위형

38

Unf(1256)

 

BsmtHalfBath

Basement half bathrooms

이산형

0

0(1378)

 

CentralAir

Central air conditioning

명목형

0

Y(1365)

 

Condition1

Proximity to various conditions

명목형

0

Norm(1260)

 

Condition2

Proximity to various conditions(if more than one if present)

명목형

0

Norm(1445)

 

Electrical

Electrical system

순위형

1

SBrkr(1334)

 

EnclosedPorch

Enclosed porch area in square feet

연속형

0

0(1252)

552(1)

Functional

Home functionality(Assume typical unless deductions are warranted)

명목형

0

Typ(1360)

 

GarageCond

Garage condition

순위형

81

TA(1326)

 

GarageQual

Garage quality

순위형

81

TA(1311)

 

Heating

Type of heating

명목형

0

GasA(1428)

 

KitchenAbvGr

Kitchens above grade

순위형

0

1(1392)

 

LandContour

Flatness of the property

순위형

0

Lvl(1311)

 

LandSlope

Slope of property

순위형

0

Gtl(1382)

 

LowQualFinSF

Low quality finished square feet(all floors)

연속형

0

0(1434)

 

MasVnrArea

Masonry veneer area in square feet

연속형

8

0.0(861)

 

MiscFeature

Miscellaneous feature not covered in other categories

명목형

1406

Shed(49)

 

MiscVal

Value of miscellaneous feature

연속형

0

0(1408)

 

PavedDrive

Paved driveway

명목형

0

P(1340)

 

PoolArea

Pool area in square feet

연속형

0

0(1453)

 

RoofMatl

Roof material

명목형

0

CompShg(1434)

 

SaleCondition

Condition of sale

명목형

0

Normal(1198)

 

SaleType

Type of Sale

명목형

0

WD(1267)

 

ScreenPorch

Screen porch area in square feet

연속형

0

0(1344)

 

Street

Type of road access to property

명목형

0

Pave(1454)

 

Utilities

Type of utilities available

명목형

0

AllPub(1459)

 

Alley

Type of alley access to property

명목형

1369

NA

 

Fence

Fence quality

순위형

1179

NA

 

PoolQC

Pool quality

순위형

1453

NA

 

[Table 6] 특정 값에 치우친 변수 제거 결과

 

 

 

(3)  데이터 변환

 

-      아래의 변수들은 수치형 변수인데, 범주형 변수로 되어있어서 변환이 필요합니다.

 

변수 이름

내용

특이 사항

ExterQual

Evaluates the quality of the material on the exterior

 

ExterCond

Evaluates the present condition of the material on the exterior

 

BsmtQual

Evaluates the height of the basement

 

BsmtCond

Evaluates the general condition of the basement

 

BsmtFinType1

Rating of basement finished area

 

BsmtFinType2

Rating of basement finished area (if multiple types)

 

HeatingQC

Heating quality and condition

 

KitchenQual

Kitchen quality

 

FireplaceQual

Fireplace quality

 

GarageFinish

Interior finish of the garage

 

GarageQual

Garage quality

 

GarageCond

Garage condition

 

PoolQC

Pool quality

 

Fence

Fence quality

두 개 변수로 분리 가능

[Table 7] 변환 필요 데이터

 

-      아래의 변수들은 하나로 병합이 가능합니다.

변수 이름

내용

BsmtFullBath

Basement full bathrooms

BsmtHalfBath

Basement half bathrooms

 [Table 7-1] 변환 필요 데이터

 

변수 이름

내용

FullBath

Full bathrooms above grade

HalfBath

Half baths above grade

[Table 7-2] 변환 필요 데이터

 

 

5.   결론

 

[Figure 7]  월 별 집 판매가의 합

 

[Figure 8]  월 별 집 판매량

 

 

3-[2] 관찰에서 [‘MoSold’ 빈도 그래프를 그려 월별 판매량을 확인하면, 5-7월에 집 판매량이 많은 것을 확인할 수 있습니다. 어떤 유형의 집이 많이 팔렸는지, 공통점이 있는지 확인해볼 필요가 있습니다.]라고 했습니다. 확인 결과 5-7월에 판매되는 집에 특별한 공통점이 있지는 않습니다.

 

[Figure 9]  여름 집 판매량

 

 

[Figure 10]  그 외 계절 집 판매량

 

Figure 9와 10을 확인하면, 두 그래프의 모양과 판매 개수가 거의 같다는 것을 알 수 있습니다. 여름과 그 외 계절에 판매되는 집의 가격대는 대부분 유사하나, 여름에 고가의 집이 더 많이 판매됩니다.

여름에 판매되는 집의 개수가 그 외 계절에 판매되는 집의 개수의 합과 유사한 것을 보아, 여름이 시작되는 시기에 주택 구매 시즌도 함께 시작된다는 것을 알 수 있습니다.

매월 판매되는 고가 주택의 평균 가격을 계산하면, 초봄에 급상승했다가 감소하고 여름에 다시 증가합니다. 이는 초봄에 새로 상장되는 주택이 고가이기 때문이라고 추정할 수 있습니다.

 

집의 전반적인 상태를 나타내는 ‘OverallCond’ 변수를 함께 고려해 보았을 때, 일반적으로 여름에는 집의 상태에 비해 높은 가격에 구매하게 됩니다. 일반적으로 겨울에는 여름에 비해 같은 상태의 저택을 저렴하게 구매할 수 있지만, 선택의 폭이 적습니다.