1

I am trying to build a logistic regression model. After reading the data set . I am getting

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'

This is what I have done

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

Can any one tell me why I am getting this error

1
  • 2
    You don't have attributes called target_names or feature_names. If you share a few sample rows of the Data Set and explain what you mean by target_names and feature_names (Is this the header or values), it will be easier to answer the question you have. Commented Apr 22, 2018 at 15:00

1 Answer 1

3

You would have to define feature_names and target_names, as they are not native pandas attributes. If you wanted df.feature_names and df.target_names to return a select group of columns instead, you will need to create a multiindex and set df.columns equal to that. A multiindex allows you to create multiple-row-headers or indices. This is described here and can be applied to either rows or columns.

https://pandas.pydata.org/pandas-docs/stable/advanced.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.