名称错误:未定义名称“表格列表”

2024-06-12 02:31:34 发布

您现在位置:Python中文网/ 问答频道 /正文

from fastai import *
from fastai.tabular import *
from fastai.tabular.all import *
import pandas as pd

# set seed for reproducibility
custom_set_seed(42)

df = pd.read_csv('credit_card_default.csv', index_col=0, na_values='')
df.head()

DEP_VAR = 'default_payment_next_month'

num_features = list(df.select_dtypes('number').columns)
num_features.remove(DEP_VAR)
cat_features = list(df.select_dtypes('object').columns)

preprocessing = [FillMissing, Categorify, Normalize]

data = (TabularList.from_df(df, cat_names=cat_features, cont_names=num_features, procs=preprocessing).split_by_rand_pct(valid_pct=0.2, seed=42).label_from_df(cols=DEP_VAR).databunch())

我一直在尝试运行这段代码,但它一直遇到以下错误:

NameError                                 Traceback (most recent call last)
<ipython-input-42-5ca7e57a8e36> in <module>
      1 # Create a TabularDataBunch from the DataFrame
      2 
----> 3 data = (TabularList.from_df(df, cat_names=cat_features, cont_names=num_features, procs=preprocessing).split_by_rand_pct(valid_pct=0.2, seed=42).label_from_df(cols=DEP_VAR).databunch())

NameError: name 'TabularList' is not defined

我相信我已经导入了所有需要的模块。有人能提出解决办法吗


Tags: fromimportdfnamesvarfastainumcat