การใช้ parallel coordinates เพื่อแสดงภาพกฎ
การสาธิตด้วยภาพในแบบฝึกหัดก่อนหน้าทำให้ผู้ก่อตั้งเชื่อมั่นว่า supply-confidence border นั้นคุ้มค่าแก่การสำรวจเพิ่มเติม เธอจึงแนะนำให้ดึงข้อมูลบางส่วนของ border นั้นออกมาและแสดงภาพ เนื่องจากกฎที่อยู่บน border มีความแข็งแกร่งตามเมตริกส่วนใหญ่ เธอจึงเห็นว่าควรแสดงให้เห็นเพียงแค่ว่ากฎนั้นมีอยู่หรือไม่ แทนที่จะแสดงความเข้มข้นของกฎตามเมตริกใดเมตริกหนึ่ง
คุณตระหนักว่า parallel coordinates plot เหมาะอย่างยิ่งสำหรับกรณีเช่นนี้ ข้อมูลถูกนำเข้าให้แล้วในชื่อ onehot นอกจากนี้ยังได้นำเข้า apriori(), association_rules() และ parallel_coordinates() แล้ว และ pandas พร้อมใช้งานในชื่อ pd ส่วนฟังก์ชัน rules_to_coordinates() ได้ถูกกำหนดไว้และพร้อมใช้งานแล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Market Basket Analysis ด้วย Python
คำแนะนำการฝึกหัด
- เติมคำสั่งอัลกอริทึม Apriori โดยใช้ค่า minimum support ที่ 0.05
- คำนวณ association rules โดยใช้ค่าขีดจำกัด minimum confidence ที่ 0.50 ซึ่งสูงพอที่จะคัดเลือกเฉพาะจุดที่อยู่ใกล้ส่วนบนของ supply-confidence border
- แปลงกฎให้เป็นพิกัด
- พล็อตพิกัดโดยใช้
parallel_coordinates()
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Compute the frequent itemsets
frequent_itemsets = ____(onehot, min_support = ____,
use_colnames = True, max_len = 2)
# Compute rules from the frequent itemsets with the confidence metric
rules = association_rules(frequent_itemsets, metric = '____',
min_threshold = 0.50)
# Convert rules into coordinates suitable for use in a parallel coordinates plot
coords = rules_to_coordinates(____)
# Generate parallel coordinates plot
parallel_coordinates(____, 'rule')
plt.legend([])
plt.show()