@@ -0,0 +1,1499 @@
+#!/usr/bin/env python3%0A###############################################################################%0A #  Copyright (c) 2015 Jamis Hoo%0A #  Distributed under the MIT license %0A #  (See accompanying file LICENSE or copy at http://opensource.org/licenses/MIT)%0A #  %0A #  Project: %0A #  Filename: preprocess.py %0A #  Version: 1.0%0A #  Author: Jamis Hoo%0A #  E-mail: hoojamis@gmail.com%0A #  Date: Jul 18, 2015%0A #  Time: 21:21:16%0A #  Description: %0A###############################################################################%0Aimport os%0A%0Ainput_data_path = %22netflix/training_set%22%0Aoutput_data_path = %22canopy_input%22%0A%0Afiles = os.listdir(input_data_path)%0A%0Aoutput_handler = open(output_data_path, %22w%22)%0A%0Amovie_id = None%0Auser_ratings = %22%22%0A%0Acounter = 0%0A%0A# for each file in this dir%0Afor filename in files:%0A    # if is a data file%0A    if filename%5B0: 3%5D != %22mv_%22 or filename%5B-4: %5D != %22.txt%22:%0A        continue%0A%0A    input_handler = open(input_data_path + %22/%22 + filename)%0A%0A    # extract movie id%0A    movie_id = input_handler.readline()%5B: -2%5D%0A%0A    # extract user_ids and corresponding ratings%0A    for user_line in input_handler.readlines():%0A        user_id_rating_date = user_line.split(%22,%22)%0A        user_id = user_id_rating_date%5B0%5D%0A        rating = user_id_rating_date%5B1%5D%0A        user_ratings += str(user_id) + %22,%22 + str(rating) + %22,%22%0A    %0A    output_handler.write(movie_id + %22:%22 + user_ratings%5B: -1%5D + %22%5Cn%22)%0A    user_ratings = %22%22%0A%0A    counter = counter + 1%0A    if counter %25 128 == 0:%0A        print(counter, %22/%22, len(files))%0A%0A

add preprocess program