예제 #1
0
파일: ml_data.py 프로젝트: yichenluan/CSRec
def build_genre_dict():
    f_path = forhead_path + 'u.genre'
    f_content = read_file(f_path)
    genre = [line.split('|') for line in f_content]
    for g in genre:
        g[-1] = int(g[-1][:-1])
    genre_dict = dict([g[-1], g[0]] for g in genre)
    return genre_dict
예제 #2
0
def build_rating_data(data_path):
    f_content = read_file(data_path)
    rating_data = list()
    for line in f_content:
        line_data = line.split(' ')
        rating_data.append(
            [int(line_data[0]),
             int(line_data[1]),
             float(line_data[2])])
    return rating_data
예제 #3
0
파일: ml_data.py 프로젝트: yichenluan/CSRec
def build_user_data():
    f_path = forhead_path + 'u.user'
    f_content = read_file(f_path)
    user = [line.split('|')[:-1] for line in f_content]

    def format_user_data(line):
        line[0] = int(line[0])
        line[1] = int(line[1])
        return line

    user_data = map(format_user_data, user)
    return user_data
예제 #4
0
파일: ml_data.py 프로젝트: yichenluan/CSRec
def build_item_data():
    f_path = forhead_path + 'u.item'
    f_content = read_file(f_path)
    item = [line.split('|') for line in f_content]

    def format_item_data(line):
        line[-1] = line[-1].strip()
        genre = [int(g) for g in line[5:]]
        line = line[:3]
        line.append(genre)
        return line

    item_data = map(format_item_data, item)
    return item_data
예제 #5
0
파일: ml_data.py 프로젝트: yichenluan/CSRec
def build_occupation_data():
    f_path = forhead_path + 'u.occupation'
    f_content = read_file(f_path)
    occupation = [line[:-1] for line in f_content]
    return occupation
예제 #6
0
파일: ml_data.py 프로젝트: yichenluan/CSRec
def build_ml_data(data_path):
    f_content = read_file(data_path)
    ml_data = [[int(i) for i in line.split('\t')] for line in f_content]
    return ml_data
예제 #7
0
def build_trust_data():
    f_path = forhead_path + 'trust.txt'
    f_content = read_file(f_path)
    trust_data = [[int(i) for i in line.split(' ')] for line in f_content]
    return trust_data
예제 #8
0
def build_rating_data(data_path):
    f_content = read_file(data_path)[1:-1]
    rating_data = [[int(i) for i in line.split(' ')] for line in f_content]
    return rating_data