Deborah Paul
Deborah Paul

Reputation: 101

Tpot isnan error

I posted previously with a similar problem (Categorical Data with tpot). Thanks to Randy, I was able to get the code running, but now that I am stopping it hours later, I am getting a similar error:

  File "XXXXXXXX", line 832, in score
    if np.any(np.isnan(testing_features)):

TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

I'm not sure if I'm stopping it incorrectly (I just hit ctrl+c in spyder) or there is some other issue. I made sure the data is all numerical including feature titles. Any idea what may be the problem?

Here is the code I'm running:

train_x, test_x, train_y, test_y=train_test_split(x,y)
train_x=pd.get_dummies(train_x).values
from tpot import TPOTRegressor

regressor=TPOTRegressor()
regressor.fit(train_x,train_y)
print(regressor.score(test_x,test_y))

I don't know how to show the contents of train and test arrays. train_x is a size (2400,62) float64 and train_y is a (2400,) size series.

Upvotes: 0

Views: 966

Answers (2)

Adnan Taufique
Adnan Taufique

Reputation: 379

Using the first solution gave me the following error,

x_train = x_train.astype(np.float64)
x_test = x_test.astype(np.float64)
ValueError: setting an array element with a sequence.

Converting the features to numpy array does the trick for me. Even though they were initially numpy arrays

x_train = np.array(list(x_train), dtype=np.float)
x_test = np.array(list(x_test), dtype=np.float)

Upvotes: 1

Michael Davidson
Michael Davidson

Reputation: 1411

For some reason TPOT returns this error related to isnan when the error is the type. Ensure your features are converted to floats:

X = X.astype(np.float64)

Upvotes: 0

Related Questions