netflix 推荐算法学习1(转)

http://www.csie.ntu.edu.tw/~r95007/thesis/svdnetflix/report/report.pdf
http://eecs.wsu.edu/~vjakkula/MLProject.pdf
http://michielvanwezel.com/papers/kagie_vdloos_vwezelV2.pdf
http://cseweb.ucsd.edu/users/elkan/KddNetflixWorkshop.pdf
http://www.cs.uic.edu/~liub/KDD-cup-2007/proceedings/The-Netflix-Prize-Bennett.pdf

准备数据集
1shell 将所有测试数据集文件合并为一个文件
#!/bin/bash
for x in netflix/training_set/mv_*.txt ;
 do cat $x >> ratings.txt ;
done &

http://www.netflixprize.com/community/viewtopic.php?id=87
需要下载path模块
#!/usr/bin/env python

import sys
import csv
from path import path

NULL = '\N'

class Dialect(csv.excel):
    delimiter = '\t'
    lineterminator = '\n'
    doublequote = False
    escapechar = None
    quoting = csv.QUOTE_MINIMAL

def csvDump(iter_rows_func, basename, dir='.', csvdir='csv', dialect=Dialect):
    dir,csvdir = path(dir),path(csvdir)
    if not csvdir.exists():
        csvdir.mkdir()
    inpath = dir/basename
    outfile = csvdir/inpath.namebase + '.csv'
    if not outfile.exists():
        write = csv.writer(open(outfile, 'wb'), dialect).writerow
        print >> sys.stderr, 'Writing %s ...' % outfile
        for row in iter_rows_func(inpath):
            write(row)

def iterMovieRows(path):
    for line in open(path):
        id,year,title = line.rstrip().split(',',2)
        year = year!='NULL' and int(year) or NULL
        yield (int(id), year, title)

def iterTrainingSetRows(dir):
    for path in dir.walkfiles():
        iterlines = (line.strip() for line in open(path))
        movie_id = int(iterlines.next()[:-1])
        for line in iterlines:
            user_id,rating,date = line.split(',',2)
            yield (movie_id, int(user_id), date, float(rating))

def iterProbeSetRows(path):
    for line in (line.strip() for line in open(path)):
        try:
            user_id = int(line)
        except ValueError:
            movie_id = int(line[:-1])
        else:
            yield (movie_id,user_id)

def iterQualifyingSetRows(path):
    for line in (line.strip() for line in open(path)):
        try:
            user_id,date = line.split(',')
        except ValueError:
            movie_id = int(line[:-1])
        else:
            yield (movie_id,user_id,date)


if __name__ == '__main__':
    kwds = {}
    if len(sys.argv) > 1:
        kwds['dir'] = sys.argv[1]
    if len(sys.argv) > 2:
        kwds['csvdir'] = sys.argv[2]
    for iterfunc, basename in [
        (iterMovieRows,         'movie_titles.txt'),
        (iterTrainingSetRows,   'training_set'),
        (iterProbeSetRows,      'probe.txt'),
        (iterQualifyingSetRows, 'qualifying.txt')]:
            csvDump(iterfunc, basename, **kwds)
            
perl脚本     
#!/usr/bin/perl

use strict;

my $dir = '/path/to/your/training_set';
opendir DIR, $dir or die("could not open $dir");

while(my $fname = readdir DIR) {
        my $fname = "$dir/$fname";
        open FILE, $fname or die("could not open $fname");
        (my $mid = <FILE>) =~ s/:.*//s;
        while(<FILE>) {
                chomp;
                print qq("$mid",);
                map { print qq("$_",) } split /,/;
                print "\n";
        }
        close FILE;
}
closedir DIR;
exit;

$ time ./bigcsv.pl > bigcsv.csv

real    35m11.521s
user    10m36.272s
sys     4m9.940s

mysql> LOAD DATA INFILE 'bigcsv.csv' INTO TABLE main FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
Query OK, 100480507 rows affected (5 min 34.39 sec)
Records: 100480507  Deleted: 0  Skipped: 0  Warnings: 0
著名的Netflix 智能推荐 百万美金大奖赛使用是数据集. 因为竞赛关闭, Netflix官网上已无法下载. Netflix provided a training data set of 100,480,507 ratings that 480,189 users gave to 17,770 movies. Each training rating is a quadruplet of the form . The user and movie fields are integer IDs, while grades are from 1 to 5 (integral) stars.[3] The qualifying data set contains over 2,817,131 triplets of the form , with grades known only to the jury. A participating team's algorithm must predict grades on the entire qualifying set, but they are only informed of the score for half of the data, the quiz set of 1,408,342 ratings. The other half is the test set of 1,408,789, and performance on this is used by the jury to determine potential prize winners. Only the judges know which ratings are in the quiz set, and which are in the test set—this arrangement is intended to make it difficult to hill climb on the test set. Submitted predictions are scored against the true grades in terms of root mean squared error (RMSE), and the goal is to reduce this error as much as possible. Note that while the actual grades are integers in the range 1 to 5, submitted predictions need not be. Netflix also identified a probe subset of 1,408,395 ratings within the training data set. The probe, quiz, and test data sets were chosen to have similar statistical properties. In summary, the data used in the Netflix Prize looks as follows: Training set (99,072,112 ratings not including the probe set, 100,480,507 including the probe set) Probe set (1,408,395 ratings) Qualifying set (2,817,131 ratings) consisting of: Test set (1,408,789 ratings), used to determine winners Quiz set (1,408,342 ratings), used to calculate leaderboard scores For each movie, title and year of release are provided in a separate dataset. No information at all is provided about users. In order to protect the privacy of customers, "some of the rating data for some customers in the training and qualifyin
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值