Biểu đồ tọa độ song song

Phân tích giỏ hàng trong Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

Biểu đồ tọa độ song song là gì?

Biểu đồ minh họa ví dụ về tọa độ song song với tập dữ liệu MovieLens.

Phân tích giỏ hàng trong Python

Khi nào dùng biểu đồ tọa độ song song

 

  • Tọa độ song song vs. heatmap.
    • Không cần cường độ.
    • Chỉ cần biết có quy tắc hay không.
    • Muốn giảm rối mắt.

 

  • Tọa độ song song vs. scatterplot.
    • Cần thông tin từng quy tắc.
    • Không quan tâm nhiều chỉ số.
    • Chỉ xem các quy tắc cuối cùng.
Phân tích giỏ hàng trong Python

Chuẩn bị dữ liệu

 

from mlxtend.frequent_patterns import association_rules, apriori

# Load the one-hot encoded data
onehot = pd.read_csv('datasets/movies_onehot.csv')
# Generate frequent itemsets
frequent_itemsets = apriori(onehot, min_support = 0.10, use_colnames = True, max_len = 2)

# Generate association rules
rules = association_rules(frequent_itemsets, metric = 'support', min_threshold = 0.00)
Phân tích giỏ hàng trong Python

Chuyển quy tắc thành tọa độ

# Convert rules to coordinates.
rules['antecedent'] = rules['antecedents'].apply(lambda antecedent: list(antecedent)[0])
rules['consequent'] = rules['consequents'].apply(lambda consequent: list(consequent)[0])
rules['rule'] = rules.index
# Define coordinates and label
coords = rules[['antecedent','consequent','rule']]

# Print example
print(coords.head(1))
                antecedent        consequent  rule
0  Dark Knight, The (2008)  Inception (2010)     0
Phân tích giỏ hàng trong Python

Vẽ biểu đồ tọa độ song song

 

from pandas.plotting import parallel_coordinates

# Generate parallel coordinates plot
parallel_coordinates(coords, 'rule', colormap = 'ocean')
Phân tích giỏ hàng trong Python

Vẽ biểu đồ tọa độ song song

Hình minh họa một biểu đồ tọa độ song song với dữ liệu MovieLens.

Phân tích giỏ hàng trong Python

Tinh chỉnh biểu đồ tọa độ song song

# Generate frequent itemsets
frequent_itemsets = apriori(onehot, min_support = 0.01, use_colnames = True, max_len = 2)

# Generate association rules
rules = association_rules(frequent_itemsets, metric = 'lift', min_threshold = 1.00)

# Generate coordinates and print example
coords = rules_to_coordinates(rules)

# Generate parallel coordinates plot
parallel_coordinates(coords, 'rule')
Phân tích giỏ hàng trong Python

Tinh chỉnh biểu đồ tọa độ song song

Hình minh họa một biểu đồ tọa độ song song với dữ liệu MovieLens.

Phân tích giỏ hàng trong Python

Ayo berlatih!

Phân tích giỏ hàng trong Python

Preparing Video For Download...