본문 바로가기

분석70

3시그마 규칙 ( 68-95-99.7 규칙 ) 통계학에서 68-95-99.7 규칙은 정규 분포를 나타내는 규칙으로, 경험적인 규칙(empirical rule)이라고도 한다. 3시그마 규칙(three-sigma rule)이라고도 하는데 이 때는 평균에서 양쪽으로 3표준편차의 범위에 거의 모든 값들(99.7%)이 들어간다는 것을 나타낸다. 약 68%의 값들이 평균에서 양쪽으로 1 표준편차 범위(μ±σ)에 존재한다. 약 95%의 값들이 평균에서 양쪽으로 2 표준편차 범위(μ±2σ)에 존재한다. 거의 모든 값들(실제로는 99.7%)이 평균에서 양쪽으로 3표준편차 범위(μ±3σ)에 존재한다. 어두운 파란색은 평균에서 1표준편차 이내이다. 이는 정규 분포에서 전체 중 68.27%를 차지한다. 2표준편차 범위(중간색과 어두운색)는 95.45%를 차지한다. 3표준.. 2020. 2. 20.
with statement in SQL with 문을 사용하면 SQL 문장을 매우 직관적으로 사용할 수 있는데, 다음과 같이 몇 가지 형태로 사용할 수 있다. 1. sub query를 with 문 으로 with list1 as ( select id, area from tbl_address where area = 'seoul' ), list2 as ( select subject, avg(score) from tbl_score where id in (select id from list1) group by subject ) select * from list2; 물론 위의 쿼리는 with문을 사용하지 않고 처리할 수도 있지만, with 문안의 가상테이블에서 다른 가상테이블을 조건으로 사용할 수도 있으며 복잡한 쿼리를 단순하게 직관적으로 표현할 수 있.. 2020. 1. 29.
How To Calculate Cohort Retention in SQL ‍Losing users sucks. Losing customers really sucks. If you’re a startup, you know that Retention is King. You should always be measuring and improving your user retention, so you can keep more users over time. In this post, we’ll show you how to calculate user retention on your own data in SQL. Defining retention If Gloria used the product on Monday and used the product again on Tuesday, she is .. 2020. 1. 7.
python : pd.to_numeric() VS astype(np.float64) import pandas as pd import numpy as np df = pd.DataFrame(np.random.randint(10**5, 10**7, (5,3)), columns=list('abc'), dtype=np.int64) df a b c 0 2368596 282593 7649457 1 6486779 5348256 790672 2 8468404 4682970 2904873 3 2271514 2908642 9272301 4 7811256 3652968 6715015 df.dtypes a int64 b int64 c int64 dtype: object df['a'] = df['a'].astype(float) df.dtypes a float64 b int64 c int64 dtype: obje.. 2019. 11. 27.
Python : Seaborn Visualization import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns # 데이터셋 iris = sns.load_dataset('iris') titanic = sns.load_dataset('titanic') tips = sns.load_dataset('tips') flights = sns.load_dataset('flights') x = iris.petal_length.values sns.rugplot(x) sns.kdeplot(x) sns.distplot(x, rug=True, kde=True, bins=50) plt.hist(x, bins=50) (array([ 2., 2., 7., 13., 13., 11.. 2019. 11. 25.
Python : Pandas Visualization pandas의 plot은 내부적으로 matplotlib.pyplot을 이용한다. import numpy as np import pandas as pd import matplotlib.pyplot as plt df1 = pd.DataFrame(np.random.randn(100, 3), index=pd.date_range('1/1/2019', periods=100), columns=['A', 'B', 'C']).cumsum() df1 A B C 2019-01-01 -0.896370 -1.962732 1.584821 2019-01-02 -0.248402 -3.101740 0.370419 2019-01-03 0.622560 -3.979711 1.666569 2019-01-04 1.239019 -3.443114.. 2019. 11. 25.
Python : timedelta(months=3) 방법 Python에서 사용할 수 있는 시간의 차이에 관련된 모듈은 datetime.timedelta 가 있습니다. 아래와 같이 사용할 수 있습니다. import datetime as dt now = dt.datetime.now() delta = dt.timedelta(hours=3) diff = now - delta 이 모듈에서 사용할 수 있는 옵션은 days hours seconds weeks 등이 있지만, months, years를 사용할 수는 없습니다. 그 대안으로 사용할 수 있는 모듈이 relativedelta 라는 모듈입니다. 그리고 그 사용은 아래와 같습니다. from dateutil.relativedelta import relativedelta import datetime as dt now = d.. 2019. 11. 12.
RFM Analysis (RFM 분석) R : recency (최근 구매일) F : frequency (구매 횟수) M : monetary (구매 금액 합계) 에 따른 고객군 구분 2019. 9. 24.
PostgreSQL : Windows Function (윈도우함수 정리) Windows Function을 사용하면 group by를 사용하지 않고도 SQL의 aggregate 함수를 사용할 수 있다. -- 원래 데이터 SELECT country, month, goalamount FROM TARGET order by month, country TARGET 이라는 테이블에 아래와 같이 국가별, 월별 목표금액이 있는 테이블이 있다고 가정을 하고... * 편의상 모든 결과는 20 row 까지만 캡춰를 하였습니다. 1. 집계 함수 -- 집계 함수 SELECT country, month, goalamount , avg(goalamount) over() as avg_amount , avg(goalamount) over(partition by month) as avg_month FROM T.. 2019. 9. 18.