R特性哈希:hashed.model.matrix中的额外值 总结

R特性哈希:hashed.model.matrix中的额外值 总结,r,matrix,machine-learning,R,Matrix,Machine Learning,为什么FeatureHashing生成的hashed.model矩阵在第1列中总是有一个“勾号”(即类似于1或2或更多的条目) 细节 深入研究散列对一些简单数据的作用,我发现 我无法解释的是:为什么会产生 矩阵是否为每个记录包含1个额外值?(始终在第1列中) 数据: library(FeatureHashing) df=data.frame( soup=c('broth','pea','tomato','pea','broth'), main=c( 'fries'

为什么FeatureHashing生成的hashed.model矩阵在第1列中总是有一个“勾号”(即类似于1或2或更多的条目)

细节 深入研究散列对一些简单数据的作用,我发现 我无法解释的是:为什么会产生 矩阵是否为每个记录包含1个额外值?(始终在第1列中)

数据:

library(FeatureHashing)
df=data.frame( soup=c('broth','pea','tomato','pea','broth'),
               main=c( 'fries', 'potato', 'fries', 'rice','rice') )

> df
    soup   main
1  broth  fries
2    pea potato
3 tomato  fries
4    pea   rice
5  broth   rice
生成哈希矩阵:

m=hashed.model.matrix(~.,data=df,hash.size=16,signed.hash=FALSE,
                      create.mapping=TRUE)

5 x 16 sparse Matrix of class "dgCMatrix"
   [[ suppressing 16 column names ‘1’, ‘2’, ‘3’ ... ]]

[1,] 1 . . . . . 1 . . . . . . . 1 .
[2,] 2 . . . . . . . . . . . 1 . . .
[3,] 1 . 1 . . . . . . . . . . . 1 .
[4,] 1 . . . . . . . 1 . . . 1 . . .
[5,] 1 . . . . . 1 . 1 . . . . . . .
显示映射:

hash.mapping(m)

mainrice mainpotato  mainfries    souppea  soupbroth souptomato  
       9          1         15         13          7          3  
现在,使用上面的映射手动转换数据帧df中的第一行:第1行有soupbroth->7和mainfries->15。因此,我们预计第7列和第15列中会出现一个勾号

查看矩阵,第1行:

[1,] 1 . . . . . 1 . . . . . . . 1 .
我们确实在第7列和第15列中发现了一个勾号,但在第1列中也发现了一个额外的勾号。 事实上,列1的所有行都有一个记号这是从哪里来的?这是干什么用的?


备注:记录如下:“R版本3.2.1(2015-06-18)”/FeatureHashing_0.9第一列是截距,在许多ML包中也称为偏差项

例如:


m1=模型矩阵(~,df)

如您所见,
m1
的第一列名为intercept,其所有值均为
1

如果要删除截取列,请尝试:


m=散列的.model.matrix(~-1,…)

勾号是指逗号(,)?如果是这样的话,这就是矩阵对象的标准符号(例如参见
matrix(1:9,nrow=3)
。要了解更多关于对象表示的信息,请参见
matrix
包,该包借出了
FeatureHashing
中使用的对象。不,不是逗号。类似于1或2(或更大)的条目,我不希望出现。