2

我正在关注本教程关于使用深度信念网络https://www.pyimagesearch.com/2014/09/22/getting-started-deep-learning-python/然后我决定附加我的外部数据集并收到以下错误:

Traceback (most recent call last):
  File "C:\Users\Allan\Desktop\aaaaaaa.py", line 21, in <module>
    dataset.data , dataset.target, test_size = 0.33)
  File "C:\Python27\lib\site-packages\pandas\core\generic.py", line 3614, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'data'  

这是我使用的代码:

#import the necessary packages
import pandas as pd
from sklearn.cross_validation import train_test_split
from sklearn.metrics import classification_report
from sklearn import datasets
from nolearn.dbn import DBN
import numpy as np


#loading my dataset
dataset = pd.read_csv("C:\Users\Allan\Desktop\qqew3.csv")



#construct the training and testing splits
(trainX, testX, trainY, testY) = train_test_split(
    dataset.data , dataset.target, test_size = 0.33)

#training
dbn = DBN(
    [trainX.shape[1], 800, 800, 10],
    learn_rates = 0.3,
    learn_rate_decays = 0.9,
    epochs = 10,
    verbose = 1)
dbn.fit(trainX, trainY)


preds = dbn.predict(testX)
print (classification_report(testY, preds))

我的数据集的结构如下:

{'target_names': array(['JURISDICTION NAME','COUNT PARTICIPANTS','COUNT FEMALE','PERCENT FEMALE','COUNT MALE','PERCENT MALE','COUNT GENDER UNKNOWN','PERCENT GENDER UNKNOWN','COUNT GENDER TOTAL','PERCENT GENDER TOTAL','COUNT PACIFIC ISLANDER','PERCENT PACIFIC ISLANDER','COUNT HISPANIC LATINO','PERCENT HISPANIC LATINO','COUNT AMERICAN INDIAN','PERCENT AMERICAN INDIAN','COUNT ASIAN NON HISPANIC','PERCENT ASIAN NON HISPANIC','COUNT WHITE NON HISPANIC','PERCENT WHITE NON HISPANIC','COUNT BLACK NON HISPANIC','PERCENT BLACK NON HISPANIC','COUNT OTHER ETHNICITY','PERCENT OTHER ETHNICITY','COUNT ETHNICITY UNKNOWN','PERCENT ETHNICITY UNKNOWN','COUNT ETHNICITY TOTAL','PERCENT ETHNICITY TOTAL','COUNT PERMANENT RESIDENT ALIEN','PERCENT PERMANENT RESIDENT ALIEN','COUNT US CITIZEN','PERCENT US CITIZEN','COUNT OTHER CITIZEN STATUS','PERCENT OTHER CITIZEN STATUS','COUNT CITIZEN STATUS UNKNOWN','PERCENT CITIZEN STATUS UNKNOWN','COUNT CITIZEN STATUS TOTAL','PERCENT CITIZEN STATUS TOTAL','COUNT RECEIVES PUBLIC ASSISTANCE','PERCENT RECEIVES PUBLIC ASSISTANCE','COUNT NRECEIVES PUBLIC ASSISTANCE','PERCENT NRECEIVES PUBLIC ASSISTANCE','COUNT PUBLIC ASSISTANCE UNKNOWN','PERCENT PUBLIC ASSISTANCE UNKNOWN','COUNT PUBLIC ASSISTANCE TOTAL','PERCENT PUBLIC ASSISTANCE TOTAL']),'data': array([
[10001,44,22,0.5,22,0.5,0,0,44,100,0,0,16,0.36,0,0,3,0.07,1,0.02,21,0.48,3,0.07,0,0,44,100,2,0.05,42,0.95,0,0,0,0,44,100,20,0.45,24,0.55,0,0,44,100],
[10002,35,19,0.54,16,0.46,0,0,35,100,0,0,1,0.03,0,0,28,0.8,6,0.17,0,0,0,0,0,0,35,100,2,0.06,33,0.94,0,0,0,0,35,100,2,0.06,33,0.94,0,0,35,100],
[10003,1,1,1,0,0,0,0,1,100,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,100,0,0,1,1,0,0,0,0,1,100,0,0,1,1,0,0,1,100],
[10004,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[10005,2,2,1,0,0,0,0,2,100,0,0,0,0,0,0,1,0.5,0,0,1,0.5,0,0,0,0,2,100,1,0.5,1,0.5,0,0,0,0,2,100,0,0,2,1,0,0,2,100],
[10006,6,2,0.33,4,0.67,0,0,6,100,0,0,2,0.33,0,0,0,0,1,0.17,3,0.5,0,0,0,0,6,100,0,0,6,1,0,0,0,0,6,100,0,0,6,1,0,0,6,100],
[10007,1,0,0,1,1,0,0,1,100,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,100,0,0,1,1,0,0,0,0,1,100,1,1,0,0,0,0,1,100],
[10009,2,0,0,2,1,0,0,2,100,0,0,0,0,0,0,2,1,0,0,0,0,0,0,0,0,2,100,0,0,2,1,0,0,0,0,2,100,0,0,2,1,0,0,2,100],
[10010,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]),
 'target':array([0,1,1,1,0,0,1,0,1])}

如您所见,我的数据集具有“数据”属性,其中包含要用于训练的数据

先感谢您!

4

0 回答 0