1. Trang chủ
  2. » Luận Văn - Báo Cáo

Khai phá luật kết hợp có trọng số trong cơ sở dữ liệu lớn

91 13 0

Đ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

ĐẠI HỌC THÁI NGUYÊN TRƢỜNG ĐẠI HỌC CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG  - PHẠM ĐỨC QUANG KHAI PHÁ LUẬT KẾT HỢP CÓ TRỌNG SỐ TRONG CƠ SỞ DỮ LIỆU LỚN LUẬN VĂN THẠC SĨ KHOA HỌC MÁY TÍNH THÁI NGUN 2012 Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn ĐẠI HỌC THÁI NGUYÊN TRƢỜNG ĐẠI HỌC CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG  - PHẠM ĐỨC QUANG KHAI PHÁ LUẬT KẾT HỢP CÓ TRỌNG SỐ TRONG CƠ SỞ DỮ LIỆU LỚN Chuyên ngành: KHOA HỌC MÁY TÍNH Mã số: 60.48.01 LUẬN VĂN THẠC SĨ KHOA HỌC MÁY TÍNH Hƣớng dẫn khoa học: PGS.TS NGUYỄN THANH TÙNG THÁI NGUYÊN 2012 Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn LỜI CÁM ƠN Trước hết em xin gửi lời cám ơn chân thành đến tồn thể thầy giáo Viện Cơng nghệ thông tin - Viện Khoa học Công nghệ Việt Nam Trường Đại học Công nghệ thông tin Truyền thông - Đại học Thái nguyên dạy dỗ chúng em suốt trình học tập chương trình cao học trường Đặc biệt em xin bày tỏ lòng biết ơn sâu sắc tới PGS.TS Nguyễn Thanh Tùng quan tâm, định hướng, đưa gợi ý, góp ý chỉnh sửa vơ q báu cho em trình thực luận văn Cuối cùng, xin chân thành cám ơn bạn bè đồng nghiệp, gia đình người thân quan tâm, giúp đỡ chia sẻ với suốt trình làm luận văn tốt nghiệp Thái Nguyên, ngày 10 tháng năm 2012 Học viên Phạm Đức Quang Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn LỜI CAM ĐOAN Tôi xin cam đoan: Những nội dung luận văn thực hướng dẫn PGS.TS Nguyễn Thanh Tùng Mọi tham khảo sử dụng luận văn trích dẫn rõ ràng tác giả, tên cơng trình, thời gian, địa điểm công bố Tôi xin chịu trách nhiệm với lời cam đoan Thái Nguyên, ngày 10 tháng năm 2012 Học viên Phạm Đức Quang Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn MỤC LỤC Trang Trang bìa phụ Lời cảm ơn Lời cam đoan Mục lục i Danh mục từ, ký hiệu viết tắt iv Danh mục bảng v LỜI MỞ ĐẦU Chƣơng KHÁI QUÁT VỀ KHAI PHÁ DỮ LIỆU VÀ BÀI TOÁN KHAI PHÁ TẬP MỤC THƢỜNG XUYÊN 1.1 Khai phá liệu 1.2 Khai phá luật kết hợp 1.2.1 Cơ sở liệu giao tác 1.2.2 Phát biểu toán khai phá luật kết hợp 10 1.2.3 Thuật toán Apriori khám phá tập mục thường xuyên 12 1.3 Mở rộng toán khai phá tập mục thường xuyên 18 1.4 Kết luận chương 19 Chƣơng KHAI PHÁ LUẬT KẾT HỢP CÓ TRỌNG SỐ 20 2.1 Mở đầu 20 2.2 Khai phá luật kết hợp có trọng số khơng chuẩn hóa 21 2.2.1 Mơ hình tốn 21 2.2.2 Thuật toán MINWAL(O) khai phá tập mục thường xuyên có trọng số 24 2.2.2.1 Cơ sở toán học 24 2.2.2.2 Thuật toán MINWAL(O) 27 2.3 Khai phá luật kết hợp có trọng số chuẩn hóa 34 2.3.1 Mơ hình tốn 34 2.3.2 Thuật toán MINWAL(W) khai phá tập mục thường xuyên có trọng số chuẩn hóa 37 Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn 2.3.2.1 Cơ sở toán học 37 2.3.2.2 Thuật toán MINWAL(W) 37 2.2.3 Lập trình tính tốn thử nghiệm 45 2.4 Kết luận chương 46 Chƣơng KHAI PHÁ LUẬT KẾT HỢP CÓ TRỌNG SỐ BẰNG PHƢƠNG PHÁP CHỌN MẪU 47 3.1 Tổng thể mẫu thống kê toán học 47 3.2 Thuật toán khai phá luật kết hợp có trọng số dựa vào chọn mẫu 50 3.2.1 Xác định cỡ mẫu 50 3.2.2 Thuật toán 53 3.3 Lập trình tính tốn thử nghiệm 54 3.4 Kết luận chương 55 KẾT LUẬN 57 TÀI LIỆU THAM KHẢO 58 PHỤ LỤC 1: Chƣơng trình nguồn thuật tốn MINWAL(O) 61 PHỤ LỤC 2: Chƣơng trình nguồn thuật tốn MINWAL(O) 73 PHỤ LỤC 3: Chƣơng trình nguồn thuật toán SRS 81 Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn DANH MỤC CÁC KÝ HIỆU VÀ CHỮ VIẾT TẮT Các ký hiệu: I  i1 , , iM  : Tập tất M mục liệu sở liệu giao tác DT  T1 ,T2 , ,TN  : Cơ sở liệu DT gồm N giao tác X, Y, : Các tập tập tất mục sở liệu giao tác X = abc thay cho X  a, b, c ví dụ SC ( X ) : Số đếm hỗ trợ tập mục X (hay số giao tác chứa tập mục X) sup(X) : Độ hỗ trợ tập mục X Wsup(X) : Độ hỗ trợ có trọng số tập mục X NWsup(X) : Độ hỗ trợ có trọng số chuẩn hóa tập mục X minsup : Ngưỡng độ hỗ trợ tối thiểu wminsup : Ngưỡng độ hỗ trợ có trọng số tối thiểu nwminsup : Ngưỡng độ hỗ trợ có trọng số chuẩn hóa tối thiểu sup( X  Y ) : Độ hỗ trợ luật kết hợp X  Y conf ( X  Y ) : Độ tin cậy luật kết hợp X  Y A : Lực lượng (bản số) tập hợp A r  : Cận nguyên nhỏ số thực r Pr(E) : Xác suất xủa biến cố ngẫu nhiên E (0,1) : Phân phối chuẩn chuẩn tắc z1 : Phân vị mức  phân phối chuẩn chuẩn tắc Viết tắt: CNTT: Công nghệ Thơng tin CSDL: Cơ sở liệu Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn DANH MỤC CÁC BẢNG BIỂU Trang Bảng 1.1 Biểu diễn ngang sở liệu giao tác Bảng 1.2 Biểu diễn dọc sở liệu giao tác Bảng 1.3 Ma trận giao tác sở liệu bảng 1.1 Bảng 1.4 Cơ sở liệu giao tác minh hoạ thực thuật toán Apriori 16 Bảng 2.1 Cơ sở liệu giao tác ví dụ 26 Bảng 2.2 Trọng số mục CSDL giao tác 2.1 26 Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn LỜI MỞ ĐẦU Khai phá luật kết hợp kỹ thuật quan trọng, có nhiều ứng dụng khai phá liệu Mơ hình (mơ hình nhị phân) toán khai phá luật kết hợp đề xuất Agrawal cộng vào năm 1993, công trình nghiên cứu phát mối quan hệ (luật kết hợp) mặt hàng (mục liệu - items) sở liệu giao tác siêu thị [4, 5] Sau cơng trình kinh điển này, vấn đề khai phá luật kết hợp sở liệu (CSDL) giao tác nhiều nhà nghiên cứu lý thuyết ứng dụng quan tâm Nhiều thuật toán mới, hiệu khai phá luật kết hợp, mơ hình mở rộng tốn nhà nghiên cứu đề xuất [8, 9] Mơ hình nhị phân tốn khai phá luật kết hợp có số hạn chế, khơng đáp ứng địi hỏi khác người sử dụng Một hạn chế mơ hình tất mục liệu xử lý (xuất hay không xuất giao tác), thực tế chúng có tầm quan trọng khác Nhằm khắc phục hạn chế người ta đề xuất mơ hình tốn khai phá luật kết hợp có trọng số, mục liệu gán cho trọng số khác tùy theo mức độ quan trọng chúng việc mang lại lợi nhuận kinh doanh [3, 7, 8, 18] Những năm gần đây, khai phá luật kết hợp có trọng số trở thành đề tài hấp dẫn, nội dung quan trọng khai phá liệu, thu hút quan tâm nhiều nhà nghiên cứu ứng dụng Đề tài luận văn học viên nhằm nghiên cứu tốn, thuật tốn tìm hiểu khả ứng dụng kỹ thuật khai phá luật kết hợp có trọng số từ CSDL lớn Nội dung luận văn gồm chương: Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn Chương trình bày khái quát khai phá liệu, tóm tắt trình khai phá, kỹ thuật, ứng dụng thách thức; toán khai phá luật kết hợp nhị phân thuật toán Apriori Chương trình bày hai mơ hình mở rộng tốn khai phá luật kết hợp nhị phân: Khai phá luật kết hợp có trọng số khai phá luật kết hợp có trọng số chuẩn hóa, với giải thuật tương ứng 01) Chương trình bày cách tiếp cận tốn khai phá luật kết hợp có trọng số phương pháp lấy mẫu ngẫu nhiên từ CSDL ban đầu Thái Nguyên, tháng 09 năm 2012 Học viên Phạm Đức Quang Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn } }); int bound = 0; for (int i = itemset.getSize(); i < size; i++) { List subList = items.subList(0, size - i); double subListWeight = 0; for (Item subListItem : subList) { subListWeight += subListItem.getWeight(); } int b = (int) Math.ceil((m * wminsup) / (itemset.getWeight() + subListWeight)); bound = (bound == || bound > b) ? b : bound; } return bound; } private double computeWSupport(Itemset itemset) { double ws = (itemset.getWeight() * itemset.getSC()) / m; return ws; } private void counting() { for (Item item : header.values()) { Item[] items = {item}; Itemset itemset = new Itemset(items); itemset.setSC(computeSupportCount(items)); itemset.setB(computeBound(itemset)); if (itemset.getSC() >= itemset.getB()) { C.get(k).add(itemset); if (computeWSupport(itemset) >= wminsup) { L.get(k).add(itemset); } } } L0.addAll(L.get(k)); } private void join() { Set items = new HashSet(); for (Itemset itemset : C.get(k - 1)) { items.addAll(itemset.getItems()); } for (Set s : powerSet(items)) { if (s.size() == (k + 1)) { C.get(k).add(new Itemset(s)); } } } Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn private void prune() { Set previousItems = new HashSet(); for (Itemset itemset : C.get(k - 1)) { previousItems.addAll(itemset.getItems()); } Iterator iterator = C.get(k).iterator(); while (iterator.hasNext()) { // Check k-1 itemset in step k existed in step k-1? int yes = 0; int esc = 0; Itemset i = iterator.next(); for (Set s : powerSet(i.getItems())) { if (s.size() == k) { Set intersection = new HashSet(previousItems); intersection.retainAll(s); if (intersection.equals(s)) { yes = 1; int tmpESC = computeSupportCount(s); esc = (esc > tmpESC || esc == 0) ? tmpESC : esc; } } } int b = computeBound(i); i.setB(b); if (yes == && b > esc) { iterator.remove(); } } } private void checking() { Iterator iterator = C.get(k).iterator(); while (iterator.hasNext()) { Itemset i = iterator.next(); int sc = computeSupportCount(i.getItems()); i.setSC(sc); if (i.getB() > i.getSC()) { iterator.remove(); } if (computeWSupport(i) > wminsup) { L.get(k).add(i); } } L0.addAll(L.get(k)); Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn } private void rule() { for (Itemset itemset : L0) { int length = itemset.getSize(); int sc = itemset.getSC(); Set items = itemset.getItems(); ArrayList ss = new ArrayList(); for (Set s : powerSet(items)) { int slength = s.size(); if (slength >= && slength < length) { ss.add(s); } } for (int i = 0; i < ss.size(); i++) { Set right = new HashSet(items); Set left = ss.get(i); right.removeAll(left); int lsc = computeSupportCount(left); double conf = (double) sc / (double) lsc; if (conf >= wminconf) { Rule rule = new Rule(left, right, lsc, conf); Rules.add(rule); } } } } private Itemset getFromItems(Set items, ArrayList c) { for (Itemset itemset : c) { if (items.equals(itemset.getItems())) { return itemset; } } return null; } public static Set powerSet(Set originalSet) { Set sets = new HashSet(); if (originalSet.isEmpty()) { sets.add(new HashSet()); return sets; } List list = new ArrayList(originalSet); T head = list.get(0); Set rest = new HashSet(list.subList(1, list.size())); for (Set set : powerSet(rest)) { Set newSet = new HashSet(); Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn newSet.add(head); newSet.addAll(set); sets.add(newSet); sets.add(set); } return sets; } public void generateRules() throws IOException { config(); load(); // Procedure Counting(); C.add(new ArrayList()); L.add(new ArrayList()); counting(); while (C.get(k).size() > 1) { k++; C.add(new ArrayList()); L.add(new ArrayList()); join(); prune(); checking(); } rule(); } public String displayRules() { String str = "Danh sách luật:\n"; for (Rule rule : Rules) { str += rule.toString() + "\n"; } return str; } public String displayFrequenceItemsets() { String str = "Danh sách tập mục thường xuyên:\n"; for (Itemset itemset : L0) { str += itemset.toString() + "\n"; } return str; } public String getInputDataValues() throws IOException { String str = "CSDL giao tác: " + dataFile + "\n"; try (BufferedReader br = new BufferedReader(new FileReader(dataFile))) { String sCurrentLine; while ((sCurrentLine = br.readLine()) != null) { str += sCurrentLine + "\n"; Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn } } catch (IOException e) { e.getMessage(); } str += "Bảng trọng số: " + configFile + "\n"; try (BufferedReader br2 = new BufferedReader(new FileReader(configFile))) { String sCurrentLine2; while ((sCurrentLine2 = br2.readLine()) != null) { str += sCurrentLine2; } } catch (IOException e) { e.getMessage(); } return str; } } Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn PHỤ LỤC CHƢƠNG TRÌNH NGUỒN THUẬT TỐN MINWAL(W) File Item.java Xem mã nguồn thuật toán Minwal(O) File Itemset.java Xem mã nguồn thuật toán Minwal(O) File Rule.java Xem mã nguồn thuật toán Minwal(O) File MinwalW.java import au.com.bytecode.opencsv.*; import java.io.*; import java.util.*; class MinwalW { private String configFile; private String dataFile; private double wminsup; private double wminconf; private int size; private int m; private int k; private Map header; private List dt; private ArrayList C, L; private ArrayList L0; private ArrayList Rules; private List sortedHeader; public MinwalW() { this.C = new ArrayList(); this.L = new ArrayList(); this.L0 = new ArrayList(); this.Rules = new ArrayList(); this.size = 0; this.k = 0; this.m = 0; } public MinwalW(String cnfFile, double minconf) { this.configFile = cnfFile; this.dataFile = dtFile; this.wminsup = minsup; this.wminconf = minconf; String Số hóa Trung tâm Học liệu – Đại học Thái Nguyên dtFile, double minsup, http://www.lrc-tnu.edu.vn this.C = new ArrayList(); this.L = new ArrayList(); this.L0 = new ArrayList(); this.Rules = new ArrayList(); this.size = 0; this.k = 0; this.m = 0; } public void setDBFile(String file) { this.dataFile = file; } public String getDBFile() { return this.dataFile; } public void setHeaderFile(String file) { this.configFile = file; } public String getHeaderFile() { return this.configFile; } public void setwminsup(double minsup) { this.wminsup = minsup; } public double getwminsup() { return this.wminsup; } public void setwminconf(double minconf) { this.wminconf = minconf; } public double getwminconf() { return this.wminconf; } public void config() throws IOException { try (CSVReader readerConf = new CSVReader(new FileReader(configFile))) { header = new HashMap(); String row[] = readerConf.readNext(); for (int i = 0; i < row.length; i++) { double w = Double.valueOf(row[i]); header.put(new Integer(i), new Item(i, w)); } } catch (Exception e) { System.err.println(e.getMessage()); } Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn sortedHeader = new ArrayList(header.values()); // Sort header item desc order by weighted value Collections.sort(sortedHeader, new Comparator() { @Override public int compare(Item o1, Item o2) { if (o1.getWeight() > o2.getWeight()) { return 1; } if (o1.getWeight() < o2.getWeight()) { return -1; } return 0; } }); } public void load() throws IOException { try (CSVReader readerDT = new CSVReader(new FileReader(dataFile))) { String[] row; dt = new ArrayList(); while ((row = readerDT.readNext()) != null) { // Alternative of Search() procedure // @return size this.size = (this.size < row.length) ? row.length : this.size; this.m++; Item[] items = new Item[row.length]; for (int i = 0; i < row.length; i++) { int index = Integer.valueOf(row[i]); items[i] = new header.get(index).getWeight()); } Itemset itemset = new Itemset(items); dt.add(itemset); } } catch (Exception e) { System.err.println(e.getMessage()); } } Item(index, public int computeSupportCount(Item[] items) { int sc = 0; for (Itemset itemset : dt) { boolean yes = true; for (Item item : items) { if (!itemset.hasItem(item)) { yes = false; break; } } Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn sc += yes ? : 0; } return sc; } public int computeSupportCount(Set items) { int sc = 0; for (Itemset itemset : dt) { boolean yes = true; for (Item item : items) { if (!itemset.hasItem(item)) { yes = false; break; } } sc += yes ? : 0; } return sc; } /* * nws = nw * sc */ public double computeNWsupport(Itemset itemset) { double nws = (itemset.getWeight() * itemset.getSC()) / (m * itemset.getSize()); return nws; } public double computeWSupport(Itemset itemset) { double ws = (itemset.getWeight() * itemset.getSC()) / m; return ws; } public void counting() { for (Item item : header.values()) { Item[] items = {item}; Itemset itemset = new Itemset(items); itemset.setSC(computeSupportCount(items)); C.get(k).add(itemset); double NWsupport = computeNWsupport(itemset); if (NWsupport >= wminsup) { L.get(k).add(itemset); } } L0.addAll(L.get(k)); } public void join() { Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn for (Itemset itemset : L.get(k - 1)) { // Get all frequence itemsets from previous step int currentSC = itemset.getSC(); Set items = itemset.getItems(); List listItems = ArrayList(itemset.getItems()); Collections.sort(listItems, new Comparator() { @Override public int compare(Item o1, Item o2) { if (o1.getWeight() > o2.getWeight()) { return 1; } if (o1.getWeight() < o2.getWeight()) { return -1; } return 0; } }); new List subList = sortedHeader.subList(0, sortedHeader.indexOf(listItems.get(0))); for (Item subItem : subList) { Set newItems = new HashSet(items); newItems.add(subItem); Item[] newItem = {subItem}; int newItemSC = computeSupportCount(newItem); int esc = newItemSC = wminsup) { L.get(k).add(i); } } // System.out.print("*** Checking: "); // System.out.println(C.get(k)); L0.addAll(L.get(k)); } public void rule() { for (Itemset itemset : L0) { int length = itemset.getSize(); int sc = itemset.getSC(); Set items = itemset.getItems(); ArrayList ss = new ArrayList(); for (Set s : powerSet(items)) { int slength = s.size(); if (slength >= && slength < length) { ss.add(s); } } for (int i = 0; i < ss.size(); i++) { Set right = new HashSet(items); Set left = ss.get(i); right.removeAll(left); int lsc = computeSupportCount(left); double conf = (double) sc / (double) lsc; if (conf >= wminconf) { Rule rule = new Rule(left, right, lsc, conf); Rules.add(rule); } } } } public Itemset getExistedItemsetFromItems(Set items, ArrayList c) { Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn / for (Itemset itemset : c) { if (items.equals(itemset.getItems())) { return itemset; } } return null; } public static Set powerSet(Set originalSet) { Set sets = new HashSet(); if (originalSet.isEmpty()) { sets.add(new HashSet()); return sets; } List list = new ArrayList(originalSet); T head = list.get(0); Set rest = new HashSet(list.subList(1, list.size())); for (Set set : powerSet(rest)) { Set newSet = new HashSet(); newSet.add(head); newSet.addAll(set); sets.add(newSet); sets.add(set); } return sets; } public void generateRules() throws IOException { config(); load(); C.add(new ArrayList()); L.add(new ArrayList()); counting(); while (L.get(k).size() > 0) { k++; C.add(new ArrayList()); L.add(new ArrayList()); join(); prune(); checking(); } rule(); } public String displayRules() { String str = "Danh sách luật:\n"; for (Rule rule : Rules) { str += rule.toString() + "\n"; } Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn return str; } public String displayFrequenceItemsets() { String str = "Danh sách tập mục thường xuyên:\n"; for (Itemset itemset : L0) { str += itemset.toString() + "\n"; } return str; } public String getInputDataValues() throws IOException { String str = "CSDL giao tác: " + dataFile + "\n"; try (BufferedReader br = new BufferedReader(new FileReader(dataFile))) { String sCurrentLine; while ((sCurrentLine = br.readLine()) != null) { str += sCurrentLine + "\n"; } } catch (IOException e) { e.getMessage(); } str += "Bảng trọng số: " + configFile + "\n"; try (BufferedReader br2 = new BufferedReader(new FileReader(configFile))) { String sCurrentLine2; while ((sCurrentLine2 = br2.readLine()) != null) { str += sCurrentLine2; } } catch (IOException e) { e.getMessage(); } return str; } } Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn PHỤ LỤC CHƢƠNG TRÌNH NGUỒN THUẬT TỐN SRS File SRS.java import import import import java.io.*; java.util.*; au.com.bytecode.opencsv.CSVReader; au.com.bytecode.opencsv.CSVWriter; public class SRS { private Set mySet; private int N, n; private double z; public SRS(String filename, double d, double alpha) throws IOException { N = count(filename); if (alpha == 0.01) { z = 2.58; } if (alpha == 0.05) { z = 1.96; } n = (int) Math.ceil((N * Math.pow(z, 2)) / ((4 * N * Math.pow(d, 2)) + Math.pow(z, 2))); mySet = new TreeSet(); Random rand = new Random(); while (mySet.size() < n) { int randomNum = rand.nextInt(N + 1); mySet.add(randomNum); } String sampleFilename = filename.substring(0, filename.length() 4) + "_sample.csv"; CSVReader reader = new CSVReader(new FileReader(filename)); CSVWriter writer = new CSVWriter(new FileWriter(sampleFilename)); String[] nextLine; int lineCount = 0; while ((nextLine = reader.readNext()) != null) { if (mySet.contains(lineCount)) { writer.writeNext(nextLine); } lineCount++; } Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn reader.close(); writer.close(); } public int count(String filename) throws IOException { InputStream is = new BufferedInputStream(new FileInputStream(filename)); try { byte[] c = new byte[1024]; int count = 0; int readChars = 0; boolean empty = true; while ((readChars = is.read(c)) != -1) { empty = false; for (int i = 0; i < readChars; ++i) { if (c[i] == '\n') { ++count; } } } return (count == && !empty) ? : count; } finally { is.close(); } } } Số hóa Trung tâm Học liệu – Đại học Thái Nguyên http://www.lrc-tnu.edu.vn ... Khai phá luật kết hợp đóng vai trò quan trọng khai phá liệu Khai phá luật kết hợp phát mối quan hệ mục liệu Mơ hình tốn khai phá luật kết hợp giới thiệu Agrawal cộng vào năm 1993 phân tích sở liệu. .. minconf = 0.85, luật kết hợp có trọng số hấp dẫn là: d  e , e  d , b  de , bd  e , be  d 2.3 Khai phá luật kết hợp có trọng số chuẩn hóa Mơ hình tốn khai phá luật kết hợp có trọng số chuẩn hóa... phá luật kết hợp có trọng số khai phá luật kết hợp có trọng số chuẩn hóa, với giải thuật tương ứng 01) Chương trình bày cách tiếp cận tốn khai phá luật kết hợp có trọng số phương pháp lấy mẫu ngẫu

Ngày đăng: 26/03/2021, 06:58

Xem thêm:

TỪ KHÓA LIÊN QUAN

w