我正在尝试建立一个逻辑回归模型。在读取数据集之后。我得到了
AttributeError Traceback (most recent call last)
<ipython-input-1-b1fbf288405a> in <module>()
21 df.head(10) #This should print 10 rows
22
---> 23 df.target_names
24 df.feature_names
25
C:\Users\HP\Anaconda2\lib\site-packages\pandas\core\generic.pyc in __getattr__(self, name)
3612 if name in self._info_axis:
3613 return self[name]
-> 3614 return object.__getattribute__(self, name)
3615
3616 def __setattr__(self, name, value):
AttributeError: 'DataFrame' object has no attribute 'target_names'这就是我所做的
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
from sklearn import preprocessing
# create header for dataset
header = ['age','bp','sg','al','su','rbc','pc','pcc',
'ba','bgr','bu','sc','sod','pot','hemo','pcv',
'wbcc','rbcc','htn','dm','cad','appet','pe','ane',
'classification']
# read the dataset
df = pd.read_csv("C:\Users\HP\Documents\machine learning project\Chronic_Kidney_Disease\chronic_kidney_disease_full.arff",
header=None,
names=header
)
# dataset has '?' in it, convert these into NaN
df = df.replace('?', np.nan)
# drop the NaN
df = df.dropna(axis=0, how="any")
df.head(10) #This should print 10 rows
df.target_names
df.feature_names有人能告诉我为什么会出现这个错误吗?
发布于 2018-04-23 06:10:58
您必须定义feature_names和target_names,因为它们不是原生的pandas属性。如果您希望df.feature_names和df.target_names返回一组选定的列,则需要创建一个多索引并将df.columns设置为等于该多索引。多索引允许您创建多个行头或索引。这里描述了这一点,并且可以应用于行或列。
https://stackoverflow.com/questions/49966639
复制相似问题