1. Trang chủ
  2. » Cao đẳng - Đại học

Xây dựng datalake hỗ trợ gợi ý tập khách hàng trong ngành bán lẻ

88 97 2

Đ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

TRƯỜNG ĐẠI HỌC CÔNG NGHỆ THÔNG TIN KHOA CÔNG NGHỆ PHẦN MỀM NGŨN Q́C AN LƯU HOÀNG HIỆP KHĨA LUẬN TỐT NGHIỆP XÂY DỰNG DATALAKE HỖ TRỢ GỢI Ý TẬP KHÁCH HÀNG TRONG NGÀNH BÁN LẺ Build Data Lake to support suggesting customer group in retail industries KỸ SƯ NGÀNH KỸ THUẬT PHẦN MỀM TP HỒ CHÍ MINH ,2021 ĐẠI HỌC Q́C GIA TP HỒ CHÍ MINH TRƯỜNG ĐẠI HỌC CÔNG NGHỆ THÔNG TIN KHOA CÔNG NGHỆ PHẦN MỀM NGUYỄN Q́C AN -16520012 LƯU HOÀNG HIỆP -16520379 KHĨA LUẬN TỚT NGHIỆP XÂY DỰNG DATALAKE HỖ TRỢ GỢI Ý TẬP KHÁCH HÀNG TRONG NGÀNH BÁN LẺ Build Data Lake to support suggesting customer group in retail industries GIẢNG VIÊN HƯỚNG DẪN VŨ ĐỨC LUNG ĐỖ THỊ THANH TUYỀN TP HỒ CHÍ MINH ,2021 LỜI CÁM ƠN Xin gửi lời cảm ơn sâu sắc đến Thầy Vũ Đức Lung Cô Đỗ Thị Thanh Tuyền thời gian hỗ trợ chúng em xây dựng khóa luận tốt nghiệp Qua học kỳ 15 tuần chúng em học nhiều kiến thức hữu ích, làm việc có hỗ trợ tận tình, thoải mái tâm trạng dễ tiếp thu Các công việc tiến độ tuần tài liệu thầy giao Microsoft Team giúp chúng em có lượng kiến thức định để xây dựng nên khóa luận tốt nghiệp Kết thu khóa luận tốt nghiệp đầu tư, tâm nhóm thực mà cịn có cơng sức ý kiến giảng dạy kiến thức trình chúng em bắt đầu học, cảm ơn thầy cô giúp đỡ chúng em vượt qua khó khăn học kỳ ln tâm huyết truyền lại kiến thức giải đáp thắc mắc sinh viên chúng em Khóa luận tốt nghiệp kiến thức chúng em tổng hợp thông qua trình học tập từ kiến thức mà thầy, giảng dạy chúng em, q trình chấm báo cáo có sai sót xin thầy thơng cảm cho chúng em, cá nhân nhóm cố gắng để xây dựng nên khóa luận tốt nghiệp hồn chỉnh cố gắng hướng tới kết tốt Lời cuối lời cảm ơn sâu sắc chân thành đến thầy Lung cô Tuyền giúp chúng em có kiến thức vững để sau bắt đầu vào môi trường thực tế khơng gặp nhiều khó khăn áp dụng kiến thức học từ thầy lớp để áp dụng giải vấn đề thực tế cách tốt Nhóm thực Trang ĐHQG TP HỒ CHÍ MINH CỘNG HỊA XÃ HỘI CHỦ NGHĨA VIỆT NAM TRƯỜNG ĐẠI HỌC Độc Lập - Tự Do - Hạnh Phúc CÔNG NGHỆ THÔNG TIN ĐỀ CƯƠNG CHI TIẾT TÊN ĐỀ TÀI TIẾNG VIỆT: Xây dựng DataLake hỗ trợ gợi ý tập khách hàng ngành bán lẻ TÊN ĐỀ TÀI TIẾNG ANH: Build Data Lake to support suggesting customer group in retail industries Cán hướng dẫn: PGS.TS Vũ Đức Lung, ThS Đỗ Thị Thanh Tuyền Thời gian thực hiện: Từ ngày 01/09/2020 đến ngày 21/01/2021 Sinh viên thực hiện: Nguyễn Quốc An - 16520012, Lưu Hoàng Hiệp - 16520379 Nội dung đề tài Tổng quan đề tài Với phát triển cách nhanh chóng xã hội ngày nay, việc ứng dụng công nghệ thông tin vào doanh nghiệp với mục đích ch̉n hóa quy trình định công ty,và liệu tảng điểm khởi đầu cho thảo luận chuyển đổi doanh nghiệp Dữ liệu tiếp tục trao quyền cho người, cơng nghệ quy trình Dữ liệu cho phép tổ chức hiểu khách hàng họ, dự đốn nhu cầu sở thích họ phản hồi nhanh Dữ liệu trở thành xương sống cho thứ phải làm với cải tiến chất lượng khả sản phẩm Dữ liệu chí cịn cho phép tổ chức hiểu thân hoạt động hiệu thông qua phân tích chu kỳ kinh doanh, thói quen nhân viên nhu cầu khách hàng Trang Đó lý mà nhóm em chọn đề tài xây dựng DataLake hỗ trợ gợi ý tập khách hang ngành bán lẻ, với mục đích làm cho doanh nghiệp hiểu khách hàng họ cải thiện chất lượng, dịch vụ doanh nghiệp Nhóm em tin rằng, giải pháp hữu ích thực tiễn cho quan, tổ chức, doanh nghiệp Lý thuyết thực tiễn Xây dựng hệ thống DataLake áp dụng kiến thức trí tuệ nhân tạo, cho phép quan, tổ chức, doanh nghiệp thực tìm hiểu nhu cầu, sở thích khách hàng giúp doanh nghiệp cải thiện chất lượng dịch vụ Dựa vào liệu tìm hiểu nhu cầu khách hàng cung câp báo cáo phân tích dư liệu Kết dự kiến Xây dựng hệ thống DataLake hệ hỗ trợ định cho phép doanh nghiệp tìm hiểu hiểu nhu cầu, sở thích khách hàng giúp doanh nghiệp cải thiện chất lượng dịch vụ Dựa vào liệu tìm hiểu nhu cầu khách hàng cung câp báo cáo phân tích dư liệu Và sau gợi ý sản phẩm phù hợp cho khách hàng Kế hoạch thực hiện: STT Công việc Thời gian thực Phase 1: Tìm hiểu hệ thống DataLake có tuần thị trường xây dựng hệ thống (1/9/2020-31/10/2020) Tìm hiểu định nghĩa Big Data DataLake Trang 1.1 -Big Data gì? Tuần 1-2 -Data Lake gì? Khác biệt so với Data (1/9/2020-14/9/2020) Warehouse -Tìm hiểu Hadoop eco-system, SMACK, Mongo ELK -Tìm hiểu kiến trúc big data system -Chi phí,bảo mật,tính mở rộng, khả chịu lỗi Tìm hiểu kiến trúc Lambda 2.1 -Tìm hiểu nguyển lý hoạt động Batch Tuần 3-4 Layer,Serving Layer,Speed Layer (15/9/2020-30/9/2020) -Xác định điểm mạnh điểm yếu kiến trúc Lambda Xây dựng DataLake mơ hình kiến trúc Lambda cải tiến -Deploy Kafka,Hadoop,Zookeeper, Dremio Tuần 5-8 -Deploy Database PostgreSQL (1/10/2020-31/10/2020) -Deploy Confluent để hoàn thiện kiến trúc Lambda Phase : Xây dựng hệ thống Recomender system tuần (2/11/2020-31/12/2020) Trang 4 Tìm hiểu Recommender System 4.1 -Tìm hiểu Recommender System tuần -Tìm hiểu Hybrid Recommended, (2/11/2020-16/11/2020) Collaborative Filtering,Content Based Filtering ,Session-Based Filtering -Tìm hiểu Memory Based Model Based Collaborative Filtering Lựa chọn thuật toán 5.1 -Lựa chọn thuật toán phù hợp cho hệ tuần thống (cây định,K-Means,K-Nearest (17/11/2020-30/11/2020) Neighbor) -Lựa chọn công thức đánh giá phù hợp (Cosine Similarity, Pearson correlation coefficient, Euclidean Distance,…) Xây dựng Recommender System 6.1 -Xây dựng Recommender System dựa tuần Collaborative Filtering Content Based (1/12/2020-31/12/2020) Filtering -Xây dựng giao diện trực quan đơn giản cho người dùng phổ thơng Phase :Hồn thiện tổng kiểm thử 7.1 -Kiểm thử tuần -Hoàn thiện sản phẩm (2/1/2020-21/1/2020) Trang -Đánh giá Xác nhận CBHD Tp HCM, ngày 27 tháng 12 năm 2020 (Ký tên ghi rõ họ tên) Sinh viên (Ký tên ghi rõ họ tên) Vũ Đức Lung Đỗ Thị Thanh Tuyền Trang MỤC LỤC LỜI CÁM ƠN ĐỀ CƯƠNG CHI TIẾT MỤC LỤC DANH MỤC HÌNH VẼ TÓM TẮT ĐỀ TÀI 11 MỞ ĐẦU 12 CHƯƠNG TỔNG QUAN ĐỀ TÀI 15 1.1 MỤC TIÊU VÀ PHẠM VI 15 1.1.1 Mục tiêu 15 1.1.2 Phạm vi 15 1.2 NỘI DUNG THỰC HIỆN 15 CHƯƠNG DỮ LIỆU LỚN LÀ GÌ, CÁC KHÁI NIỆM CHUYÊN NGÀNH CẦN LÀM RÕ 17 2.1 KHẢO SÁT THỰC TRẠNG 17 2.2 DỮ LIỆU LỚN LÀ GÌ? 18 2.3 ĐẶC ĐIỂM CỦA DỮ LIỆU LỚN 19 2.3.1 Dung lượng 22 2.3.2 Vận tốc 23 2.3.3 Đa dạng 24 2.3.4 Độ xác 25 2.3.5 Giải pháp liệu lớn - sở hạ tầng đám mây so với chỗ 26 CHƯƠNG HỆ SINH THÁI HADOOP 28 3.1 APACHE HADOOP 28 3.2 HỆ THỐNG TỆP PHÂN TÁN HADOOP (HDFS) 30 3.3 HADOOP MAPREDUCE 35 3.4 YARN 35 3.5 CÁC DỰ ÁN APACHE LIÊN QUAN ĐẾN DỮ LIỆU LỚN (BIG DATA) 37 3.5.1 Apache Zookeeper 37 3.5.2 Apache Kafka 38 3.5.3 Confluent 40 3.5.4 Apache Spark 41 CHƯƠNG ÁP DỤNG 4.1 4.2 4.3 HỆ THỐNG KHUYẾN NGHỊ LÀ GÌ ? 45 CÁC HƯỚNG TIẾP CẬN CHO HỆ THỐNG KHUYẾN NGHỊ 45 CÁC THUẬT TOÁN SỬ DỤNG TRONG HỆ THỐNG KHUYẾN NGHỊ 46 CHƯƠNG 5.1 HỆ THỚNG KHUYẾN NGHỊ LÀ GÌ, CÁC KHÁI NIỆM VÀ THUẬT TOÁN ĐƯỢC 45 XÂY DỰNG DATA LAKE 50 TRÌNH BÀY Ý TƯỞNG 50 CHƯƠNG HIỆN THỰC HÓA Ý TƯỞNG 53 6.1 YÊU CẦU PHẦN MỀM 53 6.2 YÊU CẦU PHẦN CỨNG 53 6.3 HƯỚNG DẪN CHUẨN BỊ MÔI TRƯỜNG LÀM VIỆC 54 6.3.1 Cài đặt Java 54 6.3.2 Cài đặt Oracle JDK 55 6.3.3 Cài đặt Hadoop 55 6.3.4 Cài đặng KAFKA 58 Trang 6.3.5 6.3.6 6.3.7 CHƯƠNG THỐNG Cài đặt dremio 59 Cài đặt sqoop/postgreesql/hbase 61 Xây dựng DataLake 62 XÂY DỰNG RECOMMENDER SYSTEM VÀ TỔNG QUAN CỦA TOÀN BỘ HỆ 68 7.1 TRÌNH BÀY Ý TƯỞNG 68 7.2 HIỆN THỰC HÓA Ý TƯỞNG 71 7.2.1 Phần khai thác liệu 71 7.2.2 Phần hiển thị UI 79 7.3 MƠ HÌNH KIẾN TRÚC CỦA TOÀN BỘ HỆ THỐNG 80 CHƯƠNG KẾT LUẬN VÀ HƯỚNG PHÁT TRIỂN 81 8.1 KẾT QUẢ ĐẠT ĐƯỢC 81 8.2 NHẬN XÉT 81 8.2.1 Ưu điểm 81 8.2.2 Khuyết điểm 82 8.3 HƯỚNG PHÁT TRIỂN 82 CHƯƠNG TÀI LIỆU THAM KHẢO 83 Trang self.W = np.random.randn(K, self.n_users) else: self.W = Winit # item biases self.b = np.random.randn(self.n_items) self.d = np.random.randn(self.n_users) # #self.all_users = self.Y_data[:,0] # all users (may be duplicated) self.n_ratings = Y_data.shape[0] self.mu = np.mean(Y_data[:, 2]) self.mu = def normalize_Y(self): if self.user_based: user_col = item_col = n_objects = self.n_users else: user_col = item_col = n_objects = self.n_items users = self.Y_data[:, user_col] self.muu = np.zeros((n_objects,)) for n in range(n_objects): # row indices of rating done by user n # since indices need to be integers, we need to convert ids = np.where(users == n)[0].astype(np.int32) # indices of all ratings associated with user n item_ids = self.Y_data[ids, item_col] # and the corresponding ratings ratings = self.Y_data[ids, 2] # # take mean m = np.mean(ratings) print m if np.isnan(m): m = # to avoid empty array and nan value self.muu[n] = m # normalize self.Y_data[ids, 2] = ratings - m def loss(self): L=0 Trang 72 for i in range(self.n_ratings): # user, item, rating n, m, rate = int(self.Y_data[i, 0]), int(self.Y_data[i, 1]), self.Y_data[i, 2] L += 0.5*(self.X[m, :].dot(self.W[:, n]) + self.b[m] + self.d[n] + self.mu - rate)**2 # regularization, don't ever forget this L /= self.n_ratings L += 0.5*self.lam*(np.linalg.norm(self.X, 'fro') + np.linalg.norm(self.W, 'fro') + \ np.linalg.norm(self.b) + np.linalg.norm(self.d)) return L def get_items_rated_by_user(self, user_id): """ get all items which are rated by user n, and the corresponding ratings """ # y = self.Y_data_n[:,0] # all users (may be duplicated) # item indices rated by user_id # we need to +1 to user_id since in the rate_matrix, id starts from # while index in python starts from ids = np.where(self.Y_data[:,0] == user_id)[0] item_ids = self.Y_data[ids, 1].astype(np.int32) # index starts from ratings = self.Y_data[ids, 2] return (item_ids, ratings) def get_users_who_rate_item(self, item_id): """ get all users who rated item m and get the corresponding ratings """ ids = np.where(self.Y_data[:,1] == item_id)[0] user_ids = self.Y_data[ids, 0].astype(np.int32) ratings = self.Y_data[ids, 2] return (user_ids, ratings) def updateX(self): for m in range(self.n_items): user_ids, ratings = self.get_users_who_rate_item(m) Wm = self.W[:, user_ids] dm = self.d[user_ids] xm = self.X[m, :] error = xm.dot(Wm) + self.b[m] + dm + self.mu - ratings Trang 73 grad_xm = error.dot(Wm.T)/self.n_ratings + self.lam*xm grad_bm = np.sum(error)/self.n_ratings + self.lam*self.b[m] self.X[m, :] -= self.learning_rate*grad_xm.reshape((self.K,)) self.b[m] -= self.learning_rate*grad_bm def updateW(self): for n in range(self.n_users): item_ids, ratings = self.get_items_rated_by_user(n) Xn = self.X[item_ids, :] bn = self.b[item_ids] wn = self.W[:, n] error = Xn.dot(wn) + bn + self.mu + self.d[n] - ratings grad_wn = Xn.T.dot(error)/self.n_ratings + self.lam*wn grad_dn = np.sum(error)/self.n_ratings + self.lam*self.d[n] self.W[:, n] -= self.learning_rate*grad_wn.reshape((self.K,)) self.d[n] -= self.learning_rate*grad_dn def fit(self): self.normalize_Y() for it in range(self.max_iter): self.updateX() self.updateW() if (it + 1) % self.print_every == 0: rmse_train = self.evaluate_RMSE(self.Y_raw) print ('iter =', it + 1, ', loss =', self.loss(), ', RMSE train =', rmse_train) def pred(self, u, i): """ predict the rating of user u for item i if you need the un """ u = int(u) i = int(i) if self.user_based == 1: bias = self.muu[u] else: bias = self.muu[i] pred = self.X[i, :].dot(self.W[:, u]) + self.b[i] + self.d[u] + bias return max(0, min(5, pred)) def pred_for_user(self, user_id): ids = np.where(self.Y_data[:, 0] == user_id)[0] Trang 74 items_rated_by_u = self.Y_data[ids, 1].tolist() y_pred = self.X.dot(self.W[:, user_id]) predicted_ratings= [] for i in range(self.n_items): if i not in items_rated_by_u: predicted_ratings.append(i) return predicted_ratings def recommend(self, u): ids = np.where(self.Y_data[:, 0] == u) ids = ids[0] items_rated_by_u = self.Y_data[ids, 1].tolist() recommended_items = [] for i in range(self.n_items): if i not in items_rated_by_u: rating = self.pred(u, i) if rating > 0: recommended_items.append(i) return recommended_items def evaluate_RMSE(self, rate_test): n_tests = rate_test.shape[0] SE = # squared error for n in range(n_tests): # pred = self.pred(rate_test[n, 0], rate_test[n, 1]) print pred, rate_test[n, 2] SE += (pred - rate_test[n, 2])**2 RMSE = np.sqrt(SE/n_tests) return RMSE def print_recommendation(self): print(' Recommendation: ') for u in range(self.n_users): recommended_items = self.pred_for_user(u) print (' Recommend item(s):', recommended_items, 'for user', u) Tạo file contentBase.py để thực gợi ý sản phẩm tương tự cho sản phẩm (theo hướng tếp cận content-based filtering) from pyspark import SparkContext, SparkConf Trang 75 from pyspark.sql import SQLContext import findspark import pandas from sklearn.feature_extraction.text import CountVectorizer from sklearn.metrics.pairwise import cosine_similarity from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.metrics.pairwise import linear_kernel #init spark session findspark.init() conf = SparkConf().setAppName("dacn").setMaster("local") sc = SparkContext.getOrCreate() sqlContext = SQLContext(sc) spark_df = sqlContext.read.parquet("hdfs://localhost:9000/topics/dbserver1.inventory.product",header=True ) df = spark_df.toPandas() df = df[~df.index.duplicated(keep='last')] print(df.columns) df['description'] = df['description'].fillna('') tf = TfidfVectorizer(analyzer='word', ngram_range=(1, 3), min_df=0, stop_words='english') tfidf_matrix = tf.fit_transform(df['description']) cosine_similarities = linear_kernel(tfidf_matrix, tfidf_matrix) results = {} for idx, row in df.iterrows(): similar_indices = cosine_similarities[idx].argsort()[:-100:-1] similar_items = [(cosine_similarities[idx][i], df['id'][i]) for i in similar_indices] results[row['id']] = similar_items[1:] print('done!') def item(id): return df.loc[df['id'] == id]['product_name'].tolist()[0].split(' - ')[0] # Just reads the results out of the dictionary def recommend(item_id, num): Trang 76 print("Recommending " + str(num) + " products similar to " + item(item_id) + " ") print(" -") recs = results[item_id][:num] print(recs) result = [] for rec in recs: result.append(rec[1]) # # print("Recommended: " + item(rec[1]) + " (score:" + str(rec[0]) + ")") return result Tạo file app.py với nội dung bên để setup api cho ứng dụng Lấy thông tin từ hdfs lên thông qua spark """ Get product and user from HDFS """ findspark.init() conf = SparkConf().setAppName("dacn").setMaster("local") sc = SparkContext.getOrCreate() sqlContext = SQLContext(sc) spark_df = sqlContext.read.parquet("hdfs://localhost:9000/topics/dbserver1.inventory.product",header=True ) spark_user_df = sqlContext.read.parquet("hdfs://localhost:9000/topics/dbserver1.inventory.customer",header=Tru e) Tiền xử lý liệu để đưa thông tin vào xử lý df = spark_df.toPandas() df = df[~df.index.duplicated(keep='last')] df = df[df['id']

Ngày đăng: 05/09/2021, 20:52

Xem thêm:

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w