Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------------------------------------------------------
- ValueError Traceback (most recent call last)
- File <timed exec>:1, in <module>
- Input In [4], in best_model(model, params, features, target, title, list_num, list_cat)
- 17 pipeline_model = Pipeline(
- 18 steps=[
- 19 ('preprocessor', preprocessor_model),
- 20 ('model', model)
- 21 ])
- 23 gs_model = GridSearchCV(estimator=pipeline_model,
- 24 param_grid=params,
- 25 scoring='roc_auc',
- 26 cv=CV,
- 27 n_jobs=-1)
- ---> 29 gs_model.fit(features, target)
- 31 best_model = gs_model.best_estimator_
- 32 best_params = gs_model.best_params_
- File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\model_selection\_search.py:874, in BaseSearchCV.fit(self, X, y, groups, **fit_params)
- 868 results = self._format_results(
- 869 all_candidate_params, n_splits, all_out, all_more_results
- 870 )
- 872 return results
- --> 874 self._run_search(evaluate_candidates)
- 876 # multimetric is determined here because in the case of a callable
- 877 # self.scoring the return type is only known after calling
- 878 first_test_score = all_out[0]["test_scores"]
- File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\model_selection\_search.py:1388, in GridSearchCV._run_search(self, evaluate_candidates)
- 1386 def _run_search(self, evaluate_candidates):
- 1387 """Search all candidates in param_grid"""
- -> 1388 evaluate_candidates(ParameterGrid(self.param_grid))
- File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\model_selection\_search.py:851, in BaseSearchCV.fit.<locals>.evaluate_candidates(candidate_params, cv, more_results)
- 844 elif len(out) != n_candidates * n_splits:
- 845 raise ValueError(
- 846 "cv.split and cv.get_n_splits returned "
- 847 "inconsistent results. Expected {} "
- 848 "splits, got {}".format(n_splits, len(out) // n_candidates)
- 849 )
- --> 851 _warn_or_raise_about_fit_failures(out, self.error_score)
- 853 # For callable self.scoring, the return type is only know after
- 854 # calling. If the return type is a dictionary, the error scores
- 855 # can now be inserted with the correct key. The type checking
- 856 # of out will be done in `_insert_error_scores`.
- 857 if callable(self.scoring):
- File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\model_selection\_validation.py:367, in _warn_or_raise_about_fit_failures(results, error_score)
- 360 if num_failed_fits == num_fits:
- 361 all_fits_failed_message = (
- 362 f"\nAll the {num_fits} fits failed.\n"
- 363 "It is very likely that your model is misconfigured.\n"
- 364 "You can try to debug the error by setting error_score='raise'.\n\n"
- 365 f"Below are more details about the failures:\n{fit_errors_summary}"
- 366 )
- --> 367 raise ValueError(all_fits_failed_message)
- 369 else:
- 370 some_fits_failed_message = (
- 371 f"\n{num_failed_fits} fits failed out of a total of {num_fits}.\n"
- 372 "The score on these train-test partitions for these parameters"
- (...)
- 376 f"Below are more details about the failures:\n{fit_errors_summary}"
- 377 )
- ValueError:
- All the 120 fits failed.
- It is very likely that your model is misconfigured.
- You can try to debug the error by setting error_score='raise'.
- Below are more details about the failures:
- --------------------------------------------------------------------------------
- 120 fits failed with the following error:
- Traceback (most recent call last):
- File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\indexes\base.py", line 3653, in get_loc
- return self._engine.get_loc(casted_key)
- File "pandas\_libs\index.pyx", line 147, in pandas._libs.index.IndexEngine.get_loc
- File "pandas\_libs\index.pyx", line 176, in pandas._libs.index.IndexEngine.get_loc
- File "pandas\_libs\hashtable_class_helper.pxi", line 7080, in pandas._libs.hashtable.PyObjectHashTable.get_item
- File "pandas\_libs\hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item
- KeyError: 'target'
- The above exception was the direct cause of the following exception:
- Traceback (most recent call last):
- File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\utils\__init__.py", line 448, in _get_column_indices
- col_idx = all_columns.get_loc(col)
- File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\indexes\base.py", line 3655, in get_loc
- raise KeyError(key) from err
- KeyError: 'target'
- The above exception was the direct cause of the following exception:
- Traceback (most recent call last):
- File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\model_selection\_validation.py", line 686, in _fit_and_score
- estimator.fit(X_train, y_train, **fit_params)
- File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\pipeline.py", line 401, in fit
- Xt = self._fit(X, y, **fit_params_steps)
- File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\pipeline.py", line 359, in _fit
- X, fitted_transformer = fit_transform_one_cached(
- File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\joblib\memory.py", line 349, in __call__
- return self.func(*args, **kwargs)
- File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\pipeline.py", line 893, in _fit_transform_one
- res = transformer.fit_transform(X, y, **fit_params)
- File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\utils\_set_output.py", line 140, in wrapped
- data_to_wrap = f(self, X, *args, **kwargs)
- File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\compose\_column_transformer.py", line 724, in fit_transform
- self._validate_column_callables(X)
- File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\compose\_column_transformer.py", line 426, in _validate_column_callables
- transformer_to_input_indices[name] = _get_column_indices(X, columns)
- File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\utils\__init__.py", line 456, in _get_column_indices
- raise ValueError("A given column is not a column of the dataframe") from e
- ValueError: A given column is not a column of the dataframe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement