r을 이용한 통계기반 데이터 분석 · 2017-03-20 · •자체 교육 (문제의식 +...
TRANSCRIPT
일정표
1일차 2일차 3일차 4일차
오전
도입 빅데이터 배경/개념 빅데이터 플랫폼
데이터 분석 개념과 절차 1 CRISP-DM 분석전략 (목표와 가
설/지표체계) 분석도구
통계 기초 이론 기술통계/추론통계
데이터 수집 개요 Excel SQL/NoSQL,
분석절차 2 모델링 개요 Bias-Variance
Trade-off Resampling
통계분석 모델링 3 비선형모델 선형대수와
다변량분석 데이터 정제 및 EDA
이론 실습
기계학습3 신경망 군집화 연관분석
모델개발3 (모델평가, 성능고도화) 모델평가 모델 성능고
도화
오후
실습 환경구축 (R, RStudio) R 기초
R 데이터구조, 함수 작성
R 활용 통계분석 모델링1
통계분석 모델링 2 회귀분석 모델선정과
Regularization 시계열분석
기계학습1 KNN 의사결정트리
기계학습2 SVM Naïve Bayes
시각화 시각화
빅데이터 플랫폼 Hadoop Spark
마무리 클라우드 DL
빅데이터 개념과 분석 플랫폼 데이터 분석 개념과 모델링 통계 분석 기계학습 R 언어
2
1일차
3
빅데이터 개요
배경 – 3V
• Tidal Wave – 3VC
• Supercomputer – High-throughput computing
– 2가지 방향:
• 원격, 분산형 대규모 컴퓨팅 (grid computing)
• 중앙집중형 (MPP)
• Scale-Up vs. Scale-Out
• BI (Business Intelligence) – 특히 DW/OLAP/데이터 마이닝
5
Hadoop
• Hadoop의 탄생? – 배경
• Google!
• Nutch/Lucene 프로젝트에서 2006년 독립 – Doug Cutting
– Apache의 top-level 오픈소스 프로젝트
– 특징
• 대용량 데이터 분산처리 프레임워크 – http://hadoop.apache.org – 순수 S/W
• 프로그래밍 모델의 단순화로 선형 확장성 (Flat linearity) – “function-to-data model vs. data-to-function” (Locality)
– KVP (Key-Value Pair)
6
1990년대 – Excite,
Alta Vista, Yahoo,
…
2000 – Google ;
PageRank,
GFS/MapReduce
2003~4 –
Google Paper
2005 – Hadoop
탄생
(D. Cutting &
Cafarella)
2006 – Apache
프로젝트에 등재
7
8
• Hadoop Kernel
• Hadoop 배포판 – Apache 버전
• 2.x.x : 0.23.x 기반
– 3rd Party 배포판
• Cloudera, HortonWorks와 MapR 9
• Hadoop & Ecosystems
10
11
빅데이터 전략과 분석과제
• 전략 일반론 – MBO (목표에 의한 관리)
• (업무 인과관계 보다는) 현재 수립된 사업목표를 다운스트림하여 각 조직과 계층에서 해야 할 일을 명확히 함
– BSC (균형성과관리)
• 목표의 인과관계를 규정하고 여러 측면 (perspective)에서 균형 있는 성장을 도모
12
• 균형성과관리와 KPI 지표 분석
13
• 빅데이터 세부과제의 선택
14
“전략적 중요성과 현실적 실행능력”
해결요인의 발굴
전략목표
성취가능성 집행력
전술
문제
중요성
시급성
실행역량 효과성
과제의 Positioning
• 빅데이터 분석 프로젝트 추진 절차 – POC 단계
• TFT 구성 • 자체 교육 (문제의식 + 방법론 + 기초기술) • 해결하려는/ 해결 가능한 문제를 정의 • 문제 해결을 위해 필요한 feature-set을 식별 • 모델링 (대체안) 및 평가 후 선정 • 효과 평가
– 1차 확산단계 • 추가의 문제 식별 후 실행 • 전사 데이터 관리전략 검토 • 1차 확산단계 평가
– 2차 확산단계 • 전사적 데이터 전략검토 수립 • 전사적 인재 관리전략 검토 수립 • (데이터 중심의 문화)
15
빅데티터 주요 활용 사례
리스크 분석 (은행)
사기 탐지 (신용카드), 자금세탁 위험탐지
소셜네트워크 분석 금융 및 통신사의 마케팅 (이벤트)
유통 최적화 (시뮬레이션) 부당 보험첨구 및 탈세위험 탐지
사전적 예방점검 (항공) 감성분석/SNA 제조부문에서의 수요예측 건강보험/질병정보 분석
전통적 텍스트 분석 실시간 영상감시 데이터 웨어하우징
실시간 (real time) 일괄처리 (Batch)
데이터의 속도
데이터의 유형
정형데이터 비정형데이터
16
데이터 분석 개요
17
뒷부분에서 가져옴
데이터 분석의 개념과 범위
• Data Mining/ Predictive Analysis
• Data Science
• BI/OLAP
• Analytics
• Modeling
• Machine Learning
• 수리/통계 분석
• KDD (Knowledge Discovery)
• Decision Support System
18
• 발전 – Data Science – 전통적 분석
• BI/OLAP/DB Query, Spreadsheet 중심 분석
• 통계 분석
– + 텍스트 분석 (SNA/감성분석, 마이닝, 검색)
– + Machine Learning/Deep Learning
데이터과학 (Data Science)
• Data Science
• 통계와 기계학습
통계 기계학습
Estimation Learning
Classifier Hypothesis
Data point Example/Instance
Regression Supervised Learning
Classification Supervised Learning
Covariate Features
Response Label
19
분석 절차
• CRISP-DM
20
Business 이해
데이터 이해
데이터 준비
모델링 Deployment 모델의 평가
Format Data
데이터 통합
Construct Data
데이터 정제
Select Data
Business Objectives 결정
Review Project
최종 보고서
Plan Monitoring & Maintenance
Plan Deployment
이후 단계의 결정
Review Process
모델수행 결과의 평가
Assess Model
모델 수립
Test Design
모델링 기법의 선택
상황의 분석
Explore Data
Describe Data
Initial Data의 수집
Data Mining 목표 설정
데이터 품질 점검
Project Plan의 작성
• 분석도구 – Big Bang
– 유료:
• Excel, SAS, SPSS, Matlab, …
– 오픈소스:
• R vs Python vs Octave vs Julia, …
http://www.openwith.net 21
R
• open-source 수리/통계 분석도구 및 프로그래밍 언어 – S 언어에서 기원하였으며 7,000여 개의 package
• CRAN: http://cran.r-project.org/
– 뛰어난 성능과 시각화 (visualization) 기능
22
기초통계
23
목차
• Unit I: 개요 – 1. 개요와 기술(記述)통계
– 2. 확률이론과 Bayesian
• Unit II: 변량별 데이터 분석 – 3. 단변량/이변량/다변량
• Unit III: 분포와 표본추출 – 4. 이산 분포와 연속 분포
– 5. 표본추출과 표본분포
• Unit IV: 모수 추정 – 6. 추정(단일/2개 모집단)
– 7. 가설검정
– 8. 분산분석과 실험계획
24 http://www.openwith.net
• 1.2 기술통계 (Descriptive Statistics) – (1) 중심경향성: Ungrouped Data
• Mode, Mean, Median • Percentile, Quantile/Quartile
– (2) 변동성: Ungrouped Data • Range & IQR (Interquartile Range) • MAD (Mean Absolute Deviation) • Variance, Standard Deviation
• Empirical Rule와 Chebychev’s Theorem
• Population vs. Sample Variance and Standard Deviation – Unbiased estimator
• Z-score
• Coefficient of Variation (CV)
27
http://www.openwith.net
– (3) Measures of Shape
• Skewness
– Coefficient of Skewness
• Kurtosis
• Box-and-Whisker Plots
28
– (4) 연관성 (Association) 측도
• Correlation
– Pearson product-moment correlation coefficient
– Spearman Correlation Coefficient
– Kendall Tau(τ) Correlation Coefficient
» 두 변수 순서관계 (ordinal association)
29 http://www.openwith.net
2. 확률이론과 Bayesian
• 2.1 기본개념
– Experiment, (근원) 사건, 표본공간, 독립사건, Unions, Intersections,
– MECE (Mutually Exclusive Collectively Exhaustive)
– Marginal, Union, Joint
– Counting Possibilities
• mn Counting Rule: m x n
• Sampling from a Population with Replacement: (N)n possibilities
• Combinations: Sampling from Population Without Replacement: NCn = 𝑁!/𝑛!(𝑁−𝑛)!
30
P(X⋂Y) = 0
http://www.openwith.net
31 http://www.openwith.net
3. 변량별 분석 도구
• 3.1 단변량 – Categorical Data
• Table, Barplots, Pie Chart, Dot Chart
– Numeric Data
• Stem-and-leaf plots, Strip chart
• Center: mean, median & mode
• Range, variance, …
– 분포의 모양
• Mode, Symmetry and Skew
• Boxplot, Histogram
33 http://www.openwith.net
• 3.2 이변량 (Bivariate) 데이터 – Pairs of categorical variables
• 2-way Table - 주변분포 (Marginal Distribution), 조건부 분포, contingency table
– 독립표본의 비교 • Side-by-side Boxplots, Density plot, Strip Chart, Q-Q plots
– Numeric Data에서의 관계(Relationship) • Scatter plot을 이용한 관계성 분석 - 상관관계
– 단순회귀분석
• 3.3 다변량 (Multivariate) 데이터 – 다변량데이터의 요약
• 범주형 다변량데이터 요약
• 독립표본의 비교와 관계성 비교
– 다변량 데이터 모델링 • Boxplot과 다변량 모델
• Contingency Table – xtabs()
• split()과 stack()
– Lattice 그래픽 활용
34
http://www.openwith.net
4. 이산 분포와 연속분포
• 4.1 개요 – 확률변수 (Random variable)
• = a variable that contains the outcomes of a chance experiment
• 4.2 이산분포의 모양 – 평균 or 기대값
• = long-run average of occurrences
– Variance와 Standard Deviation
• 4.2 이항분포 – Binomial formula
– 이항분포의 평균과 표준편차
• 4.3 Poisson 분포 – Law of improbable events
36
http://www.openwith.net
λ = long-run average
• 4.5 초기하 (Hypergeometric) 분포 – 개요
• = 유한 모집단으로부터 비복원추출 시 나타나는 확률분포
– 다음 경우에 이항분포 대신 사용:
• (i) Sampling is done without replacement.
• (ii) n ≥ 5% N
37 http://www.openwith.net
(연속 분포 )
• 4.6 일양분포 (一樣分布 Uniform Distribution)
• 4.7 정규분포 – 개요
• Gaussian 분포
• 정규분포의 확률밀도함수
– Standardized Normal Distribution • z score = 평균을 중심으로 한 표준편차의 개수
• z distribution
• 4.8 이항분포 대신 정규분포의 적용 (Approximate) – 경험법칙;
• 대략 normal curve value의 99.7%가 3 s.d. 이내
• n • p > 5 and n • q > 5
– Correcting for Continuity • ; Converting discrete distribution into a continuous distribution.
38
http://www.openwith.net
• 4.7 지수분포 – = Random occurrences 사이 시간의 확률분포
– 지수분포의 확률
• random arrivals 사이의 Inter-arrival times는 지수분포
– cf. Poisson 분포 = random occurrences over some interval
39 http://www.openwith.net
5. 표본추출과 표본분포
• 5.1 Sampling(표본추출) 방법
• 5.2 𝑥 의 표본분포
– 중심극한정리
• 𝜇𝑥 = μ
• 𝜎𝑥 = 𝜎
𝑛
– z Formula for Sample Means
– Sampling from a Finite Population
– 중심극한정리
• 5.3 𝑝 의 표본분포
40 http://www.openwith.net
6. 추정
• 신뢰구간 추정 (단일 모집단) – z 통계량 이용한 신뢰구간 추정 (단일 모집단) (σ Known)
• 점추정 (point estimation)
• 100(1-α)% Confidence Interval to Estimate μ: σ known]
• 유한조정계수
• Sample Size가 작은 경우 – 여태까지 주로 n ≥ 30
– n < 30 이어도 중심극한정리에 의해 z formula 적용 :
– sample size가 클 때 또는 작아도 모집단이 정규분포 (σ known)
42 http://www.openwith.net
– t 통계량 이용한 신뢰구간추정 (단일모집단) (σ Unknown)
• 모집단이 정규분포인데 모집단 s.d 를 모르는 경우 t 분포 적용.
– 표본크기에 따라 분포가 다르다.
– t statistic 의 assumption: 모집단이 정규분포
» If population is not normal dist. or is unknown, nonparametric techniques
– t Distribution의 특징: Robust
• t 통계량을 이용한 모집단 평균 추정에서의 신뢰구간
– 모비율 추정
43 http://www.openwith.net
– 모분산 추정
• (…)
– Sample Variance
– 모분산과 표본분산의 관계: χ2 분포
– 표본크기의 산정
• μ 추정 시의 표본크기
– μ 추정 시: 표본크기는 z formula를 이용
• p 추정 시의 표본크기
44 http://www.openwith.net
7. 가설검정 (단일 모집단)
• 7.1 개요 – Hypotheses의 종류
– Statistical Hypotheses
• H0 Ha
– 가설검정의 절차
– Rejection and Nonrejection Regions
– Type I 및 Type II Errors
45 http://www.openwith.net
• 7.2 z 통계량 이용한 모평균의 가설검정 (σ Known) – z Test for a Single Mean
– 유한모집단의 평균에 대한 검정
– p-Value를 이용한 가설검정
• p-value = 관측된 유의수준 (level of significance)
– defines the smallest value of 𝛼 for which the H0 can be rejected.
• “α 가 p보다 커야만 H0를 reject 가능”
– Critical Value Method를 이용한 가설검정
• Rejecting H0 using p-values
46 http://www.openwith.net
• 7.3 t 통계량 이용한 모평균 가설검정 (σ Unknown) – (…)
• z Test of a Population Proportion
– Critical Value Method를 이용한 가설검정 • Rejecting H0 using p-values
• 7.4 비율에 관한 가설검정 – […]
• Using p-value
• Using the critical value method
47 http://www.openwith.net
• 7.5 분산에 관한 가설검정
• Table χ2 vs. Observed χ2
• H0 can also be tested by the critical value method.
• 관측된 χ2 값 대신 critical χ2 value for α를 적용하여 s2 계산 yields critical sample variance (sc
2)
• 7.6 Type II Errors
48 http://www.openwith.net
(추정 – 2개 모집단)
• 7.7 z 통계량 이용한 두 개 평균 차에 대한 추정/가설검정 (σ Known)
– (…) – CLT: “”Difference in two sample means, 𝑥 1 − 𝑥 2 ~ ND() for large sample (both
n1 and n2 ≥ 30) regardless of the shape of populations”
– z formula for the difference in two sample means
– Hypothesis Testing – H0: μ1 – μ2 =δ
– Ha: μ1 – μ2 ≠δ
– Confidence Intervals
49
http://www.openwith.net
• 7.8 두 평균 차에 대한 추정/가설검정: 독립표본이고 σ Known – 가설검정
– t Test를 이용한 두 모평균 차에 대한 CI 수립 및 가설검정 – Confidence Intervals
• 7.9 서로 관련된 모집단에 대한 추정
– 종류 • Before-and-after study • Matched-pair with built-in relatedness, as an experimental control mechanism
(ex) twins, siblings
– 가설검정
– 신뢰구간
50
http://www.openwith.net
• 7.10 두 개 모비율에 대한 추정(p1 - p2)
– (…)
– 가설검정
– 신뢰구간
• 7.11 두 개 모분산에 대한 추정
51 http://www.openwith.net
8. 분산분석과 실험계획
• 8.1 실험계획 – 개념
• = a plan and a structure to test hypotheses in which the researcher either controls or manipulates one or more variables.
– 독립변수 (I.V.) • 처치변인 (treatment variable)
= 실험자가 통제 또는 조절하는 변인 • 분류변인 (classification variable (=factors))
= some characteristic of the subject that was present prior to the experiment and is not a result of manipulations or control.
• Each I.V. has 2 or more levels (= classifications =subcategories)
– 종속변수 (D.V.)
52 http://www.openwith.net
• 8.2 Completely Randomized Design (CRD)
– One-Way Analysis of Variance
• H0: μ1 = μ2 = μ3 = … = μk
• Ha: At least one of the means is different from the others.
53 http://www.openwith.net
– F 분포표 상의 수치
– ANOVA tests are always one-tailed tests w/ rejection region in the upper tail
– “Observed F value” vs. “Critical value of F test” (=Table F value) (d.f.에 의해 참조되는 값)
– Reject H0 if (observed F > critical F)
– F값 및 t값의 비교 • F = t2 for dfC = 1
54
http://www.openwith.net
• 8.3 다중비교 검정 – (…)
• ANOVA는multiple group의 평균 차에 대한 가설검정에 유용
– (장점) Type I error, α, is controlled
– Tukey’s HSD Test: The Case of Equal Sample Sizes
• = pairwise multiple comparisons
– Tukey-Kramer Procedure: The Case of Unequal Sample Sizes
55 http://www.openwith.net
• 8.4 Randomized Block Design (RBD) • CRD (I.V. = treatment var. ) + Blocking variable
– Block’g var ; to control confounding/concomitant variable
» researcher want to control but is not the treatment of interest
56 http://www.openwith.net
• 8.5 Factorial Design (Two-Way ANOVA) – Factorial Design의 장점
CRD RBD Factorial Design
각 변수의 Effect를
별도로 분석 (one
per design).
즉, 변수를 독립적으
로 검토
…
단 , focus on one
treatment variable &
control for the
blocking effect
Interaction 분석 가능
하나의 실험설계에서 두 변수를 동시에 분석.
Confounding or concomitant 변수를 하나의
study에서 control 가능하므로 CRD보다 power 증
가 가능 SSE로부터 2nd 변수의 추가효과를 제거
FD with 2 treatments는 RBD와 유사
두 변수의 effect에 주목
(2 treatment변수 간의 interaction 분석 가능, if
multiple measurements are taken under every
combination of levels of 2 treatment)
http://www.openwith.net 57
– 2개 처치변인을 가지는 Factorial Designs
– Factorial Design에 대한 통계검정 • Row effects:
H0: Row means all are equal. Ha: At least one row is different.
• Column effects: H0: Col. means are all equal. Ha: At least one col is different.
• Interaction effects: H0: Interaction effects =0. Ha: Interaction effect is present.
• Each of these observed F values is compared to a table F value.
• The table F value is determined by a, dfnum, and dfdenom.
http://www.openwith.net 58
실습환경 구축
60
추가 slide
R과 RStudio
• R 설치
• RStudio 설치
61
추가 slide
R 기초
62
• R 데이터 구조
• 제어구문
• R 함수의 작성
• R에서의 OOP
• 별도 자료 제공
63
R활용 통계분석 모델링 1
64
추가 slide
실습
65