forked from maciejkula/spotlight
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Process to follow: 1. Install spotlight using virtualenv PR: maciejkula#123 2. run python setpy.py install
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |