In [ ]:
from fastai.tabular import * # Quick accesss to tabular functionality
Tabular data should be in a Pandas DataFrame
.
In [ ]:
path = untar_data(URLs.ADULT_SAMPLE)
df = pd.read_csv(path/'adult.csv')
In [ ]:
df['salary'].unique()
Out[ ]:
In [ ]:
# function import
from fastai.utils.mem import *
In [ ]:
# other function teset
gpu_with_max_free_mem()
Out[ ]:
In [ ]:
# test reduce_mem_usage(df)
In [ ]:
df.head()
Out[ ]:
In [ ]:
dep_var = 'salary'
cat_names = ['workclass', 'education', 'marital-status', 'occupation', 'relationship', 'race']
cont_names = ['age', 'fnlwgt', 'education-num']
procs = [FillMissing, Categorify, Normalize]
In [ ]:
test = TabularList.from_df(df.iloc[800:1000].copy(), path=path, cat_names=cat_names, cont_names=cont_names)
In [ ]:
data = (TabularList.from_df(df, path=path, cat_names=cat_names, cont_names=cont_names, procs=procs)
.split_by_idx(list(range(800,1000)))
.label_from_df(cols=dep_var)
.add_test(test)
.databunch())
In [ ]:
data.show_batch(rows=10)
In [ ]:
learn = tabular_learner(data, layers=[200,100], metrics=accuracy)
learn.fit(1, 1e-2)
In [ ]:
row = df.iloc[0]
In [ ]:
learn.predict(row)
Out[ ]:
In [ ]: