EpistasisLab / EpistasisLab/tpot

Target variable error: could not convert string to float:

Open
#992 1 comment 0 reactions 0 assignees View on GitHub
easy enhancement
Dominant language
Jupyter Notebook
Stars
10.1k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

Hi,
I'm new to tpot but I got this error. I understand that score function can take strings, but I got the following error when using TPOTClassifier.

> --------------------------------------------------------------
> ValueError Traceback (most recent call last)
> in
> ----> 1 tpot.score(X_test, y_test)
>
> ~/miniconda3/envs/ml/lib/python3.7/site-packages/tpot/base.py in score(self, testing_features, testing_target)
> 937 self.fitted_pipeline_,
> 938 testing_features.astype(np.float64),
> --> 939 testing_target.astype(np.float64)
> 940 )
> 941 return score
>
> ~/miniconda3/envs/ml/lib/python3.7/site-packages/pandas/core/generic.py in astype(self, dtype, copy, errors, **kwargs)
> 5880 # else, only a single dtype is given
> 5881 new_data = self._data.astype(
> -> 5882 dtype=dtype, copy=copy, errors=errors, **kwargs
> 5883 )
> 5884 return self._constructor(new_data).__finalize__(self)
>
> ~/miniconda3/envs/ml/lib/python3.7/site-packages/pandas/core/internals/managers.py in astype(self, dtype, **kwargs)
> 579
> 580 def astype(self, dtype, **kwargs):
> --> 581 return self.apply("astype", dtype=dtype, **kwargs)
> 582
> 583 def convert(self, **kwargs):
>
> ~/miniconda3/envs/ml/lib/python3.7/site-packages/pandas/core/internals/managers.py in apply(self, f, axes, filter, do_integrity_check, consolidate, **kwargs)
> 436 kwargs[k] = obj.reindex(b_items, axis=axis, copy=align_copy)
> 437
> --> 438 applied = getattr(b, f)(**kwargs)
> 439 result_blocks = _extend_blocks(applied, result_blocks)
> 440
>
> ~/miniconda3/envs/ml/lib/python3.7/site-packages/pandas/core/internals/blocks.py in astype(self, dtype, copy, errors, values, **kwargs)
> 557
> 558 def astype(self, dtype, copy=False, errors="raise", values=None, **kwargs):
> --> 559 return self._astype(dtype, copy=copy, errors=errors, values=values, **kwargs)
> 560
> 561 def _astype(self, dtype, copy=False, errors="raise", values=None, **kwargs):
>
> ~/miniconda3/envs/ml/lib/python3.7/site-packages/pandas/core/internals/blocks.py in _astype(self, dtype, copy, errors, values, **kwargs)
> 641 # _astype_nansafe works fine with 1-d only
> 642 vals1d = values.ravel()
> --> 643 values = astype_nansafe(vals1d, dtype, copy=True, **kwargs)
> 644
> 645 # TODO(extension)
>
> ~/miniconda3/envs/ml/lib/python3.7/site-packages/pandas/core/dtypes/cast.py in astype_nansafe(arr, dtype, copy, skipna)
> 727 if copy or is_object_dtype(arr) or is_object_dtype(dtype):
> 728 # Explicit copy, or required since NumPy can't view from / to object.
> --> 729 return arr.astype(dtype, copy=True)
> 730
> 731 return arr.view(dtype)
>
> ValueError: could not convert string to float: 'control'

This is how tpot was called:
`TPOTClassifier(verbosity=2,
scoring="balanced_accuracy",
random_state=21,
periodic_checkpoint_folder="tpot_check.txt",
n_jobs=-1,
generations=10,
population_size=100`

tpot was trying to score this pipeline after running uneventfully 10 generations:

> LinearSVC(input_matrix, C=5.0, dual=False, loss=squared_hinge, penalty=l1, tol=0.0001)

I can see that **score** is trying to deal with a float64 (testing_target.astype(np.float64)), but I guessed that it should have been previously encoded. I understand that there is no need to encode the target variables, and that LinearSVC takes string target variables. I tried it in skit-learn and no problems.

Is this a bug or I missed something?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.