티스토리 뷰
In [3]:
import pandas as pd
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import apriori
In [4]:
dataset= [['양말','팬티','신발'],
['신발','바지','팬티','셔츠'],
['모자','양말','신발'],
['신발','바지','팬티','장갑']]
In [6]:
t = TransactionEncoder()
t_a = t.fit(dataset).transform(dataset)
df = pd.DataFrame(t_a, columns = t.columns_)
df
Out[6]:
In [7]:
frequent = apriori(df, min_support=0.5, use_colnames=True)
frequent
Out[7]:
바지를 살 확률은 0.5, 팬티, 바지, 신발을 같이 살 확률도 0.5
신뢰도가 0.2인 항목만 보기¶
In [15]:
from mlxtend.frequent_patterns import association_rules
association_rules(frequent, metric='confidence', min_threshold=0.2)
Out[15]:
항상도(lift) | 의미 |
---|---|
1보다 작은 경우 | 우연적 기회보다 높은 확률 |
1인 경우 | 독립 |
1보다 큰 경우 | 우연적 기회보다 낮은 확률 |
3열을 보면 lift가 1보다 크므로 바지를 구매한 고객이 팬티를 구매할 확률이 높다는 것을 알 수 있다.
In [ ]:
출처: http://blog.naver.com/PostView.nhn?blogId=eqfq1&logNo=221444712369&parentCategoryNo=&categoryNo=45&viewDate=&isShowPopularPosts=true&from=search
'beginner > 파이썬 기초' 카테고리의 다른 글
클래스 (0) | 2019.04.29 |
---|---|
스택(stack)&큐(Queue)기본개념 (0) | 2019.04.09 |
Matplotlib (0) | 2019.02.19 |
NumPy_기타 (0) | 2019.02.19 |
NumPy_구간나누기 (0) | 2019.02.18 |