Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
194 views
in Technique[技术] by (71.8m points)

python - ImportError: cannot import name 'AdultDataset' from 'dataset'

Please I am working on AdultDataset for a classification task

I found out: from dataset import AdultDataset

is giving the error below:

ImportError: cannot import name 'AdultDataset' from 'dataset'

Import Relevant Libraries

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import train_test_split

import torch
import torch.nn as nn

import torch.optim as optim
from torch.autograd import Variable
from torch.utils.data import DataLoader


from dataset import AdultDataset

So when I am trying to create a 3 layer Feed Forward Neural network using pytorch that takes as input the a dataset entries and classifies if the individuals gains more or less than 50K (i.e., the fnlwgt label)

starting with the code below I get an error

train_dataset = AdultDataset(X_train, y_train)
test_dataset = AdultDataset(X_test, y_test)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-49-4ab31bdb6258> in <module>
      1 # Using norm_D01
      2 
----> 3 train_dataset = AdultDataset(X_train, y_train)
      4 test_dataset = AdultDataset(X_test, y_test)
      5 

NameError: name 'AdultDataset' is not defined

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I believe your problem can be fixed like this:

from aif360.datasets import AdultDataset

Maybe you are using an old guide?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...