i am performing some operation on some datasets for recommendation with images and…
- User
i am performing some operation on some datasets for recommendation with images and attributes and review. i have an item-attribute dataset where the first column is the 'asin' of the images and the other columns are the onehot attributes. the original test,train and val dataset have a column named 'asin' which defines the ID of the images and the other two columns. what i want to obtain is to have the exact correspondence between the original train+test+val csv files and the other item-attribute tsv file, in order to perform correctly the operation.
the following is the code for mapping, where i map the original asin to something else. i want you to automatize the mapping with the "synchronization" of the dataset
import numpy as np import pandas as pd import os import argparse
parser = argparse.ArgumentParser(description="Mapping config.") parser.add_argument('--folder_name', type=str, help="folder name.", required=True) args = parser.parse_args()
train = pd.read_csv('train.tsv', sep='\t', header=None) val = pd.read_csv('val.tsv', sep='\t', header=None) test = pd.read_csv('test.tsv', sep='\t', header=None) attributes = pd.read_csv('item_attributes_filtered.tsv', sep='\t', header=None)
df = pd.concat([train, val, test], axis=0)
users = df[0].unique() items = df[1].unique()
users_map = {u: idx for idx, u in enumerate(users)} items_map = {i: idx for idx, i in enumerate(items)}
items_map_csv = pd.DataFrame(list(items_map.items()), columns=['ID', 'Value']) items_map_csv.to_csv(f'items_map.tsv', sep='\t', index=False)
train[0] = train[0].map(users_map) train[1] = train[1].map(items_map)
val[0] = val[0].map(users_map) val[1] = val[1].map(items_map)
test[0] = test[0].map(users_map) test[1] = test[1].map(items_map)
attributes[0] = attributes[0].map(items_map).astype(int)
train.to_csv('train_indexed.tsv', sep='\t', index=False, header=None) val.to_csv('val_indexed.tsv', sep='\t', index=False, header=None) test.to_csv('test_indexed.tsv', sep='\t', index=False, header=None) attributes.to_csv('item_attributes_filtered_indexed.tsv', sep='\t', index=False, header=None)
these are some code operation that was made in order to go from item_attribute.tsv file to the item_attribute_filtered.tsv file to the item_attribute_filtered_indexed file.
So, can you perform everything in the same file in the most correct possible way? keep it simple, follow strictly the original code
- Assistant