alteryx / alteryx/evalml

Invalid logical type error for data while on its own (infer_feature_types)

Aperta
#3,886 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug
Lingua principale
Python
Stelle
850
Fork
96
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

While attempting to split a dataset into multiple pandas dataframes, an error occurs when one column of binary data is marked as categorical through the infer_feature_types function while in its own dataframe. This error only occurs while it is in its own dataframe, when any other columns of data are included in the dataframe, it accepts the categorical logical type as expected.

I should also mention, i'm still quite new at programming, so the error could be in my understanding.

Here is the exact error I'm getting:
```python
Traceback (most recent call last):
File "d:\PYTHON PROJECTS\Adv-Stock-Predictions\errortest.py", line 68, in
YI = infer_feature_types(
File "C:\Users\chous\AppData\Roaming\Python\Python39\site-packages\evalml\utils\woodwork_utils.py", line 71, in infer_feature_types
return ww.init_series(data, logical_type=feature_types)
File "C:\Users\chous\AppData\Roaming\Python\Python39\site-packages\woodwork\accessor_utils.py", line 62, in init_series
logical_type = _get_column_logical_type(series, logical_type, series.name)
File "C:\Users\chous\AppData\Roaming\Python\Python39\site-packages\woodwork\utils.py", line 416, in _get_column_logical_type
return _parse_logical_type(logical_type, name)
File "C:\Users\chous\AppData\Roaming\Python\Python39\site-packages\woodwork\utils.py", line 429, in _parse_logical_type
raise TypeError(f"Invalid logical type specified for '{name}'")
TypeError: Invalid logical type specified for 'Increased'
```

Here is the code I'm using:
```python
import os
import datetime as dt
import pandas_datareader as pdr
import pandas as pd
from evalml.utils import infer_feature_types

os.makedirs('Historical_Data', exist_ok=True)

def increased_close(row):
if row['Close'] > row['Open']:
return int('1')
else:
return int('0')

# Uncomment these lines to pull initial dataset from Yahoo Finance Historical Data
# start = dt.datetime(1999,11,17)
# end = dt.date.today() - dt.timedelta(days = 5)
# data = pdr.data.DataReader('A','yahoo',start,end)
# data.to_csv('Historical_Data/A.csv')

data = pd.read_csv('Historical_Data/A.csv', header=0)
data = data.drop('Adj Close', axis=1)
data['Increased'] = data.apply(increased_close, axis=1)
data['Yest_High'] = data.High.shift(1)
data['Yest_Low'] = data.Low.shift(1)
data['Yest_Open'] = data.Open.shift(1)
data['Yest_Volume'] = data.Volume.shift(1)
data['Yest_Close'] = data.Close.shift(1)
data['Yest_Increased'] = data.Increased.shift(1)
data = data.dropna()
data = data.loc[:,
['Date', 'Open', 'High', 'Low', 'Volume', 'Yest_Open', 'Yest_High', 'Yest_Low', 'Yest_Volume',
'Yest_Close', 'Yest_Increased', 'Close', 'Increased']]

X = data.iloc[:, 0:-2]
Y = data.iloc[:, -2]
YI = data.iloc[:, -1]

# This works as expected
data = infer_feature_types(
data,
feature_types={
'Yest_Increased': 'Categorical',
'Increased': 'Categorical'
}
)

print(data.ww)

X = infer_feature_types(
X,
feature_types={
'Yest_Increased': 'Categorical'
},
)

print(X.ww)

Y = infer_feature_types(
Y
)

print(Y.ww)

# This causes the TypeError
YI = infer_feature_types(
YI,
feature_types={
'Increased': 'Categorical'
},
)

print(YI.ww)

```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.