<s> """<STR_LIT>""" <EOL> from os . path import dirname <EOL> from os . path import join <EOL> import numpy as np <EOL> class Bunch ( dict ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> dict . __init__ ( self , kwargs ) <EOL> self . __dict__ = self <EOL> def load_movielens_r100k ( load_timestamp = False ) : <EOL> """<STR_LIT>""" <EOL> base_dir = join ( dirname ( __file__ ) , '<STR_LIT>' ) <EOL> if load_timestamp : <EOL> data_m = np . loadtxt ( base_dir + '<STR_LIT>' , <EOL> delimiter = '<STR_LIT:\t>' , dtype = int ) <EOL> data_movies = { } <EOL> for user_id , item_id , rating , timestamp in data_m : <EOL> data_movies . setdefault ( user_id , { } ) <EOL> data_movies [ user_id ] [ item_id ] = ( timestamp , int ( rating ) ) <EOL> else : <EOL> data_m = np . loadtxt ( base_dir + '<STR_LIT>' , <EOL> delimiter = '<STR_LIT:\t>' , usecols = ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ) , dtype = int ) <EOL> data_movies = { } <EOL> for user_id , item_id , rating in data_m : <EOL> data_movies . setdefault ( user_id , { } ) <EOL> data_movies [ user_id ] [ item_id ] = int ( rating ) <EOL> data_titles = np . loadtxt ( base_dir + '<STR_LIT>' , <EOL> delimiter = '<STR_LIT:|>' , usecols = ( <NUM_LIT:0> , <NUM_LIT:1> ) , dtype = str ) <EOL> data_t = [ ] <EOL> for item_id , label in data_titles : <EOL> data_t . append ( ( int ( item_id ) , label ) ) <EOL> data_titles = dict ( data_t ) <EOL> fdescr = open ( dirname ( __file__ ) + '<STR_LIT>' ) <EOL> return Bunch ( data = data_movies , item_ids = data_titles , <EOL> user_ids = None , DESCR = fdescr . read ( ) ) <EOL> def load_sample_songs ( ) : <EOL> """<STR_LIT>""" <EOL> base_dir = join ( dirname ( __file__ ) , '<STR_LIT>' ) <EOL> data_m = np . loadtxt ( base_dir + '<STR_LIT>' , <EOL> delimiter = '<STR_LIT:U+002C>' , dtype = str ) <EOL> item_ids = [ ] <EOL> user_ids = [ ] <EOL> data_songs = { } <EOL> for user_id , item_id , rating in data_m : <EOL> if user_id not in user_ids : <EOL> user_ids . append ( user_id ) <EOL> if item_id not in item_ids : <EOL> item_ids . append ( item_id ) <EOL> u_ix = user_ids . index ( user_id ) + <NUM_LIT:1> <EOL> i_ix = item_ids . index ( item_id ) + <NUM_LIT:1> <EOL> data_songs . setdefault ( u_ix , { } ) <EOL> data_songs [ u_ix ] [ i_ix ] = float ( rating ) <EOL> data_t = [ ] <EOL> for no , item_id in enumerate ( item_ids ) : <EOL> data_t . append ( ( no + <NUM_LIT:1> , item_id ) ) <EOL> data_titles = dict ( data_t ) <EOL> data_u = [ ] <EOL> for no , user_id in enumerate ( user_ids ) : <EOL> data_u . append ( ( no + <NUM_LIT:1> , user_id ) ) <EOL> data_users = dict ( data_u ) <EOL> fdescr = open ( dirname ( __file__ ) + '<STR_LIT>' ) <EOL> return Bunch ( data = data_songs , item_ids = data_titles , <EOL> user_ids = data_users , DESCR = fdescr . read ( ) ) <EOL> def load_sample_movies ( ) : <EOL> """<STR_LIT>""" <EOL> base_dir = join ( dirname ( __file__ ) , '<STR_LIT>' ) <EOL> data_m = np . loadtxt ( base_dir + '<STR_LIT>' , <EOL> delimiter = '<STR_LIT:;>' , dtype = str ) <EOL> item_ids = [ ] <EOL> user_ids = [ ] <EOL> data_songs = { } <EOL> for user_id , item_id , rating in data_m : <EOL> if user_id not in user_ids : <EOL> user_ids . append ( user_id ) <EOL> if item_id not in item_ids : <EOL> item_ids . append ( item_id ) <EOL> u_ix = user_ids . index ( user_id ) + <NUM_LIT:1> <EOL> i_ix = item_ids . index ( item_id ) + <NUM_LIT:1> <EOL> data_songs . setdefault ( u_ix , { } ) <EOL> data_songs [ u_ix ] [ i_ix ] = float ( rating ) <EOL> data_t = [ ] <EOL> for no , item_id in enumerate ( item_ids ) : <EOL> data_t . append ( ( no + <NUM_LIT:1> , item_id ) ) <EOL> data_titles = dict ( data_t ) <EOL> data_u = [ ] <EOL> for no , user_id in enumerate ( user_ids ) : <EOL> data_u . append ( ( no + <NUM_LIT:1> , user_id ) ) <EOL> data_users = dict ( data_u ) <EOL> fdescr = open ( dirname ( __file__ ) + '<STR_LIT>' ) <EOL> return Bunch ( data = data_songs , item_ids = data_titles , <EOL> user_ids = data_users , DESCR = fdescr . read ( ) ) </s>
