text_plain_output_1.png
import pandas as pd

from fastai.tabular.all import *
pd.options.display.float_format = '{:.2f}'.format
set_seed(42)

data = pd.read_csv('../input/medias-cost-prediction-in-foodmart/media prediction and its cost.csv')

Name = sorted(data['class'].unique().tolist())
N = list(range(len(Name)))
normal_mapping = dict(zip(Name, N))
reverse_mapping = dict(zip(N, Name))

data = data.drop('cost', axis=1)

m = len(data)
M = list(range(m))
random.seed(2021)
random.shuffle(M)

train = data.iloc[M[0:m // 4 * 3]]
test = data.iloc[M[m // 4 * 3:]]
testY = test['class'].map(normal_mapping)

splits = RandomSplitter(seed=42)(train)

dls = TabularPandas(train, splits=splits, cat_names=['food_category', 'food_department', 'food_family', 'promotion_name', 'sales_country', 'marital_status', 'gender', 'education', 'member_card', 'occupation', 'houseowner', 'avg. yearly_income', 'brand_name', 'store_type', 'store_city', 'store_state', 'media_type'], cont_names=['store_sales(in millions)', 'store_cost(in millions)', 'unit_sales(in millions)', 'total_children', 'avg_cars_at home(approx)', 'num_children_at_home', 'avg_cars_at home(approx).1', 'SRP', 'gross_weight', 'net_weight', 'recyclable_package', 'low_fat', 'units_per_case', 'store_sqft', 'grocery_sqft', 'frozen_sqft', 'meat_sqft', 'coffee_bar', 'video_store', 'salad_bar', 'prepared_food', 'florist'], y_names='class', y_block=CategoryBlock(), procs=[Categorify, FillMissing, Normalize]).dataloaders(path='.')
dls

learn = tabular_learner(dls, layers=[200, 100], metrics=accuracy)
learn