Skip to content

Commit

Permalink
Load custom data from .csv
Browse files Browse the repository at this point in the history
Process to follow:
1. Install spotlight using virtualenv PR: maciejkula#123
2. run python setpy.py install
  • Loading branch information
ankit1k committed Apr 2, 2020
1 parent 9e3f870 commit 60297f6
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions spotlight/datasets/custom_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
Utilities for fetching the custom dataset from local filepath.
"""

import os

#import h5py
import numpy as np
import torch

from spotlight.datasets import _transport
from spotlight.interactions import Interactions

def _get_custom_dataset(dataset):
extension = '.csv'
URL_PREFIX = '/home/***/****/*****/********2017_05_01/'

data = np.genfromtxt(URL_PREFIX + dataset + extension, delimiter=',', names=True, dtype=(int, int, int, int))

user_ids = data['user_id']
product_ids = data['product_id']
ratings = data['product_id_total_orders']

return (user_ids, product_ids, ratings)

def get_dataset(datafile):
"""
Returns
-------
Interactions: :class:`spotlight.interactions.Interactions`
instance of the interactions class
"""

url = datafile

return Interactions(*_get_custom_dataset(url))

0 comments on commit 60297f6

Please sign in to comment.