Notice
Recent Posts
Recent Comments
Today
Total
04-28 05:24
Archives
관리 메뉴

Jeongchul Kim

Machine Learning with the tools IPython Notebook SFrame 본문

MachineLearning

Machine Learning with the tools IPython Notebook SFrame

김 정출 2017. 2. 5. 16:34


Machine Learning with the tools IPython Notebook SFrame


출처 : Coursera / Emily Fox & Carlos Guestrin / Machine Learning Specialization / University of Washington



Machine Learning Introduction

Machine Learning with the tools IPython Notebook & GraphLab
Create

Machine Learning with the tools IPython Notebook & GraphLab Create on AWS

Machine Learning with the tools IPython Notebook  Usage



Jupyter 에서 새로운 notebook을 생성합니다.


이름을 Started with SFrames로 변경합니다.


Cell에서 Ctrl+m을 누르고 또 m을 누르면 Markdown으로 변경되는 단축키입니다.


Cell - Markdown

# GraphLab Create


Cell - Code

import graphlab


Cell - Markdown

# Load a data-set


Cell - Code

sf = graphlab.SFrame(‘people-example.csv’)



people을 입력시 Tab을 입력하면 자동완성됩니다.

people-example.csv 파일을 불러옵니다.


Cell - Code

sf


sf를 입력하면 Table의 모습을 확인할 수 있습니다.


Cell - Code

sf.head() # 데이터의 시작 부분을 보여줍니다.


Cell - Code

sf.tail() # 데이터의 마지막 부분을 보여줍니다.


Data-set이 많지 않아 같은 테이블의 값을 보여주고 있습니다.


GraphLab Canvas

어떠한 data-set 구조도 GraphLab-Create에서 이용할 수 있습니다.

sf.show()를 입력하면 Canvas url 주소로 이동합니다. http://localhost:53692/index.html

Canvas는 Visualization으로 Dataset을 시각화합니다.

Summary에서는 4개의 Feature를 확인할 수 있습니다.

Feature를 클릭하면 Histogram을 보여준다.


Cell - Markdown

# GraphLab Canvas


Cell - Code

sf.show()


Cell - Code

graphlab.canvas.set_target(‘ipynb’)

sf[‘age’].show(view=’Categoriacl’)


SFrame Data 검색

Cell - Markdown

# Inspect columns of dataset


Cell - Code

sf[‘Country’]


Cell - Code

sf[‘age’]


Cell - Code

sf[‘age’].mean() # 평균

sf[‘age’].max() # 최대값



SFrame Data-set 새로운 column 만들기

Cell - Markdown

# Create new columns in our SFrame


Cell - Code

sf

sf[‘Full Name’] = sf[‘First Name’] +’ ’+ sf[‘Last Name’]

sf



Cell - Markdown

# Use the apply function to data transformation

Cell - Code

sf[‘Country’]

sf[‘Country’].show()


보시는 바와같이 USA와 United States는 같으나, Value가 달라 다르게 취급하고 있습니다.


새로운 함수를 생성하여 Data-Set을 변형해봅시다. 새로 생성한 함수를 apply() 함수에 넣어 조작합니다.


Cell - Code

def transform_country(country):
   if country == 'USA':
       return 'United States'
   else:
       return country


Cell - Code

sf[‘Country’].apply(transform_country)


Cell - Code

sf[‘Country’] = sf[‘Country’].apply(transform_country)

sf


이상입니다.




Comments