본문 바로가기

빅데이터

[k-Digital] Modeling Project - 완료!

세번째 프로젝트인 모델링을 시작한지 이틀차,,, 현타가 찾아와 머리를 정리하기 위해 기록을 남깁니다...

주제 :  https://www.kaggle.com/c/zillow-prize-1

 

Zillow Prize: Zillow’s Home Value Prediction (Zestimate) | Kaggle

 

www.kaggle.com

상금이 큰 이유가 있었고, 오늘도 세상을 배웠습니다.....또륵,,ㅠ

(9/9) 아직 갈 길이 멀었다는 생각도 들고, 팀원들에게 도움이 되어주지는 못할 망정 민폐는 안끼치고 싶은데 생각처럼 안 따라주는 내 머리통이 정말 원망스럽다. 그렇다고 포기하기엔 더 큰 민폐이기 때문에 내가 할 수 있는 만큼 노력하는 방법밖에 없지!! 화이탱!!! 으랏차차!!!!!!!

(9/13) 드디어 끝났다아아아아!! 팀원들의 엄청난 캐리 덕분에 프로젝트를 완성할 수 있었다고 생각하고, 솔직히 난 성적이 어떻든 아무래도 상관없는지라 제출해서 너무 기쁘다ㅠㅠㅜ 그들의 노력이 헛되지 않기만을 바라고 나는 이미 이 프로젝트를 통해서 정말 정말 많은 것들을 얻었기에 내 점수를 다빼서라도 팀원들에게 나눠주고싶은 마음뿐이다.

나는 이 프로젝트로 앞으로 해야할 일들과 가야할 방향성을 잡았다. 솔직하게 두렵지 않다면 거짓말이지만 그날 밤 스스로의 부족함에 엉엉울던 기억은 내가 앞으로 걸어나갈 수 있는 원동력이 되어줄 것이라고 믿어 의심치 않는다. 아직 갈길이 멀다 정신차리자!!! 화이탱!!


혹시나 나처럼 영어를 잘하지 못하면서 이 kaggle을 해보시는 분들을 위해 조금이나마 정리해 봅니다...

file : properties_2016.csv (2017.csv도 column은 같음)

parcelid : pk, 구획에 대한 고유한 id -> 미드를 보면 집이 마당을 포함해서 사각형으로 나뉘어져 있는데, 그 토지 구역에 각각 부여되는 고유한 id값이라고 한다. 여기는 숫자로만 이루어져 있기 때문에 '지번'을 말하는 것으로 추측

airconditioningtypeid : 에어컨 종류

더보기

- 1 : Central

- 2 : Chilled Water

- 3 : Evaporative Cooler

- 4 : Geo Thermal

- 5 : None

- 6 : Other

- 7 : Packaged AC Unit

- 8 : Partial

- 9 : Refrigeration

- 10 : Ventilation

- 11 : Wall Unit

- 12 : Window Unit

- 13 : Yes

architecturalstyletypeid : 건축 양식

더보기

- 1 : A-Frame

- 2 : Bungalow

- 3 : Cape Cod

- 4 : Cottage

- 5 : Colonial

- 6 : Custom

- 7 : Contemporary

- 8 : Conventional

- 9 : Dome

- 10 : French Provincial

- 11 : Georgian

- 12 : High Rise

- 13 : Historical

- 14 : Log Cabin/Rustic

- 15 : Mediterranean

- 16 : Modern

- 17 : Mansion

- 18 : English

- 19 : Other

- 20 : Prefab

- 21 : Ranch/Rambler

- 22 : Raised Ranch

- 23 : Spanish

- 24 : Traditional

- 25 : Tudor

- 26 : Unfinished/Under Construction

- 27 : Victorian

basementsqft : 지하실 면적 [sqft]

bathroomcnt : 욕실 개수 (실제, 1/4, 2/4, 3/4 욕실 포함)

bedroomcnt : 침실 개수

buildingqualitytypeid : 건물의 전반적인 상태 평가 (1등급->best; 숫자가 작을수록 상태가 좋음)

buildingclasstypeid : 건물 프레임의 종류

더보기

- 1 : Buildings having fireproofed structural steel frames carrying all wall, floor and roof loads.  Wall, floor and roof structures are built of non-combustible materials.

- 2 :  Buildings having fireproofed reinforced concrete frames carrying all wall floor and roof loads which are all non-combustible.

- 3 : Buildings having exterior walls built of a non-combustible material such as brick, concrete, block or poured concrete. Interior partitions and roof structures are built of combustible materials. Floor may be concrete or wood frame.

- 4 : Buildings having wood or wood and steel frames

- 5 : Specialized buildings that do not fit in any of the above categories

calculatedbathnbr : 욕실 개수 (추산된 견적, 1/4, 2/4, 3/4 욕실 포함)

decktypeid : deck의 종류 (but, 66이라는 알 수 없는 단일숫자로 이루어져 있음;;)

threequarterbathnbr : 3/4 욕실 개수 (세면대, 샤워기, 변기)

finishedfloor1squarefeet : 1층(입구) 생활 면적의 크기 [sqft]

calculatedfinishedsquarefeet : 총 생활 면적 (추산된 견적) [sqft]

finishedsquarefeet6 : base(토대) 미완성 및 완료 영역(면적) [sqft]

finishedsquarefeet12 : 총 생활 면적 (실제) [sqft]

finishedsquarefeet13 : 생활 면적의 둘레 [sqft]

finishedsquarefeet15 : 총 면적 (생활 면적 + 베이스 면적 + ....기타등등 포함) [sqft]

finishedsquarefeet50 : 1층(입구) 생활 면적의 크기 [sqft]

fips : 연방 정보 처리 표준 코드

fireplacecnt : 벽난로 개수

fireplaceflag : 벽난로 여부

fullbathcnt : 풀(4/4) 욕실 개수 (세면대, 샤워기, 욕조, 변기)

garagecarcnt : 총 차고 개수

garagetotalsqft : 총 차고 면적 [sqft]

hashottuborspa : 온수 욕조/스파 여부 (있으면 TRUE)

heatingorsystemtypeid : 난방 시스템 종류

더보기

- 1 : Baseboard

- 2 : Central

- 3 : Coal

- 4 : Convection

- 5 : Electric

- 6 : Forced air

- 7 : Floor/Wall

- 8 : Gas

- 9 : Geo Thermal

- 10 : Gravity

- 11 : Heat Pump

- 12 : Hot Water

- 13 : None

- 14 : Other

- 15 : Oil

- 16 : Partial

- 17 : Propane

- 18 : Radiant

- 19 : Steam

- 20 : Solar

- 21 : Space/Suspended

- 22 : Vent

- 23 : Wood Burning

- 24 : Yes

- 25 : Zone

latitude : 위도 [10e^6]

longitude : 경도 [10e^6]

lotsizesquarefeet : 로트 면적(재산선까지의 마당을 포함한 땅의 총 면적) [sqft]

numberofstories : 층(계단) 수

poolcnt : 수영장의 총 개수

poolsizesum : 총 수영장의 제곱피트거리

pooltypeid10 : 단독 스파/온수 욕조 여부

pooltypeid2 : (온수 욕조/스파가 포함된) 수영장 여부

pooltypeid7 : (온수 욕조가 포함되지 않은) 수영장 여부

propertycountylandusecode : 주(연방) 토지이용 코드

propertylandusetypeid : 토지이용의 종류

더보기

- 31 : Commercial/Office/Residential Mixed Used

- 46 : Multi-Story Store

- 47 : Store/Office (Mixed Use)

- 246 : Duplex (2 Units, Any Combination)

- 247 : Triplex (3 Units, Any Combination)

- 248 : Quadruplex (4 Units, Any Combination)

- 260 : Residential General

- 261 : Single Family Residential

- 262 : Rural Residence

- 263 : Mobile Home

- 264 : Townhouse

- 265 : Cluster Home

- 266 : Condominium

- 267 : Cooperative

- 268 : Row House

- 269 : Planned Unit Development

- 270 : Residential Common Area

- 271 : Timeshare

- 273 : Bungalow

- 274 : Zero Lot Line

- 275 : Manufactured, Modular, Prefabricated Homes

- 276 : Patio Home

- 279 : Inferred Single Family Residential

- 290 : Vacant Land - General

- 291 : Residential Vacant Land

propertyzoningdesc : 허가된 토지이용계획에 대한 설명(코드)

rawcensustractandblock : (원시) 인구조사와 블록 번호

censustractandblock : 인구조사와 블록(가장 작은 지리 조사 단위) 번호

regionidcounty : 주(연방) 번호

regionidcity : (도시에 있는 경우) 시 번호

regionidzip : 우편 번호

regionidneighborhood : 근린 지역 번호 (주변 환경과 연관된 feature인 것 같음)

roomcnt : 총 방의 개수

storytypeid : 다층의 유형(종류)

더보기

- 1 : Attic & Basement

- 2 : Attic

- 3 : Bi-Level with Attic & Basement

- 4 : Bi-Level

- 5 : Bi-Level with Attic

- 6 : Bi-Level with Basement

- 7 : Basement

- 8 : Split Entry with Attic & Basement

- 9 : Split Foyer with Attic & Basement

- 10 : Level with Attic & Basement

- 11 : Level with Attic

- 12 : Level with Basement

- 13 : Level

- 14 : Multi-Level with Attic & Basement

- 15 : Multi-Level

- 16 : Multi-Level with Attic

- 17 : Multi-Level with Basement

- 18 : Split Level with Attic & Basement

- 19 : Single Level with Attic & Basement

- 20 : Split Entry with Attic

- 21 : Split Entry with Basement

- 22 : Split Foyer with Attic

- 23 : Split Foyer with Basement

- 24 : Single Level with Attic

- 25 : Single Level with Basement

- 26 : Single Level

- 27 : Split Level with Attic

- 28 : Split Level with Basement

- 29 : Split Entry

- 30 : Split Foyer

- 31 : Split Level

- 32 : Tri-level with Attic & Basement

- 33 : Tri-level with Attic

- 34 : Tri-level with Basement

- 35 : Tri-level

typeconstructiontypeid : 건축 재료의 종류

더보기

- 1 : Adobe

- 2 : Brick

- 3 : Concrete Block

- 4 : Concrete

- 5 : Dome

- 6 : Frame

- 7 : Heavy

- 8 : Log

- 9 : Light

- 10 : Metal

- 11 : Manufactured

- 12 : Mixed

- 13 : Masonry

- 14 : Other

- 15 : Steel

- 16 : Stone

- 17 : Tilt-Up

- 18 : Wood

unitcnt : 주택 단위 수 (ex. duplex = 한 토지내에 2가구가 살고 있다는 뜻)

yardbuildingsqft17 : 마당의 patio(테라스) 면적 [sqft]

yardbuildingsqft26 : 마당의 저장소 면적 [sqft]

yearbuilt : 주 거주지의 건축 연도

taxvaluedollarcnt : 총 세금 평가값 [dollar]

structuretaxvaluedollarcnt : 건축물에 대한 세금 [dollar]

landtaxvaluedollarcnt : 대지 면적에 대한 세금 [dollar]

taxamount : 재산세 (부동산에 대한 세금) [dollar]

assessmentyear : 재산세 평가 연도 (일반적인 경우엔 매년 시행함)

taxdelinquencyflag : 재산세 연체 여부 (2015년 기준)

taxdelinquencyyear : 재산세 연체 연도


컬럼명이 마음에 안든다면 변환해서 사용하세요 :) (순서대로가 아니니 적당히 알아서 대입하시길...)

names = ['parcelid', 'air_conditioning_type', 'architectural_style', 
         'area_basement', 'num_bathroom', 'num_bedroom', 'framing_type',
         'building_quality', 'num_bathroom_calc', 'deck_type',
         'area_firstfloor_finished', 'area_total_calc',
         'area_living_finished', 'perimeter_living',
         'area_total', 'area_firstfloor_unfinished',
         'area_base', 'fips', 'num_fireplace', 'num_fullbath',
         'num_garagecar', 'area_garage', 'hashottuborspa',
         'heating_type', 'latitude', 'longitude',
         'area_lot', 'num_pool', 'area_pools', 'pooltypeid10',
         'pooltypeid2', 'pooltypeid7', 'property_land_use_code',
         'property_land_use_type', 'property_zoning_desc',
         'census_raw_tract_block', 'region_city', 'region_county',
         'region_neighborhood', 'region_zipcode', 'num_room', 'story_type',
         'num_34_bath', 'material_type', 'num_unit',
         'area_patio', 'area_shed', 'build_year',
         'num_stories', 'flag_fireplace', 'tax_assessed_structure_value',
         'tax_assessed_parcel_value', 'tax_assessment_year', 'tax_assessed_land_value',
         'tax_property', 'tax_delinquency_flag', 'tax_delinquency_year',
         'census_tract_block']

 

<새로운 feature값 계산식>

실면적과 추산면적 오차 = finishedsquarefeet12 - calculatedfinishedsquarefeet

욕실 개수 오차 = bathroomcnt - calculatedbathnbr

quarter, half bathroom 개수(거의 손님용이라고 합니다) = bathroomcnt - (fullbathcnt + threequarterbathnbr) 

건축된지 몇 년이내 인가 = 해당 년도 - yearbuilt

extra tax = taxvaluedollarcnt - (structuretaxvaluedollarcnt + landtaxvaluedollarcnt + taxamount)

한 가구당 세금 = extra tax / unitcnt (다가구일 경우에만 'unitcnt=1')

총 지상 건물 면적 = finishedsquarefeet15(총 건물면적) - basementsqft(지하실면적)

소유지에서 건물이 차지하는 비율 = 총 지상 건물 면적 / lotsizesquarefeet(땅의 총면적) * 100

수영장 1개의 면적 = poolsizesum / poolcnt

1층제외 위층의 생활 면적 = (finishedsquarefeet12 - finishedfloor1squarefeet) / (numberofstories - 1)

extra_room = roomcnt - (bedroomcnt + bathroomcnt)

 


 

Regression Model

Evaluation : MAE

회귀 모형의 성능 지표 : MAE, MSE, RMSE, MAPE, MPE, MSLE, MSPE, MSAE, R-Square(결정계수), adjusted R-Square, AIC, F-value, P-value

참고 : https://mizykk.tistory.com/102

 

[Python] 성능 측정 지표 :: MAE, MSE, RMSE, MAPE, MPE, MSLE

1. MAE (Mean Absolute Error) - 실제 값과 예측 값의 차이(Error)를 절대값으로 변환해 평균화 - MAE는 에러에 절대값을 취하기 때문에 에러의 크기 그대로 반영된다. 그러므로 예측 결과물의 에러가 10이

mizykk.tistory.com

 

하이퍼 파라미터 변경하기 -> GridSearchCV 사용

<GridSearchCV 클래스의 생성자>

- estimator : classifier, regressor, pipeline 등 가능

- param_grid : 튜닝을 위해 파라미터, 사용될 파라미터를 dictionary 형태로 만들어서 넣는다.

- scoring : 예측 성능을 측정할 평가 방법을 넣는다. 보통 accuracy 로 지정하여서 정확도로 성능 평가를 한다.

- cv : 교차 검증에서 몇개로 분할되는지 지정한다.

- refit : True가 디폴트로 True로 하면 최적의 하이퍼 파라미터를 찾아서 재학습 시킨다.

 

모델별 파라미터(+매개변수) 조사

1. Linear Regression

별다른 파라미터가 존재하지 않는다. (model 복잡도를 제어할 수 없다)

- n_jobs : 기본값은 한 개의 코어만을 사용하며 -1로 지정하면 가용한 모든 코어를 사용. 복수개의 타깃을 가진 경우 1이상으로 설정하여 시스템의 CPU 코어를 최대한으로 활용할 수 있는 파라미터.

2. Decision Tree

 

 

 

 

 

 

 

 

 

일단 완성된 우리팀의 노트북을 첨부합니당 헤헿 자랑스럽다 

https://www.kaggle.com/asolim/yut-zillow-project-notebook

 

YUT_zillow project_notebook

Explore and run machine learning code with Kaggle Notebooks | Using data from multiple data sources

www.kaggle.com