点击日志数据转换成FFM数据格式——CSV2FFM

在用FFM数据时,肯定会问几个问题:1-ffm数据是啥意思,特征中的数据是啥意思啊,例如1:2:0,3:5:1,这种数据本来的真实数据是啥?2-如何将真实数据转成这种格式?转换中肯定会遇到的问题(1)单值与多值特征怎么区别对待?(2)在使用模型训练ffm数据后是否需要特征原来对应的真实数据?(这个问题是跑一个模型就知道了,或许就不是问题)3-模型训练完后如何召回?能不能用faiss

下面先说2-生产数据格式转换

2-1,单值数据转换成FFM数据格式,在kaggle上看到了一个非并行版本

这里面需要了解一个函数make_classification

from sklearn.datasets import make_classification

原来版本是100个samples,注意int是数值型数据,这种数据feature idx肯定都是一样的,而str才是类别型数据,所以value 都是1

这里我的疑问已经被另一个大佬提出来了,为啥不是从0到1进行编码,这个有点难以理解啊。

刚一夸kaggle比逼乎逼格高,特么的就屏蔽我的账号了??卧槽,

我复制个东西,然后粘贴下,提个问题,就这个就屏蔽了??woc,傻逼玩意。【我又注册个账号,重复这种操作,确认了是这个原因,当我想解封时给我提了个问题,如下,

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 2248.,

。。。。kaggle真是任性。】

算了已经进入误区了。折回重来,再看一个版本

下面是kaggle版本和微软版本的对比,如下,10万条数据,kaggle版本转换需要1分钟,而微软版本只需1秒,而且发现两个版本有随数据量线性增长的趋势。所以在时间上已经确定kaggle版本不行了。50万则分别需要305,5.13秒,5千万则可能需要3万秒和500秒,明显是后者了。【实际在服务器上1千万数据,Time 1:3585.653191, 2:65.854875】

微软的版本依旧与合成的数据是一样的,参考XDeepFM踩坑之路。【即编码完一个field的特征,再编码另一个field的特征,这点与libffm中的介绍是不同的,后者是编码完一条数据的特征才开始编码下一条数据中新的特征】

而当为离散型(数值型float)数据时,结果kaggle版本出错,这就不行了。

Origin Data:
    float1  float2  float3 string1 string2  clicked
0  -0.462  -0.587  -1.221     1.0    -0.0        0
1   1.547   1.900  -0.301     0.0     1.0        1
2   0.884   1.068  -1.328    -0.0    -4.0        1
3   1.440   1.777  -0.116     1.0     1.0        1
4   1.425   1.727   0.197    -1.0    -2.0        1
5  -0.925  -1.140   0.209     1.0    -2.0        0
6  -1.597  -1.963   0.738     1.0    -5.0        0
7  -0.763  -0.938  -1.960     1.0    -1.0        1
8  -0.581  -0.721   0.823     1.0    -3.0        0
9  -2.389  -2.895   0.171     1.0     1.0        0
kaggle version:
 0    0 3:33:1 4:38:1
1    1 3:34:1 4:39:1
2    1 3:35:1 4:40:1
3    1 3:33:1 4:39:1
4    1 3:36:1 4:41:1
5    0 3:33:1 4:41:1
6    0 3:33:1 4:42:1
7    1 3:33:1 4:43:1
8    0 3:33:1 4:44:1
9    0 3:33:1 4:39:1
dtype: object 
microsoft version:
    clicked      float1      float2      float3 string1 string2
0        0  1:1:-0.462  2:2:-0.587  3:3:-1.221   4:4:1   5:8:1
1        1   1:1:1.547     2:2:1.9  3:3:-0.301   4:5:1   5:9:1
2        1   1:1:0.884   2:2:1.068  3:3:-1.328   4:6:1  5:10:1
3        1    1:1:1.44   2:2:1.777  3:3:-0.116   4:4:1   5:9:1
4        1   1:1:1.425   2:2:1.727   3:3:0.197   4:7:1  5:11:1
5        0  1:1:-0.925   2:2:-1.14   3:3:0.209   4:4:1  5:11:1
6        0  1:1:-1.597  2:2:-1.963   3:3:0.738   4:4:1  5:12:1
7        1  1:1:-0.763  2:2:-0.938   3:3:-1.96   4:4:1  5:13:1
8        0  1:1:-0.581  2:2:-0.721   3:3:0.823   4:4:1  5:14:1
9        0  1:1:-2.389  2:2:-2.895   3:3:0.171   4:4:1   5:9:1
Time 1:0.010993, 2:0.006997

如何证明这种编码是有效、正确的呢?采用movielens-1M进行FFM模型测试即可

【将评分视为label进行预测,后来发现这种做法在libffm下是不适用的,官方的模型是预测的点击与否,只能将分类结果预测出来,我看看能不能预测评分】

命令行如下:首先分割成train.ffm和test.ffm数据,我将评分除以5进行归一化,但仍旧不行啊,下面是过程及结果

$ ./ffm-train -p test.ffm train.ffm mymodel
First check if the text file has already been converted to binary format (0.0 seconds)
Binary file NOT found. Convert text file to binary file (1.2 seconds)
First check if the text file has already been converted to binary format (0.0 seconds)
Binary file NOT found. Convert text file to binary file (0.3 seconds)
iter   tr_logloss   va_logloss      tr_time
   1      0.43943      0.42538          0.7
   2      0.41742      0.42085          1.4
   3      0.40935      0.41919          2.1
   4      0.40203      0.41849          2.8
   5      0.39509      0.41843          3.5
   6      0.38823      0.41871          4.1
   7      0.38129      0.41931          4.8
   8      0.37428      0.42023          5.5
   9      0.36742      0.42130          6.2
  10      0.36089      0.42281          6.8
  11      0.35491      0.42466          7.5
  12      0.34955      0.42663          8.2
  13      0.34474      0.42882          8.9
  14      0.34051      0.43103          9.5
  15      0.33675      0.43335         10.2

./ffm-predict test.ffm mymodel 'testPred.txt'
logloss = 0.43335

the results are bad enough !!! So will try another method,that is the reference,classify the rating into like and not like

过程及结果如下:

iter   tr_logloss   va_logloss      tr_time
   1      0.56010      0.53802          0.8
   2      0.53190      0.53201          1.4
   3      0.52133      0.52879          2.1
   4      0.51214      0.52717          2.8
   5      0.50332      0.52592          3.5
   6      0.49438      0.52502          4.2
   7      0.48536      0.52439          4.9
   8      0.47661      0.52426          5.6
   9      0.46855      0.52485          6.3
  10      0.46134      0.52603          6.9
  11      0.45504      0.52750          7.6
  12      0.44953      0.52938          8.3
  13      0.44467      0.53141          9.0
  14      0.44038      0.53362          9.7
  15      0.43658      0.53591         10.3

上面的loss发现 验证集第8次已经是最小了,后面的都是过拟合了,涉及早停参数,修改如下:发现并没有很好的改善

又调了一次,仍旧不理想,如下

$ ./ffm-train -p test.ffm -l 0.003 -t 50 --auto-stop train.ffm 
First check if the text file has already been converted to binary format (0.1 seconds)
Binary file found. Skip converting text to binary
First check if the text file has already been converted to binary format (0.0 seconds)
Binary file found. Skip converting text to binary
iter   tr_logloss   va_logloss      tr_time
   1      0.59387      0.55961          0.7
   2      0.55231      0.54819          1.4
   3      0.54301      0.54335          2.1
   4      0.53763      0.54001          2.9
   5      0.53345      0.53745          3.6
   6      0.52979      0.53541          4.3
   7      0.52643      0.53308          5.6
   8      0.52320      0.53075          7.0
   9      0.51999      0.52904          8.4
  10      0.51685      0.52689          9.7
  11      0.51368      0.52503         11.1
  12      0.51064      0.52342         12.5
  13      0.50781      0.52167         13.9
  14      0.50517      0.52049         15.2
  15      0.50270      0.51954         16.6
  16      0.50053      0.51835         18.0
  17      0.49843      0.51757         19.3
  18      0.49654      0.51691         20.7
  19      0.49480      0.51619         22.1
  20      0.49313      0.51561         23.4
  21      0.49159      0.51491         24.8
  22      0.49010      0.51447         26.2
  23      0.48861      0.51429         27.5
  24      0.48730      0.51392         28.9
  25      0.48601      0.51347         30.3
  26      0.48475      0.51321         31.6
  27      0.48354      0.51294         33.0
  28      0.48239      0.51269         34.4
  29      0.48120      0.51249         35.9
  30      0.48011      0.51230         37.6
  31      0.47904      0.51204         39.2
  32      0.47797      0.51186         40.9
  33      0.47698      0.51170         42.5
  34      0.47593      0.51160         44.2
  35      0.47498      0.51153         45.8
  36      0.47400      0.51152         47.4
  37      0.47310      0.51137         48.9
  38      0.47225      0.51115         50.4
  39      0.47131      0.51121
Auto-stop. Use model at 38th iteration.

$ ./ffm-predict test.ffm train.ffm.model 'testPred.txt'logloss = 0.51115

不行啊,无论是这种分类或者看做回归,这种代码与这种数据的结果都是不对的。所以我不知道怎么将movielens-1M的数据代入FFM代码中,这是个问题啊。也没个大佬指点下。人生艰难啊!

待续吧。

 

 

For Video Recommendation in Deep learning QQ Group 277356808

For Speech, Image, Video in deep learning QQ Group 868373192

I'm here waiting for you

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章