블로그 이미지
윤영식
Full Stacker, Application Architecter, KnowHow Dispenser and Bike Rider

Publication

Category

Recent Post

2015. 2. 21. 13:23 AI Deep Learning

가격 결정을 위한 모델링은 이질적인 속성을 기반을 둔 숫자 데이터를 예측하는데 최적의 알고리즘이다.




kNN


  - K-nearnest neighbors : k는 마지막 결과를 얻기 위해 평균을 낼 물품의 개수를 말한다. 데이터가 완벽하다면 k=1을 사용한다. 

  - 인접개수의 평균을 낼 때 너무 작거나 크면 안되고 적정개수를 찾아야 한다. 




물품 가중치


  - 거리에 따라 가중치를 둔다. 물품들이 비슷할 수록 그들 간의 거리가 더 가까워진다. 

  - 물품들을 군집화하기 위한 방법 - 적정한 인접 개수를 구하는 것이 필요하다. 

  - 역함수(inverse function), 빼기 함수(substraction function), 가우스 함수(gaussian function)

  - 가중 kNN (Weighted kNN) : 가우시안을 구하고 평균을 구한다 




교차검증


  - 데이터를 학습 세트와 테스트 세트로 나누는 기법들을 총칭한다. (cross validation set) : 표본값을 잘 뽑는 방법

  - training set -> test set 




이질 변수


  - 가격 결정에 너무 큰 영향을 미치는 이질적 요소

  - 변수의 단위가 틀릴때 스케일(Scale)을 조정하여 대입한다. 




실습 


  - $ pip install virtualenvwrapper

 - $ source /usr/local/bin/virtualenvwrapper.sh

 - mkvirtualenv env1

 - vi requirements.txt

// requirements.txt 내역 

beautifulsoup4==4.3.2

html5lib==0.999

lxml==3.4.2

numpy==1.9.1

pandas==0.15.2

python-dateutil==2.4.0

pytz==2014.10

six==1.9.0

wsgiref==0.1.2


  - pip install ipython  (module 없을 경우 계속 pip install <moduleName>)

  - ipython notebook 을 통해서 실습 시작

  - chapter7의 treepredict 데이터 생성 : data.txt

Referrer,Location,Read FAQ,Pages viewed,Service chosen

Slashdot,USA,Yes,18,None

Google,France,Yes,23,Premium

Digg,USA,Yes,24,Basic

Kiwitobes,France,Yes,23,Basic

Google,UK,No,21,Premium

(direct),New Zealand,No,12,None

(direct),UK,No,21,Basic

Google,USA,No,24,Premium

Slashdot,France,Yes,19,None

Digg,USA,No,18,None

Google,UK,No,18,None

Kiwitobes,UK,No,19,None

Digg,New Zealand,Yes,12,Basic

Google,UK,Yes,18,Basic

Kiwitobes,France,Yes,19,Basic


  - treepredict.py 작성 : pandas 통해서 데이터 만듦

import pandas as pd 


def main():

  data = pd.read_csv("./data.txt", sep=",")

  print data

  values = data.values

  print values


if __name__ == '__main__':

  main()


  - pandas로 하면 데이터 유형이 틀려지므로 그냥 책에 있는 내용 copy&paste

  - 실행 내역을 html로 출력

$ ipython nbconvert treepredict.ipynb

[NbConvertApp] Using existing profile dir: u'/Users/nulpulum/.ipython/profile_default'

[NbConvertApp] Converting notebook treepredict.ipynb to html

[NbConvertApp] Support files will be in treepredict_files/

[NbConvertApp] Loaded template full.tpl

[NbConvertApp] Writing 202262 bytes to treepredict.html

(env1)




<참조> 


  - https://virtualenvwrapper.readthedocs.org/en/latest/ : python 가상 환경 

  - https://pypi.python.org/pypi/virtualenv

  - iPython notebook 사용하기 

posted by 윤영식