Advertisement
vishneva_olga

Untitled

Oct 7th, 2023
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.77 KB | None | 0 0
  1. ---------------------------------------------------------------------------
  2. ValueError                                Traceback (most recent call last)
  3. File <timed exec>:1, in <module>
  4.  
  5. Input In [4], in best_model(model, params, features, target, title, list_num, list_cat)
  6.      17 pipeline_model = Pipeline(
  7.      18                         steps=[
  8.      19                             ('preprocessor', preprocessor_model),
  9.      20                             ('model', model)
  10.      21                                 ])
  11.      23 gs_model = GridSearchCV(estimator=pipeline_model,
  12.      24                         param_grid=params,
  13.      25                         scoring='roc_auc',
  14.      26                         cv=CV,
  15.      27                         n_jobs=-1)
  16. ---> 29 gs_model.fit(features, target)
  17.      31 best_model = gs_model.best_estimator_
  18.      32 best_params = gs_model.best_params_
  19.  
  20. File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\model_selection\_search.py:874, in BaseSearchCV.fit(self, X, y, groups, **fit_params)
  21.     868     results = self._format_results(
  22.     869         all_candidate_params, n_splits, all_out, all_more_results
  23.     870     )
  24.     872     return results
  25. --> 874 self._run_search(evaluate_candidates)
  26.     876 # multimetric is determined here because in the case of a callable
  27.     877 # self.scoring the return type is only known after calling
  28.     878 first_test_score = all_out[0]["test_scores"]
  29.  
  30. File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\model_selection\_search.py:1388, in GridSearchCV._run_search(self, evaluate_candidates)
  31.    1386 def _run_search(self, evaluate_candidates):
  32.    1387     """Search all candidates in param_grid"""
  33. -> 1388     evaluate_candidates(ParameterGrid(self.param_grid))
  34.  
  35. 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)
  36.     844 elif len(out) != n_candidates * n_splits:
  37.     845     raise ValueError(
  38.     846         "cv.split and cv.get_n_splits returned "
  39.     847         "inconsistent results. Expected {} "
  40.     848         "splits, got {}".format(n_splits, len(out) // n_candidates)
  41.     849     )
  42. --> 851 _warn_or_raise_about_fit_failures(out, self.error_score)
  43.     853 # For callable self.scoring, the return type is only know after
  44.     854 # calling. If the return type is a dictionary, the error scores
  45.     855 # can now be inserted with the correct key. The type checking
  46.     856 # of out will be done in `_insert_error_scores`.
  47.     857 if callable(self.scoring):
  48.  
  49. 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)
  50.     360 if num_failed_fits == num_fits:
  51.     361     all_fits_failed_message = (
  52.     362         f"\nAll the {num_fits} fits failed.\n"
  53.     363         "It is very likely that your model is misconfigured.\n"
  54.     364         "You can try to debug the error by setting error_score='raise'.\n\n"
  55.     365         f"Below are more details about the failures:\n{fit_errors_summary}"
  56.     366     )
  57. --> 367     raise ValueError(all_fits_failed_message)
  58.     369 else:
  59.     370     some_fits_failed_message = (
  60.     371         f"\n{num_failed_fits} fits failed out of a total of {num_fits}.\n"
  61.     372         "The score on these train-test partitions for these parameters"
  62.    (...)
  63.     376         f"Below are more details about the failures:\n{fit_errors_summary}"
  64.     377     )
  65.  
  66. ValueError:
  67. All the 120 fits failed.
  68. It is very likely that your model is misconfigured.
  69. You can try to debug the error by setting error_score='raise'.
  70.  
  71. Below are more details about the failures:
  72. --------------------------------------------------------------------------------
  73. 120 fits failed with the following error:
  74. Traceback (most recent call last):
  75.   File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\indexes\base.py", line 3653, in get_loc
  76.     return self._engine.get_loc(casted_key)
  77.   File "pandas\_libs\index.pyx", line 147, in pandas._libs.index.IndexEngine.get_loc
  78.   File "pandas\_libs\index.pyx", line 176, in pandas._libs.index.IndexEngine.get_loc
  79.   File "pandas\_libs\hashtable_class_helper.pxi", line 7080, in pandas._libs.hashtable.PyObjectHashTable.get_item
  80.   File "pandas\_libs\hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item
  81. KeyError: 'target'
  82.  
  83. The above exception was the direct cause of the following exception:
  84.  
  85. Traceback (most recent call last):
  86.   File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\utils\__init__.py", line 448, in _get_column_indices
  87.     col_idx = all_columns.get_loc(col)
  88.   File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\indexes\base.py", line 3655, in get_loc
  89.     raise KeyError(key) from err
  90. KeyError: 'target'
  91.  
  92. The above exception was the direct cause of the following exception:
  93.  
  94. Traceback (most recent call last):
  95.   File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\model_selection\_validation.py", line 686, in _fit_and_score
  96.     estimator.fit(X_train, y_train, **fit_params)
  97.   File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\pipeline.py", line 401, in fit
  98.     Xt = self._fit(X, y, **fit_params_steps)
  99.   File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\pipeline.py", line 359, in _fit
  100.     X, fitted_transformer = fit_transform_one_cached(
  101.   File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\joblib\memory.py", line 349, in __call__
  102.     return self.func(*args, **kwargs)
  103.   File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\pipeline.py", line 893, in _fit_transform_one
  104.     res = transformer.fit_transform(X, y, **fit_params)
  105.   File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\utils\_set_output.py", line 140, in wrapped
  106.     data_to_wrap = f(self, X, *args, **kwargs)
  107.   File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\compose\_column_transformer.py", line 724, in fit_transform
  108.     self._validate_column_callables(X)
  109.   File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\compose\_column_transformer.py", line 426, in _validate_column_callables
  110.     transformer_to_input_indices[name] = _get_column_indices(X, columns)
  111.   File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\utils\__init__.py", line 456, in _get_column_indices
  112.     raise ValueError("A given column is not a column of the dataframe") from e
  113. ValueError: A given column is not a column of the dataframe
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement