處理稀疏性

用 Python 建立推薦引擎

Rob O'Callaghan

Director of Data

稀疏矩陣

小型非稀疏矩陣

用 Python 建立推薦引擎

稀疏矩陣

小型非稀疏矩陣與大型稀疏矩陣

用 Python 建立推薦引擎

稀疏矩陣

小型非稀疏矩陣與大型稀疏矩陣

用 Python 建立推薦引擎

衡量稀疏性

print(book_rating_df)
title     The Great Gatsby    The Catcher in the Rye    Fifty Shades of Grey
User                    
User_233               3.0                       NaN                     NaN
User_651               NaN                       5.0                     4.0
User_965               4.0                       3.0                     NaN
     ...               ...                       ...                     ...
用 Python 建立推薦引擎

衡量稀疏性

number_of_empty = book_ratings_df.isnull().values.sum()

total_number = user_ratings_df.size
sparsity = number_of_empty/total_number
print(sparsity)
0.0114
用 Python 建立推薦引擎

為什麼稀疏性重要

大型稀疏矩陣

用 Python 建立推薦引擎

為什麼稀疏性重要

大型稀疏矩陣,空白格標示

用 Python 建立推薦引擎

為什麼稀疏性重要

大型稀疏矩陣,最近的非空鄰居標示

用 Python 建立推薦引擎

為什麼稀疏性重要

大型稀疏矩陣,最近的非空鄰居標示

用 Python 建立推薦引擎

逐欄衡量稀疏性

user_ratings_df.notnull().sum()
The Pelican Brief                           1
Snow Crash                                  1
The Great Gatsby                           12
Fifty Shades of Grey                        9
Leviathan                                   1
                                           ..
用 Python 建立推薦引擎

矩陣分解

大型稀疏矩陣

用 Python 建立推薦引擎

矩陣分解

大型稀疏矩陣與其分解後的因子

用 Python 建立推薦引擎

矩陣分解

大型稀疏矩陣、其因子與補齊後的大型矩陣

用 Python 建立推薦引擎

矩陣相乘

兩個長方形矩陣

用 Python 建立推薦引擎

矩陣相乘

兩個長方形矩陣

用 Python 建立推薦引擎

矩陣相乘

兩個長方形矩陣

用 Python 建立推薦引擎

矩陣相乘

兩個長方形矩陣

用 Python 建立推薦引擎

矩陣相乘

兩個長方形矩陣與其相乘所得較大矩陣

用 Python 建立推薦引擎

矩陣相乘

print(matrix_x)
[[4, 1], 
 [2, 2], 
 [3, 3]]
print(matrix_b)
[[1, 0, 4], 
 [0, 1, 6]]
用 Python 建立推薦引擎

矩陣相乘

import numpy as np

dot_product = np.dot(matrix_x, matrix_b)
print(dot_product)
[[ 4  1 22]
 [ 2  2 20]
 [ 3  3 30]]
用 Python 建立推薦引擎

一起來練習吧!

用 Python 建立推薦引擎

Preparing Video For Download...