【问题标题】:NameError: name 'TabularList' is not definedNameError:名称“TabularList”未定义
【发布时间】:2021-08-21 15:33:33
【问题描述】:
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

我相信我已经导入了所有需要的模块。有人可以为此提出解决方案吗?

【问题讨论】:

    标签: python deep-learning fast-ai


    【解决方案1】:

    检查完整路径导入,如下所示

    from fastai.tabular.data import TabularList
    

    【讨论】:

    • 感谢@Pankaj78691 的回复,但它似乎不起作用。我现在收到一个导入错误: ImportError Traceback (最近一次调用最后一次) in 2 from fastai.tabular import * 3 from fastai.tabular.all import * ---- > 4 from fastai.tabular.data import TabularList 5 6 import pandas as pd ImportError: cannot import name 'TabularList' from 'fastai.tabular.data' (c:\users\khuba\appdata\local\programs\python\python39\ lib\site-packages\fastai\tabular\data.py)
    • @KhubaibAbdullah 那么您可能需要检查 fastai 是否在路径中,或者您可以启动 python 交互式 shell 并尝试导入并查看它是否有效
    猜你喜欢
    • 2022-10-24
    • 1970-01-01
    • 2018-01-24
    • 1970-01-01
    • 2021-04-15
    • 2019-01-26
    • 2021-10-05
    • 2017-08-16
    相关资源
    最近更新 更多