pythonanomaly-detectionpycaret

PyCaret Anomaly setup() is not working (ATTRIBUTE ERROR)


I am trying to follow a tutorial to perform Anomaly Detection in PyCaret. While running setup(), I keep getting this error:

AttributeError: 'DataFrame' object has no attribute 'unique'

This error happens anytime I have a categorical variable in the dataset. Below is the code I used and a screenshot of the error:

data = pd.read_csv('https://raw.githubusercontent.com/numenta/NAB/master/data/realKnownCause/nyc_taxi.csv')
data['timestamp'] = pd.to_datetime(data['timestamp'])

data.set_index('timestamp', drop=True, inplace=True)
# resample timeseries to hourly 
data = data.resample('H').sum()
# creature features from date
data['day'] = [i.day for i in data.index]
data['day_name'] = [i.day_name() for i in data.index]
data['day_of_year'] = [i.dayofyear for i in data.index]
data['week_of_year'] = [i.weekofyear for i in data.index]
data['hour'] = [i.hour for i in data.index]
data['is_weekday'] = [i.isoweekday() for i in data.index]

s = setup(data, session_id = 123)
```[enter image description here][1]


  [1]: https://i.sstatic.net/LOWMn.png

Solution

  • It looks like a bug in the source code. You could try raising it on GitHub.

    You also could monkey patch the data frame:

    import pandas as pd
    
    pd.DataFrame.unique = pd.DataFrame.drop_duplicates