dimanche 27 novembre 2016

Python - Sample from 'x' lists with different distribution

In the following code, I've created a list of items and users. I've seperated the items to 3 different lists of very popular, popular and regular items.

import numpy as np


N_USERS = 20000
N_ITEMS = 1000

items = range(0, N_ITEMS)
users = range(0, N_USERS)

vpop = int(len(items)*0.1)
pop = int(len(items)*0.3)

np.random.shuffle(items)
vpop_items = items[:vpop]
pop_items = items[vpop:pop]
reg_items = items [pop:]

I want to sample X samples from those lists with different distribution. For example:

list_of_items = sample(vpop_items, pop_items, reg_items, p = [0.5, 0.35, 0.15], X)

where X is the number of samples I want to make. and P is the list of distributions corespond with the lists (vpop_items, pop_items, reg_items).




Aucun commentaire:

Enregistrer un commentaire