-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 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,7 @@ | ||
import os.path as osp | ||
|
||
from torch_frame.datasets import Mercari | ||
|
||
path = osp.join(osp.dirname(osp.realpath(__file__)), '..', 'data') | ||
dataset = Mercari(root=path) | ||
print(dataset.df) |
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
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,39 @@ | ||
import os.path as osp | ||
|
||
import pandas as pd | ||
|
||
import torch_frame | ||
from torch_frame.utils.split import SPLIT_TO_NUM | ||
|
||
|
||
class Mercari(torch_frame.data.Dataset): | ||
base_url = 'https://data.pyg.org/datasets/tables/mercari_price_suggestion/' | ||
files = ['train', 'test', 'test_stg2'] | ||
|
||
def __init__(self, root: str): | ||
self.dfs = dict() | ||
col_to_stype = { | ||
'name': torch_frame.text_embedded, | ||
'item_condition_id': torch_frame.categorical, | ||
'category_name': torch_frame.categorical, | ||
'brand_name': torch_frame.categorical, | ||
'price': torch_frame.numerical, | ||
'shipping': torch_frame.categorical, | ||
'item_description': torch_frame.text_embedded | ||
} | ||
for file in self.files: | ||
if file == 'test': | ||
split = 'val' | ||
elif file == 'test_stg2': | ||
split = 'test' | ||
else: | ||
split = 'train' | ||
self.dfs[split] = pd.read_csv( | ||
self.download_url(osp.join(self.base_url, file + '.csv'), | ||
root)) | ||
df = pd.concat(self.dfs.values(), keys=self.dfs.keys(), | ||
names=['split']).reset_index(level=0) | ||
df['split'] = df['split'].map(SPLIT_TO_NUM) | ||
df.drop(['train_id', 'test_id'], axis=1, inplace=True) | ||
super().__init__(df, col_to_stype, target_col='price', | ||
split_col='split') |