The way to debug it is to pass error_score="raise"
when calling cross_validate
or validation_curve
. It will raise the following error
ValueError Traceback (most recent call last)
<ipython-input-2-3f47846e2c6a> in <module>
16
17 gama_de_gammas=np.logspace(-3,2,num=30)
---> 18 train_scores, test_scores = validation_curve(
19 modelo, data, target, param_name="svc__gamma", param_range=gama_de_gammas,
20 scoring="neg_mean_absolute_error", ### THAT DOESN'T WORK
~/Documents/packages/scikit-learn/sklearn/model_selection/_validation.py in validation_curve(estimator, X, y, param_name, param_range, groups, cv, scoring, n_jobs, pre_dispatch, verbose, error_score, fit_params)
1640 parallel = Parallel(n_jobs=n_jobs, pre_dispatch=pre_dispatch,
1641 verbose=verbose)
-> 1642 results = parallel(delayed(_fit_and_score)(
1643 clone(estimator), X, y, scorer, train, test, verbose,
1644 parameters={param_name: v}, fit_params=fit_params,
~/miniconda3/envs/dev/lib/python3.8/site-packages/joblib/parallel.py in __call__(self, iterable)
1040
1041 with self._backend.retrieval_context():
-> 1042 self.retrieve()
1043 # Make sure that we get a last message telling us we are done
1044 elapsed_time = time.time() - self._start_time
~/miniconda3/envs/dev/lib/python3.8/site-packages/joblib/parallel.py in retrieve(self)
919 try:
920 if getattr(self._backend, 'supports_timeout', False):
--> 921 self._output.extend(job.get(timeout=self.timeout))
922 else:
923 self._output.extend(job.get())
~/miniconda3/envs/dev/lib/python3.8/site-packages/joblib/_parallel_backends.py in wrap_future_result(future, timeout)
540 AsyncResults.get from multiprocessing."""
541 try:
--> 542 return future.result(timeout=timeout)
543 except CfTimeoutError as e:
544 raise TimeoutError from e
~/miniconda3/envs/dev/lib/python3.8/concurrent/futures/_base.py in result(self, timeout)
430 raise CancelledError()
431 elif self._state == FINISHED:
--> 432 return self.__get_result()
433
434 self._condition.wait(timeout)
~/miniconda3/envs/dev/lib/python3.8/concurrent/futures/_base.py in __get_result(self)
386 def __get_result(self):
387 if self._exception:
--> 388 raise self._exception
389 else:
390 return self._result
ValueError: could not convert string to float: 'not donated'
It might be a bug in scikit-learn, I will need to debug a bit more. However, you can bypass this error by encoding the target after loading the data.
from sklearn.preprocessing import LabelEncoder
...
target = LabelEncoder().fit_transform(target)
The code then will work.