Tìm hiểu một số thuật toán khai phá tập mục lợi ích cao và ứng dụng (LV thạc sĩ)

84 276 0
Tìm hiểu một số thuật toán khai phá tập mục lợi ích cao và ứng dụng (LV thạc sĩ)

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Tìm hiểu một số thuật toán khai phá tập mục lợi ích cao và ứng dụng (LV thạc sĩ)Tìm hiểu một số thuật toán khai phá tập mục lợi ích cao và ứng dụng (LV thạc sĩ)Tìm hiểu một số thuật toán khai phá tập mục lợi ích cao và ứng dụng (LV thạc sĩ)Tìm hiểu một số thuật toán khai phá tập mục lợi ích cao và ứng dụng (LV thạc sĩ)Tìm hiểu một số thuật toán khai phá tập mục lợi ích cao và ứng dụng (LV thạc sĩ)Tìm hiểu một số thuật toán khai phá tập mục lợi ích cao và ứng dụng (LV thạc sĩ)Tìm hiểu một số thuật toán khai phá tập mục lợi ích cao và ứng dụng (LV thạc sĩ)Tìm hiểu một số thuật toán khai phá tập mục lợi ích cao và ứng dụng (LV thạc sĩ)Tìm hiểu một số thuật toán khai phá tập mục lợi ích cao và ứng dụng (LV thạc sĩ)Tìm hiểu một số thuật toán khai phá tập mục lợi ích cao và ứng dụng (LV thạc sĩ)Tìm hiểu một số thuật toán khai phá tập mục lợi ích cao và ứng dụng (LV thạc sĩ)Tìm hiểu một số thuật toán khai phá tập mục lợi ích cao và ứng dụng (LV thạc sĩ)Tìm hiểu một số thuật toán khai phá tập mục lợi ích cao và ứng dụng (LV thạc sĩ)Tìm hiểu một số thuật toán khai phá tập mục lợi ích cao và ứng dụng (LV thạc sĩ)

i ii ĐẠI HỌC THÁI NGYÊN TRƯỜNG ĐẠI HỌC CNTT&TT TÌM HIỂU MỘT SỐ THUẬT TOÁN KHAI PHÁ TẬP MỤC LỢI ÍCH CAO ỨNG DỤNG Vũ Anh Đức Người hướng dẫn: TS Nguyễn Huy Đức Thái Nguyên- năm 2016 iii MỤC LỤC MỤC LỤC ii DANH MỤC HÌNH ẢNH v DANH MỤC BẢNG BIỂU vi LỜI CẢM ƠN vii LỜI CAM ĐOAN viii LỜI MỞ ĐẦU .1 Chương I: TỔNG QUAN VỀ KHAI PHÁ DỮ LIỆU KHAI PHÁ TẬP MỤC PHỔ BIẾN 1.1 Khái niệm khai phá tri thức khai phá liệu 1.2 Quá trình khai phá liệu 1.3 Một số kỹ thuật khai phá liệu .4 1.4 Một số ứng dụng khai phá liệu 1.5 Khai phá tập mục phổ biến 10 1.5.1 CSDL giao tác 10 1.5.2 Tập mục phổ biến luật kết hợp .12 1.5.2.1 Tập mục phổ biến 12 1.6 Thuật toán khai phá tập mục phổ biến 15 1.6.1 Thuật toán Apriori .16 1.6.2 Thuật toán FP-growth 18 1.7 Một số hướng mở rộng toán khai phá tập mục phổ biến 25 Chương II: MỘT SỐ THUẬT TOÁN HIỆU QUẢ KHAI PHÁ TẬP MỤC LỢI ÍCH CAO 27 2.1 Bài toán tập mục lợi ích cao .27 2.1.1 Các khái niệm liêm quan đến khai phá tập mục lợi ích cao 28 2.1.2 Bài toán khai phá tập mục lợi ích cao: 31 2.2 Thuật toán Hai pha 32 2.2.1 Cơ sở lý thuyết 32 2.2.2 Các bước thực thuật toán Hai pha .33 2.3 Thuật toán HUI - Miner 39 iv 2.3.1 Giới thiệu thuật toán 39 2.3.2 Cấu trúc utility-list 39 2.3.3 Khai phá tập mục lợi ích cao .44 Chương III:CHƯƠNG TRÌNH THỰC NGHIỆM ỨNG DỤNG .48 3.1 Bài toán phát nhóm mặt hàng mang lại lợi nhuận cao tập liệu bán hàng siêu thị Yên Bái 49 3.2 Mô tả liệu 50 3.3 Xây dựng chương trình 53 3.4 Thực nghiệm khai phá tìm tập mục lợi ích cao 55 3.5 Ý nghĩa kết thực nghiệm 56 KẾT LUẬN .58 TÀI LIỆU THAM KHẢO 60 PHỤ LỤC 62 v DANH MỤC HÌNH ẢNH Hình 1.1: Quá trình phát tri thức Hình 1.2: Quá trình KPDL Hình 1.3: Cây định Hình 1.4: Mẫu kết nhiệm vụ phân cụm liệu .6 Hình 1.5: Mẫu kết nhiệm vụ hồi quy .7 Hình 1.6: Cây FP-tree xây dựng dần thêm giao tác T1, T2, T3 21 Hình 1.7: Cây FP-tree CSDL DB bảng 1.4 .21 Hình 2.1: không gian tìm kiếm tập mục lợi ích cao 38 Hình 2.2: utility-list ban đầu .42 Hình 2.3: Utility-list tập mục 42 Hình 2.4 Cây liệt kê tập mục .45 Hình 3.1: Dữ liệu mã hóa chuẩn bị cho khai phá 53 Hình 3.2: Bảng lợi ích .53 Hình 3.3: Hiển thị dạng form: 55 Hình 3.4: Hiển thị dạng file: .56 vi DANH MỤC BẢNG BIỂU Bảng 1.1 Biểu diễn ngang CSDL giao tác 11 Bảng 1.2 Biểu diễn dọc CSDL giao tác .11 Bảng 1.3 Ma trận giao tác CSDL 11 Bảng 1.4 CSDL giao tác minh hoạ cho thuật toán FP- growth .20 Bảng 2.1: CSDL giao tác 36 Bảng 2.2: bảng lợi ích .36 Bảng 2.3: Bảng giao tác 40 Bảng 2.4: Bảng lợi ích .40 Bảng 2.5 Dữ liệu sau duyệtCSDL .41 Bảng 3.1: Dữ liệu trích chọn để khai phá .50 Bảng 3.2: Bảng lợi ích mặt hàng 51 Bảng 3.3 Mã hóa mặt hàng 52 vii LỜI CẢM ƠN Lời xin gửi lời cảm ơn chân thành biết ơn sâu sắc tới TS Nguyễn Huy Đức – Trường Cao đẳng Sư phạm Trung ương, người bảo hướng dẫn tận tình cho suốt trình nghiên cứu khoa học thực luận văn Tôi xin chân thành cảm ơn dạy bảo, giúp đỡ, tạo điều kiện khuyến khích trình học tập nghiên cứu thầy cô giáo Viện Công nghệ Thông tin, Trường Đại học Công nghệ Thông tin Truyền thông – Đại học Thái Nguyên cuối cùng, xin gửi lời cảm ơn tới gia đình, người thân bạn bè – người bên lúc khó khăn nhất, động viên tôi, khuyến khích sống công việc Tôi xin chân thành cảm ơn! Thái Nguyên, ngày 10 tháng 07 năm 2016 Tác giả Vũ Anh Đức viii LỜI CAM ĐOAN Tôi xin cam đoan Luận văn "Tìm hiểu số thuật toán khai phá tập mục lợi ích cao ứng dụng" công trình nghiên cứu riêng hướng dẫn TS Nguyễn Huy Đức Kết đạt luận văn sản phẩm riêng cá nhân tôi, không chép lại người khác Trong toàn luận văn, điều trình bày cá nhân tổng hợp từ nhiều nguồn tài liệu Tất tài liệu tham khảo có xuất xứ rõ ràng trích dẫn hợp pháp Tôi xin chịu hoàn toàn trách nhiệm chịu hình thức kỷ luật theo quy định cho lời cam đoan Thái Nguyên, ngày 10 tháng 07 năm 2016 Người cam đoan Vũ Anh Đức LỜI MỞ ĐẦU Khai phá tập mục phổ biến có vai trò quan trọng nhiều nhiệm vụ khai phá liệu Khai phá tập mục phổ biến xuất toán nhiều lĩnh vực khai phá liệu khám phá luật kết hợp, khám phá mẫu tuần tự… Bài toán khai phá luật kết hợp Agrawal, T.Imielinski A N Swami [3] đề xuất nghiên cứu lần đầu vào năm 1993 với mục tiêu phát tập mục phổ biến, từ tạo luật kết hợp Trong mô hình toán này, giá trị mục liệu giao tác 1, tức quan tâm mục liệu có xuất giao tác hay không Bài toán có nhiều ứng dụng, vậy, tập mục phổ biến mang ngữ nghĩa thống kê nên đáp ứng phần nhu cầu của thực tiễn Nhằm khắc phục hạn chế toán khai phá luật kết hợp, nhiều nhà nghiên cứu mở rộng toán theo nhiều hướng khác Năm 1997, Hilderman cộng đề xuất toán khai phá tập mục cổ phần cao Trong mô hình này, giá trị mục liệu giao tác số Năm 2004, nhóm nhà nghiên cứu H Yao, Hamilton Butz [9], mở rộng tiếp toán, đề xuất mô hình khai phá tập mục lợi ích cao Trong mô hình khai phá tập mục lợi ích cao, giá trị mục liệu giao tác số (như số lượng bán mặt hàng, gọi giá trị khách quan), có bảng lợi ích cho biết lợi ích mang lại bán đơn vị hàng (gọi giá trị chủ quan) Lợi ích tập mục số đo lợi nhuận mà tập mục mang lại Khai phá tập mục lợi ích cao khám phá tất tập mụclợi ích không nhỏ ngưỡng lợi ích tối thiểu người sử dụng Trong năm gần đây, toán thu hút quan tâm nhiều nhà nghiên cứu nước Với mục đích tìm hiểu toán tìm tập mục lợi ích cao thuật toán khai phá hiệu gần đây, em định lựa chọn đề tài “Tìm hiểu số thuật toán khai phá tập mục lợi ích cao ứng dụng” Nội dung luận văn gồm chương: Chương 1: Tổng quan khai phá liệu khai phá tập mục phổ biến Chương 2: Một số thuật toán hiệu khai phá tập mục lợi ích cao Chương 3: Chương trình thực nghiệm Chương I: TỔNG QUAN VỀ KHAI PHÁ DỮ LIỆU KHAI PHÁ TẬP MỤC PHỔ BIẾN 1.1 Khái niệm khai phá tri thức khai phá liệu KPDL việc rút trích tri thức cách tự động hiệu từ khối liệu lớn Tri thức thường dạng mẫu có tính chất không tầm thường, không tường minh (ẩn), chưa biết đến có tiềm mang lại lợi íchsố nhà nghiên cứu gọi KPDL phát tri thức sở liệu (Knowledge Discovery in Database – KDD) Ở coi KPDL cốt lõi trình phát tri thức Quá trình phát tri thức gồm bước [4]: Bước 1: Trích chọn liệu (data selection): Là bước trích chọn tập liệu cần khai phá từ tập liệu lớn (databases, data ware houses) Bước 2: Tiền xử lý liệu (data preprocessing): Là bước làm liệu (xử lý liệu không đầy đủ, liệu nhiễu, liệu không quán,…v.v), rút gọn liệu (sử dụng phương pháp thu gọn liệu, histograms, lấy mẫu…v.v), rời rạc hóa liệu (dựa vào histograms, entropy, phân khoảng, v.v) Sau bước này, liệu quán, đầy đủ, rút gọn rời rạc hóa Bước 3: Biến đổi liệu (data transformation): Là bước chuẩn hóa làm mịn liệu để đưa liệu dạng thuận lợi nhằm phục vụ cho kỹ thuật khai thác bước sau Bước 4: Khai phá liệu (data mining): Đây bước quan trọng tốn nhiều thời gian trình khám phá tri thức, áp dụng kỹ thuật khai phá (phần lớn kỹ thuật machine learning) để khai phá, trích chọn mẫu (pattern) thông tin, mối liên hệ đặc biệt liệu Bước 5: Đánh giá biểu diễn tri thức (knowledge representation & evaluation): Dùng kỹ thuật hiển thị liệu để trình bày mẫu thông tin 62 PHỤ LỤC Mã nguồn chương trình: import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import ca.pfv.spmf.tools.MemoryLogger; /** * This is an implementation of the "HUI-MINER Algorithm" for High-Utility Itemsets Mining * as described in the conference paper : * * Liu, M., Qu, J (2012) Mining High Utility Itemsets without Candidate Generation * Proc of CIKM 2012 pp.55-64 * * @see UtilityList 63 * @see Element * @author Philippe Fournier-Viger */ public class AlgoHUIMiner { /** the time at which the algorithm started */ public long startTimestamp = 0; /** the time at which the algorithm ended */ public long endTimestamp = 0; /** the number of high-utility itemsets generated */ public int huiCount =0; /** Map to remember the TWU of each item */ Map mapItemToTWU; /** writer to write the output file */ BufferedWriter writer = null; /** the number of utility-list that was constructed */ private int joinCount; /** buffer for storing the current itemset that is mined when performing mining * the idea is to always reuse the same buffer to reduce memory usage */ final int BUFFERS_SIZE = 200; private int[] itemsetBuffer = null; /** this class represent an item and its utility in a transaction */ class Pair{ 64 int item = 0; int utility = 0; } /** * Default constructor */ public AlgoHUIMiner() { } /** * Run the algorithm * @param input the input file path * @param output the output file path * @param minUtility the minimum utility threshold * @throws IOException exception if error while writing the file */ public void runAlgorithm(String input, String output, int minUtility) throws IOException { // reset maximum MemoryLogger.getInstance().reset(); // initialize the buffer for storing the current itemset itemsetBuffer = new int[BUFFERS_SIZE]; startTimestamp = System.currentTimeMillis(); writer = new BufferedWriter(new FileWriter(output)); // We create a map to store the TWU of each item 65 mapItemToTWU = new HashMap(); // We scan the database a first time to calculate the TWU of each item BufferedReader myInput = null; String thisLine; try { // prepare the object for reading the file myInput = new BufferedReader(new InputStreamReader( new FileInputStream(new File(input)))); // for each line (transaction) until the end of file while ((thisLine = myInput.readLine()) != null) { // if the line is a comment, is empty or is a // kind of metadata if (thisLine.isEmpty() == true || thisLine.charAt(0) == '#' || thisLine.charAt(0) == '%' || thisLine.charAt(0) == '@') { continue; } // split the transaction according to the : separator String split[] = thisLine.split(":"); // the first part is the list of items String items[] = split[0].split(" "); // the second part is the transaction utility int transactionUtility = Integer.parseInt(split[1]); // for each item, we add the transaction utility to its TWU for(int i=0; i = MIN_UTILITY List listOfUtilityLists = new ArrayList(); // CREATE A MAP TO STORE THE UTILITY LIST FOR EACH ITEM // Key : item Value : utility list associated to that item Map HashMap(); // For each item mapItemToUtilityList = new 67 for(Integer item: mapItemToTWU.keySet()){ // if the item is promising (TWU >= minutility) if(mapItemToTWU.get(item) >= minUtility){ // create an empty Utility List that we will fill later UtilityList uList = new UtilityList(item); mapItemToUtilityList.put(item, uList); // add the item to the list of high TWU items listOfUtilityLists.add(uList); } } // SORT THE LIST OF HIGH TWU ITEMS IN ASCENDING ORDER Collections.sort(listOfUtilityLists, new Comparator(){ public int compare(UtilityList o1, UtilityList o2) { // compare the TWU of the items return compareItems(o1.item, o2.item); } } ); // SECOND DATABASE PASS TO CONSTRUCT THE UTILITY LISTS // OF 1-ITEMSETS HAVING TWU >= minutil (promising items) try { // prepare object for reading the file myInput = new BufferedReader(new InputStreamReader(new FileInputStream(new File(input)))); // variable to count the number of transaction int tid =0; // for each line (transaction) until the end of file 68 while ((thisLine = myInput.readLine()) != null) { // if the line is a comment, is empty or is a // kind of metadata if (thisLine.isEmpty() == true || thisLine.charAt(0) == '#' || thisLine.charAt(0) == '%' || thisLine.charAt(0) == '@') { continue; } // split the line according to the separator String split[] = thisLine.split(":"); // get the list of items String items[] = split[0].split(" "); // get the list of utility values corresponding to each item // for that transaction String utilityValues[] = split[2].split(" "); // Copy the transaction into lists but // without items with TWU < minutility int remainingUtility =0; // Create a list to store items List revisedTransaction = new ArrayList(); // for each item for(int i=0; i = minUtility){ // add it revisedTransaction.add(pair); remainingUtility += pair.utility; } } Collections.sort(revisedTransaction, new Comparator(){ public int compare(Pair o1, Pair o2) { return compareItems(o1.item, o2.item); }}); // for each item left in the transaction for(Pair pair : revisedTransaction){ // subtract the utility of this item from the remaining utility remainingUtility = remainingUtility - pair.utility; // get the utility list of this item UtilityList utilityListOfItem = mapItemToUtilityList.get(pair.item); // Add a new Element to the utility list of this item corresponding to this transaction 70 Element element = new Element(tid, pair.utility, remainingUtility); utilityListOfItem.addElement(element); } tid++; // increase tid number for next transaction } } catch (Exception e) { // to catch error while reading the input file e.printStackTrace(); }finally { if(myInput != null){ myInput.close(); } } // check the memory usage MemoryLogger.getInstance().checkMemory(); // Mine the database recursively huiMiner(itemsetBuffer, 0, null, listOfUtilityLists, minUtility); // check the memory usage again and close the file MemoryLogger.getInstance().checkMemory(); // close output file writer.close(); // record end time endTimestamp = System.currentTimeMillis(); } 71 private int compareItems(int item1, int item2) { int compare = mapItemToTWU.get(item1) - mapItemToTWU.get(item2); // if the same, use the lexical order otherwise use the TWU return (compare == 0)? item1 - item2 : compare; } /** * This is the recursive method to find all high utility itemsets It writes * the itemsets to the output file * @param prefix This is the current prefix Initially, it is empty * @param pUL This is the Utility List of the prefix Initially, it is empty * @param ULs The utility lists corresponding to each extension of the prefix * @param minUtility The minUtility threshold * @param prefixLength The current prefix length * @throws IOException */ private void huiMiner(int [] prefix, int prefixLength, UtilityList pUL, List ULs, int minUtility) throws IOException { // For each extension X of prefix P for(int i=0; i< ULs.size(); i++){ UtilityList X = ULs.get(i); // If pX is a high utility itemset // we save the itemset: pX if(X.sumIutils >= minUtility){ 72 // save to file writeOut(prefix, prefixLength, X.item, X.sumIutils); } // If the sum of the remaining utilities for pX // is higher than minUtility, we explore extensions of pX // (this is the pruning condition) if(X.sumIutils + X.sumRutils >= minUtility){ // This list will contain the utility lists of pX extensions List exULs = new ArrayList(); // For each extension of p appearing // after X according to the ascending order for(int j=i+1; j < ULs.size(); j++){ UtilityList Y = ULs.get(j); // we construct the extension pXY // and add it to the list of extensions of pX exULs.add(construct(pUL, X, Y)); joinCount++; } // We create new prefix pX itemsetBuffer[prefixLength] = X.item; // We make a recursive call to discover all itemsets with the prefix pXY huiMiner(itemsetBuffer, prefixLength+1, X, exULs, minUtility); } } } 73 /** * This method constructs the utility list of pXY * @param P : the utility list of prefix P * @param px : the utility list of pX * @param py : the utility list of pY * @return the utility list of pXY */ private UtilityList construct(UtilityList P, UtilityList px, UtilityList py) { // create an empy utility list for pXY UtilityList pxyUL = new UtilityList(py.item); // for each element in the utility list of pX for(Element ex : px.elements){ // a binary search to find element ey in py with tid = ex.tid Element ey = findElementWithTID(py, ex.tid); if(ey == null){ continue; } // if the prefix p is null if(P == null){ // Create the new element Element eXY = new Element(ex.tid, ex.iutils + ey.iutils, ey.rutils); // add the new element to the utility list of pXY pxyUL.addElement(eXY); }else{ // find the element in the utility list of p wih the same tid Element e = findElementWithTID(P, ex.tid); if(e != null){ // Create new element 74 Element eXY = new Element(ex.tid, ex.iutils + ey.iutils - e.iutils, ey.rutils); // add the new element to the utility list of pXY pxyUL.addElement(eXY); } } } // return the utility list of pXY return pxyUL; } /** * Do a binary search to find the element with a given tid in a utility list * @param ulist the utility list * @param tid the tid * @return the element or null if none has the tid */ private Element findElementWithTID(UtilityList ulist, int tid){ List list = ulist.elements; // perform a binary search to check if the subset appears in level k-1 int first = 0; int last = list.size() - 1; // the binary search while( first >> 1; // divide by 75 if(list.get(middle).tid < tid){ first = middle + 1; // the itemset compared is larger than the subset according to the lexical order } else if(list.get(middle).tid > tid){ last = middle - 1; // the itemset compared is smaller than the subset is smaller according to the lexical order } else{ return list.get(middle); } } return null; } /** * Method to write a high utility itemset to the output file * @param the prefix to be writent o the output file * @param an item to be appended to the prefix * @param utility the utility of the prefix concatenated with the item * @param prefixLength the prefix length */ private void writeOut(int[] prefix, int prefixLength, int item, long utility) throws IOException { huiCount++; // increase the number of high utility itemsets found //Create a string buffer StringBuilder buffer = new StringBuilder(); // append the prefix for (int i = 0; i < prefixLength; i++) { 76 buffer.append(prefix[i]); buffer.append(' '); } // append the last item buffer.append(item); // append the utility value buffer.append(" #UTIL: "); buffer.append(utility); // write to file writer.write(buffer.toString()); writer.newLine(); } /** * Print statistics about the latest execution to System.out */ public void printStats() { System.out.println("============= HUI-MINER ALGORITHM ============="); System.out.println(" Total time ~ " + (endTimestamp - startTimestamp) + " ms"); System.out.println(" Memory ~ " + MemoryLogger.getInstance().getMaxMemory() + " MB"); System.out.println(" Số nhóm mặt hàng lợi ích cao : " + huiCount); System.out.println(" Join count : " + joinCount); System.out.println("======================================== ==========="); } } ... Tìm hiểu số thuật toán khai phá tập mục lợi ích cao ứng dụng Nội dung luận văn gồm chương: Chương 1: Tổng quan khai phá liệu khai phá tập mục phổ biến Chương 2: Một số thuật toán hiệu khai phá. .. lợi ích mang lại bán đơn vị hàng (gọi giá trị chủ quan) Lợi ích tập mục số đo lợi nhuận mà tập mục mang lại Khai phá tập mục lợi ích cao khám phá tất tập mục có lợi ích không nhỏ ngưỡng lợi ích. .. 18 1.7 Một số hướng mở rộng toán khai phá tập mục phổ biến 25 Chương II: MỘT SỐ THUẬT TOÁN HIỆU QUẢ KHAI PHÁ TẬP MỤC LỢI ÍCH CAO 27 2.1 Bài toán tập mục lợi ích cao

Ngày đăng: 26/07/2017, 15:56

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan