5
我有一個(對稱)鄰接矩陣,它是根據報紙文章(例如:a,b,c等)中名稱(例如:Greg,Mary,Sam,Tom) d)。見下文。電梯價值計算
如何爲非零矩陣元素(http://en.wikipedia.org/wiki/Lift_(data_mining))計算提升值?
我會對有效的實現感興趣,它也可以用於非常大的矩陣(例如,一百萬個非零元素)。
我很感激任何幫助。
# Load package
library(Matrix)
# Data
A <- new("dgTMatrix"
, i = c(2L, 2L, 2L, 0L, 3L, 3L, 3L, 1L, 1L)
, j = c(0L, 1L, 2L, 0L, 1L, 2L, 3L, 1L, 3L)
, Dim = c(4L, 4L)
, Dimnames = list(c("Greg", "Mary", "Sam", "Tom"), c("a", "b", "c", "d"))
, x = c(1, 1, 1, 1, 1, 1, 1, 1, 1)
, factors = list()
)
# > A
# 4 x 4 sparse Matrix of class "dgTMatrix"
# a b c d
# Greg 1 . . .
# Mary . 1 . 1
# Sam 1 1 1 .
# Tom . 1 1 1
# One mode projection of the data
# (i.e. final adjacency matrix, which is the basis for the lift value calculation)
A.final <- tcrossprod(A)
# > A.final
# 4 x 4 sparse Matrix of class "dsCMatrix"
# Greg Mary Sam Tom
# Greg 1 . 1 .
# Mary . 2 1 2
# Sam 1 1 3 2
# Tom . 2 2 3