1 / 67

2012. 6.

 LCBEx (Low Cost But Excellent) 분석 플랫폼으로의 R 의 활용. 2012. 6. 김 준 기 The leading expert in R jkkim@begas.co.kr. R 관련 기사. New York Times: Data Analysts Captivated by R’s Power 6 Jan 2009.

joel-lloyd
Download Presentation

2012. 6.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1.  LCBEx (Low Cost But Excellent) 분석 플랫폼으로의 R의 활용 2012. 6. 김 준 기 The leading expert in R jkkim@begas.co.kr

  2. R 관련 기사 New York Times: Data Analysts Captivated by R’s Power 6 Jan 2009 To some people R is just the 18th letter of the alphabet. R is also the name of a popular programming language used by a growing number of data analysts inside corporations and academia. Companies as diverse as Google, Pfizer, Merck, Bank of America, the InterContinental Hotels Group and Shell use it. The popularity of R at universities could threaten SAS Institute, the privately held business software company that specializes in data analysis software.

  3. R에 대한 관심의 증가 • 폭발적인 사용자 증가와 개발자의 확산으로, 대학교육의 표준 툴로 자리 잡음 ☞ Revolution Analytics 소개자료(소스 : http://r4stats.com/articles/popularity/)

  4. 기업체에서의 R의 활용 • 빅 데이터 기업의 분석 플랫폼 엔진으로 사용 중이며, 유수기업에서 데이터 분석 tool로 사용 중임

  5. 기업체에서의 R의 활용 • 특히, Google과 Facebook은 R을 자사의 주된 분석 플랫폼으로 활용하고 있음 Google's R Style Guide Google uses R for data exploration and model prototyping, it is not typically used in production: in Bo’s group, R is typically run in a desktop environment. - Bo Cowgill, Google Itamar conveyed how Facebook’s Data Team used R in 2007 to answer two questions about new users: (i) which data points predict whether a user will stay? and (ii) if they stay, which data points predict how active they’ll be after three months? - Itamar Rosenn, Facebook http://www.dataspora.com/2009/02/predictive-analytics-using-r/

  6. 소프트웨어 Vendor의 R 적용 • Oracle, IBM의 Netezza, SAP의 HANA, Teradata 등에서 in-memory 혹은 in-database 분석 엔진으로 R을 적용함

  7. 통계 소프트웨어 Vendor의 R 적용 • SAS나 SPSS 등의 통계 소프트웨어에서 R과의 연동을 통해 새로운 분석 방법을 제공 SAS/JMP

  8. Big Data 분석을 위한 R의 활용 • 빅 데이터 분석을 위한 아키텍처 전반에 걸쳐 공통적인 분석 플랫폼으로 자리잡음 Hadoop File Based In-database

  9. R / Hadoop • 특히 국내외 Big Data 분석에 관심이 많은 기업체에서 Hadoop 기반의 R 분석 기능 구현을 위하여 기술 확보에 노력하고 있음 ☞ Revolution Analytics 소개자료

  10. R / Hadoop (Word Count Example) ☞ Revolution Analytics 소개자료

  11. 웹 분석시스템 구현 • 엔터프라이즈 환경의 분석 플랫폼으로 이용 Data Sources & Creation of Analytics Consumption of Analytics & Results Data Analysis Business Intelligence DeployR R / Statistical Modeling Expert DeploymentExpert Interactive Web Apps Cloud / SaaS ☞ Revolution Analytics 소개자료

  12. History of R ☞ 유충현 (넥스알, 빅데이터 애널리틱스 인사이드 2011) • R은 1993년 뉴질랜드 오클랜드대학의 통계학과 교수 2명(Ross Ihaka, Robert Gentleman)에 의하여 개발 • 1976년 Bell Lab의 John Chambers, Rick Becker, Allan Wilks에 의하여 개발된 S Language에 그 뿌리를 두고 있음

  13. 왜 이름이 R일까? • 두 명의 저자(Robert Gentleman과 Ross Ihaka) 이름 맨 앞 철자 • 1976년 Bell Lab에서 개발된 ‘S’ 언어의 이름에서

  14. R 이란 I R is a language and environment for statistical computing and graphics. • 통계분석과 그래픽 작성을 위한 프로그래밍 언어 • 통계학자에 의한, 그리고 통계학자를 위한 • 분석 소프트웨어 • 데이터 입출력, 데이터 처리, 데이터 분석, 그래프 작성 등을 위한 수많은 알고리즘 및 방법론 제공

  15. R 이란 II R is available as Free Software under the terms of the Free Software Foundation's GNU General Public License in source code form. • “GNU”라는 이름은 “GNU's Not Unix!”라는 문장의 재귀적 약어 • GNU는 자유 소프트웨어를 뜻함 • 프로그램을 어떠한 목적으로도 실행할 수 있는 자유 • 자신의 필요에 맞게 개작할 수 있는 자유 • 복제물을 재배포할 수 있는 자유 • 프로그램을 개선시킬 수 있는 자유와 개선된 이점을 공동체 전체가 누릴 수 있게 그것을 발표할 자유

  16. R 이란 III R is Free. • 사용자의 입장에서 Free 라는 것이 단지 무료임을 뜻하는 것은 아님 • 언제 어디서든 다운로드 및 설치가 가능 • Windows, Linux, Unix, Mac 등 다양한 운영체제에서 동작 • 누구나 패키지를 만들어 다른 사람과 공유 가능 • Java, Python, .Net, Visual Studio 등 다양한 개발 언어 및 플랫폼과 연동

  17. R의 특징 • In-Memory Computing • 빠른 처리 속도, H/W 메모리 크기에 영향을 받음 • Object-oriented programming • 데이터, 함수가 object로 관리되어 짐 • 클래스(class)& 메소드(method) • Package • 최신의 알고리즘 및 방법론을 적용 • 다양한 함수 및 데이터 내장, Help의 Examples 바로 사용 가능

  18. The R Foundation (http://www.r-project.org) • R Development Core Team 멤버들에 의하여 설립된 비영리 단체 • R의 배포와 수정은 R Development Core Team과 많은 기여자들에 의하여 이루어 지고 있음

  19. CRAN (The Comprehensive R Archive Network) http://cran.r-project.org/ Korea : http://cran.nexr.com/ • R은 CRAN Site를 통하여 자유롭게 다운로드 받아 설치할 수 있음 • 현재 39개국 87개 Mirror 사이트 운영 중

  20. R Package (http://cran.r-project.org/web/packages/) R 패키지 수 • CRAN Site에 3,868개 등록됨 (2012년 6월 11일 기준) • 이러한 패키지들은 새로운 통계분석 알고리즘이나 새로운 IT 기술의 응용에 관한 것을 포함 • Software Vendor에 의하여 Version Up이 되지 않는다는 것이 다른 통계분석 소프트웨어와의 차이임

  21. R Manual (http://cran.r-project.org/manuals.html) • R과 관련된 매뉴얼을 HTML 및 PDF 파일로 지원 (An Introduction to R, R Data Import/Export 등)

  22. RGUI • RGui 실행 기본 화면은 메뉴, 단축아이콘, 콘솔 창으로 구성 ① 메뉴 ② 툴바 R Console ③

  23. RGUI (메뉴) • 메뉴는 파일, 편집, 보기, 기타, 패키지, 윈도우즈, 도움말로 구성 ① 도움말 패키지 파일 편집 기타

  24. RGui (R Console) • 입력된 명령(command)에 대한 결과가 interactive하게 화면에 출력 R Console에 입력된 R command > getwd() > search() > searchpaths() > ls 오브젝트 리스트를 문자열로 보여주는 함수 > ls() ls 함수를 실행 > ls(pos=6) posargument 값으로 6을 입력하여 ls 함수를 실행

  25. RGui (도움말) • R Console에 help 명령어와 오브젝트이름을 입력 R Console에 입력된 R command > ls ls 함수 코드 > args(ls) ls 함수의 arguments 정보 > help(ls) ls 함수의 도움말 정보(html 형식) ls 함수의 도움말 정보가 웹 브라우저에 표시

  26. R을 배워 업무에 적용하려면 Or is it?

  27. R을 배우는데 도움이 될 만한 곳 • http://www.r-project.org • http://www.r-project.kr (한국 R 사용자 모임 - KRUG) • http://www.r-bloggers.com • http://stackoverflow.com • http://stats.stackexchange.com • http://www.inside-r.org/ • http://www.r-statistics.com/

  28. R GUI Projects “The 95% of statistical software users do not know how to write a script in command-line.” ☞ 신종화(서울과학종합대학원대학교, Korea R User Conference 2011)

  29. R Studio (http://www.rstudio.org/)

  30. Red-R (http://www.red-r.org/)

  31. Red-R

  32. Rattle (http://rattle.togaware.com/), (install.packages("rattle"))

  33. Rattle (library(rattle); rattle())

  34. RExcel (http://rcom.univie.ac.at/)

  35. RExcel

  36. R Commander (install.packages("Rcmdr"))

  37. R Commander (library(Rcmdr))

  38. 기업체에서 주로 사용하는 R Package • RODBC • sqldf • ggplot2 • RgoogleMaps • googleVis • animation

  39. RODBC 패키지 • DBMS와의 인터페이스를 위한 패키지 Oracle, DB2, SQL Server, MySQL 등 다양한 DBMS와 인터페이스가 가능

  40. RODBC 패키지 내 오브젝트 • DBMS와의 인터페이스를 위한 패키지 RODBC 패키지 내 주요 오브젝트

  41. sqldf 패키지 • R 데이터에 대하여 SQL 문을 사용하여 데이터 Manipulation이 가능 # SQL 사용 : Inner Join # merge(import_emp_tb_data, import_dept_tb_data, by = c("DEPTNO")) sqldf("select a.*, b.DNAME, LOC from import_emp_tb_data a, import_dept_tb_data b where a.DEPTNO = b.DEPTNO") # SQL 사용 : Left Join # merge(import_emp_tb_data, import_dept_tb_data, by = c("DEPTNO"), all.x = T) sqldf("select a.*, b.DNAME, LOC from import_emp_tb_data a left join import_dept_tb_data b using(DEPTNO)")

  42. ggplot2 패키지 • 보다 화려하고 유연하고 동적인 그래프 생성이 가능

  43. ggplot2 패키지 qplot(x = hp, y = mpg, data = mtcars, color = cyl, facets = .~ gear) qplot(x = hp, y = mpg, data = mtcars, color = cyl, facets = .~ gear, label = rownames(mtcars), geom=c("text","point"), size = .1, hjust=-0.25)

  44. RgoogleMaps 패키지 • 구글 지도 상에 다양한 정보를 표출 고속도로 영업소 위치 표출 # 패키지 로딩... library(RgoogleMaps) # 데이터 읽어들이기 tollgate_info <- read.csv("영업소정보.csv") # 지도 중심 위치 설정 map.center.loc <- c(36, 128) # 지도 레벨 input.zoom <- 7 map_data <- tollgate_info # 고속도로 영업소 표시 win.graph() mymap <- GetMap(center = map.center.loc, zoom = input.zoom, maptype = "road", format = "roadmap", destfile = "mymap.png") PlotOnStaticMap(mymap, lat = map_data$Y좌표, lon = map_data$X좌표, destfile = "mymap.point.png", cex = 1, pch =20, col="blue“)

  45. googleVis 패키지 • R에서 구글 데이터 시각화 API를 이용 http://code.google.com/p/google-motion-charts-with-r/

  46. animation 패키지 • R Graph 결과를 animation으로 생성 # animation으로 생성 saveHTML({ for(map.i in 1:length(unique.name)) { mymap <- GetMap(center = map.center.loc, zoom = input.zoom, maptype = "road", format = "roadmap", destfile = "mymap.png") PlotOnStaticMap(mymap, lat = map_data[map_data$지역본부 == unique.name[map.i], ]$Y좌표, lon = map_data[map_data$지역본부 == unique.name[map.i], ]$X좌표, destfile = "mymap.point.png", cex = 1, pch =20, col="blue") } }, img.name = "unif_plot", imgdir = "unif_dir", htmlfile = "random.html", autobrowse = FALSE, title = "고속도로 영영소", description = c("RgoogleMaps 패키지를 활용한 데모.\n\n"))

  47. 기업체에서 주로 사용하는 R 유틸리티 • Rcmd • Rtools

  48. Rcmd 유틸리티 • Batch 작업을 위한 R Script # ============================================================================================== # 프로그램 시작 # ============================================================================================== cat("Batch Program Start!!!", as.character(Sys.time()), "\n") # ---------------------------------------------------------------------------------------------- # 오늘 날짜 today.date <- as.character(Sys.Date()) # 데이터프레임 생성 sample.df <- data.frame(year = substr(today.date, 1, 4), month = substr(today.date, 6, 7), day = substr(today.date, 9, 10), sample.norm = rnorm(1000000), stringsAsFactors = TRUE) # 데이터프레임을 csv 파일로 저장 write.csv(sample.df, paste("C:\\RProject\\OUT\\", today.date, ".", "sample.df.csv", sep = ""), row.names = FALSE) # ============================================================================================== # 프로그램 종료 # ============================================================================================== cat("Batch Program End!!!", as.character(Sys.time()), "\n") # ----------------------------------------------------------------------------------------------

  49. Rcmd 유틸리티 • Batch 작업을 위한 bat 파일 CD C:\Program Files\R\R-2.13.1\bin\x64 Rcmd BATCH C:\Rproject\RSC\RBatchSample.R C:\RProject\TXT\RBatchSample.txt set filename=RBatchSample_%date:~2%_%time:~0,2%_%time:~3,2%_%time:~6,2%.log copy C:\RProject\TXT\RBatchSample.txt C:\RProject\LOG\%filename% • bat 파일 • bat 파일 내 명령어는 dos 명령어 임 • Rcmd • R Batch를 수행하기 위해서는 Rcmd.exe 파일을 이용함 • Rcmd BATCH • BATCH 명령어는 대문자 임 • Usage: Rcmd BATCH [options] infile [outfile] • outfile을 지정하지 않으면 .Rout 파일로 outfile이 생성됨

  50. Rtools 유틸리티 • 기업체 내부의 분석 로직을 R 패키지로 생성 http://www.murdoch-sutherland.com/Rtools

More Related