Example #1
0
def test_interactions_ds():
    df = pd.DataFrame([
        [1, 1, 2],
        [2, 4, 5],
        [3, 3, 3],
        [3, 6, 1],
    ],
                      columns=['user', 'item', 'interaction'])
    return InteractionDataset.read_df(df)
Example #2
0
def interactions_ds():
    df = pd.DataFrame([
        [1, 2, 3, 100],
        [1, 4, 5, 50],
        [1, 5, 2, 25],
        [2, 2, 5, 100],
        [2, 3, 2, 20],
    ],
                      columns=['user', 'item', 'interaction', 'timestamp'])
    return InteractionDataset.read_df(df)
Example #3
0
def interactions_ds():
    rng = random.Random(0)
    df = pd.DataFrame([[u, i, rng.randint(-1, 5)] for u in range(50)
                       for i in range(200) if rng.randint(0, 4) == 0],
                      columns=['user', 'item', 'interaction'])
    print(df.values)
    return leave_k_out(InteractionDataset.read_df(df),
                       k=5,
                       min_user_interactions=0,
                       last_timestamps=False,
                       seed=10)
Example #4
0
def train_interactions_ds():
    df = pd.DataFrame([
        [1, 2, 3],
        [1, 4, 5],
        [1, 5, 2],
        [2, 2, 5],
        [2, 3, 2],
        [3, 2, 2],
        [3, 5, 5],
        [3, 1, 1],
    ],
                      columns=['user', 'item', 'interaction'])
    return InteractionDataset.read_df(df)
Example #5
0
from DRecPy.Dataset import InteractionDataset
import pandas as pd
from os import remove

# create file with sample dataset
with open('tmp.csv', 'w') as f:
    f.write('users,items,interactions\n')
    f.write('"john","ps4",4.5\n')
    f.write('"patrick","xbox",4.1\n')
    f.write('"anna","brush",3.6\n')
    f.write('"david","tv",2.0\n')

# load dataset into memory
df = pd.read_csv('tmp.csv')
ds_memory = InteractionDataset.read_df(df, user_label='users', item_label='items', interaction_label='interactions')
print('all values:', ds_memory.values_list())

remove('tmp.csv')  # delete previously created sample dataset file