當前位置: 首頁>>代碼示例>>Python>>正文


Python data.Data類代碼示例

本文整理匯總了Python中recsys.datamodel.data.Data的典型用法代碼示例。如果您正苦於以下問題:Python Data類的具體用法?Python Data怎麽用?Python Data使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Data類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _convert_hash

 def _convert_hash(self, dataset):
     data = Data()
     for key in dataset:
         record = dataset[key]
         batch = [(record[k], key, k) for k in record]
         data.set(batch, extend=True)
     return data
開發者ID:norbert,項目名稱:fickle,代碼行數:7,代碼來源:recommenders.py

示例2: train_and_save

def train_and_save(filename):

    step = filename.split('.')[-1]

    data = Data()

    format = {'col': 1, 'row': 0, 'value': 2, 'ids': 'str'}
    data.load(filename, sep='::', format=format)

    train, test = data.split_train_test(percent=80)

    try:

        svd = SVD('svdn_model_{step}.zip'.format(step=step))
        print('Already exists: svdn_model_{step}.zip'.format(step=step))

    except:

        svd = SVD()
        svd.set_data(train)

        svd.compute(
            k=100,
            min_values=2,
            pre_normalize=False,
            mean_center=True,
            post_normalize=True,
            savefile='svdn_model_{step}'.format(step=step)
        )

        print('Saved svdn_model_{step}.zip'.format(step=step))
開發者ID:Chuchu2OP,項目名稱:amazon-recsys,代碼行數:31,代碼來源:train.py

示例3: ex1

def ex1(dat_file='./ml-1m/ratings.dat',
        pct_train=0.5):

    data = Data()
    data.load(dat_file, sep='::', format={'col':0, 'row':1, 'value':2,'ids':int})
       

    # create train/test split
    train, test = data.split_train_test(percent=pct_train)

    # create svd
    K=100
    svd = SVD()
    svd.set_data(train)
    svd.compute(k=K, min_values=5, pre_normalize=None, mean_center=True, post_normalize=True)

    # evaluate performance
    rmse = RMSE()
    mae = MAE()
    for rating, item_id, user_id in test.get():
        try:
            pred_rating = svd.predict(item_id, user_id)
            rmse.add(rating, pred_rating)
            mae.add(rating, pred_rating)
        except KeyError:
            continue

    print 'RMSE=%s' % rmse.compute()
    print 'MAE=%s' % mae.compute()
開發者ID:barnettjacob,項目名稱:ga_ds,代碼行數:29,代碼來源:Lec14_RecommendationSystem.py

示例4: Algorithm

class Algorithm(object):
    def __init__(self):
        self._data = Data()

    def __repr__(self):
        s = '%d rows.' % len(self.get_data())
        if len(self.get_data()):
            s += '\nE.g: %s' % str(self.get_data()[0])
        return s

    def __len__(self):
        return len(self.get_data())

    def get_data(self):
        return self._data

    def set_data(self, data):
        self._data = data

    def add_tuple(self, tuple):
        self.get_data().add_tuple(tuple)

    def load_data(self, filename, sep='\t', format={'value':0, 'row':1, 'col':2}):
        self._data.load_file(filename, sep, format)

    def compute(self):
        if not self._data.get():
            raise ValueError('No data set. Matrix is empty!')
開發者ID:luosha865,項目名稱:recsysPlatform,代碼行數:28,代碼來源:baseclass.py

示例5: get_preference

def get_preference(user_List):
    #generate list of users
    
    preference_dict={}
    user_map={}
    data = Data() #saving rating data
    i=1
    for user in user_List:
        user_id=(str(user))
        url = "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?\
key=147CBF377C6B648EC3DC73499CE73D32&steamid="+user+"&format=json"
        response = urllib2.urlopen(url)
        owned_gameData = json.loads(response.read().decode('utf-8-sig'))
        user_Pref={}
        #print (user)
        try: 
            if owned_gameData['response']['game_count']!=0:
                user_Pref={}
                for games in owned_gameData['response']['games']:
                    if games['playtime_forever']>0:
                        user_Pref[games['appid']]= math.log(games['playtime_forever'])
                        data.add_tuple((math.log(games['playtime_forever'], 10), games['appid'], i))
                        user_map[i]=user
        except:
            continue
        i=i+1
        preference_dict[user]=user_Pref
    data.save('rating.dat')
開發者ID:Sapphirine,項目名稱:Game-recommendation-on-Steam,代碼行數:28,代碼來源:game.py

示例6: test_data_extend

def test_data_extend():
    dataset = [(1,2,3), (4,5,6)]
    dataset2 = [(7,8,9), (10,11,12)]
    data = Data()
    data.set(dataset)
    assert_equal(len(data), 2)

    data.set(dataset2, extend=True)
    assert_equal(len(data), 4)
開發者ID:1060460048,項目名稱:python-recsys,代碼行數:9,代碼來源:test_datamodel.py

示例7: load_ratings

def load_ratings(filename):
    """ Load ratings
    """
    
    data = Data()
    format = {'col':0, 'row':1, 'value':2, 'ids': 'int'}
    data.load(filename, sep=',', format=format)
    
    return data
開發者ID:srikanth3569,項目名稱:movie,代碼行數:9,代碼來源:utils.py

示例8: build_model

	def build_model(self,uids,kn):
		data = Data()
		for uid,songs in uids.items():
			for song in songs:
				data.add_tuple((1,song,uid))
		svd = SVD()
		svd.set_data(data)
		svd.compute(k=kn,min_values=1)
		self.model = svd
開發者ID:micolin,項目名稱:thesis,代碼行數:9,代碼來源:svd.py

示例9: getAverageRating

def getAverageRating(ITEMID):
    averageRating = 0
    totalUsers = 0
    data = Data()
    data.load('./data/movielens/ratings.dat', sep='::', format={'col':0, 'row':1, 'value':2, 'ids':int})
    for rating, item_id, user_id in data.get():
        if(item_id == ITEMID):
            totalUsers += 1
            averageRating += rating
    print averageRating/totalUsers
開發者ID:udaysagar2177,項目名稱:predictMovieRatings,代碼行數:10,代碼來源:main.py

示例10: calculate_stats_features

def calculate_stats_features(pct_train):
    dat_file='feature_matrix.csv'
    data = Data()
    data.load(dat_file, sep=',', format={'col':0, 'row':1, 'value':2,'ids':int})
    train, test = data.split_train_test(percent=pct_train)               
    K=100
    svd = SVD()
    svd.set_data(train)
    svd.compute(k=K, min_values=0, pre_normalize=None, mean_center=False,
    post_normalize=False)
    return svd,train,test
開發者ID:setman85,項目名稱:Rest_Recs,代碼行數:11,代碼來源:rec2.py

示例11: get_data_model_matrix

def get_data_model_matrix(data):
    """
    This method process raw data and store rating/users/movies in a matrix <value/row/column> respectively
    using recsys library
    :return: data object (recsys.datamodel.Data()) )
    """
    processed_data = Data()
    for user, review in data.items():
        for mov, rat in review.items():
            processed_data.add_tuple((rat, user, mov))
    return processed_data
開發者ID:LaPetiteSouris,項目名稱:Collective_Intelligence,代碼行數:11,代碼來源:modellingdata.py

示例12: get_friend_matrix

def get_friend_matrix(u_ids, raw_data):
    idata = Data()
    u_idx = 0
    for u_id in u_ids:
        u_idx += 1
        i_idx = 0
        i_ids = raw_data[u_id].keys()
        for i_id in i_ids:
            i_idx += 1
            rate, ts = raw_data[u_id][i_id]
            idata.add_tuple((float(rate),u_idx,i_idx))

    return idata
開發者ID:wanghs09,項目名稱:Experiments,代碼行數:13,代碼來源:tmp_svd.py

示例13: prepare_data

def prepare_data(raw_data):
    idata = Data()
    u_idx = 0
    for u_id in raw_data.keys():
        i_idx = 0
        u_idx += 1
        pre_u_raw_data = raw_data[u_id]
        for i_id in pre_u_raw_data.keys():
            i_idx += 1
            rate, _ = pre_u_raw_data[i_id]
            idata.add_tuple((float(rate),u_idx,i_idx))

    return idata
開發者ID:wanghs09,項目名稱:Experiments,代碼行數:13,代碼來源:svd_tmp.py

示例14: setup_svd

    def setup_svd(self, vote_list):
        if self.svd is None:
            self.cache['svd'] = SVD()
            data = Data()

            for vote in vote_list:
                user_id = vote[0].id
                item_id = vote[1]
                value = float(vote[2])
                data.add_tuple((value, item_id, user_id))  # Tuple format is: <value, row, column>
            self.cache['svd'].set_data(data)
            self.cache['svd'].compute(k=self.k, min_values=1)
        return self.svd
開發者ID:AlinaKay,項目名稱:django-recommends,代碼行數:13,代碼來源:pyrecsys.py

示例15: setUp

 def setUp(self):
     
     data = Data()
     for stars, item_id, user_id in ratings:
         data.add_tuple((stars, item_id, user_id))
     
     movies = dict()
     for mid, name, genres in movie_genres:
         movie = Item(mid)
         movie.add_data({'name': name, 'genres': genres})
         movies[mid] = movie
     
     self.ratings = data
     self.movies = movies
開發者ID:zermelozf,項目名稱:clrec,代碼行數:14,代碼來源:test.py


注:本文中的recsys.datamodel.data.Data類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。