class_docstr: Base class representing a step in an MLflow Recipe
docstr: Generate dataframe containing worst k examples with largest prediction error.
  Dataframe contains columns of all features, prediction, error, and target_col column.
  The prediction error is defined as absolute error between target value and
  prediction value.
docstr_tok: ["Generate","dataframe","containing","worst","k","examples","with","largest","prediction","error",".","Dataframe","contains","columns","of","all","features",",","prediction",",","error",",","and","target_col","column",".","The","prediction","error","is","defined","as","absolute","error","between","target","value","and","prediction","value","."]
code: def _generate_worst_examples_dataframe(
      dataframe,
      predictions,
      error,
      target_col,
      worst_k=10,
  ):
      """
      Generate dataframe containing worst k examples with largest prediction error.
      Dataframe contains columns of all features, prediction, error, and target_col column.
      The prediction error is defined as absolute error between target value and
      prediction value.
      """
      import numpy as np
  
      predictions = np.array(predictions)
      abs_error = np.absolute(error)
      worst_k_indexes = np.argsort(abs_error)[::-1][:worst_k]
      result_df = dataframe.iloc[worst_k_indexes].assign(
          prediction=predictions[worst_k_indexes],
          absolute_error=abs_error[worst_k_indexes],
      )
      front_columns = ["absolute_error", "prediction", target_col]
      reordered_columns = (
          front_columns + result_df.columns.drop(front_columns).tolist()
      )
      return result_df[reordered_columns].reset_index(drop=True)
  
imports: import abc
  import json
  import logging
  import os
  import time
  import traceback
  from enum import Enum
  from typing import Any, Dict, List, Optional
  import yaml
  from mlflow.recipes.cards import CARD_HTML_NAME, CARD_PICKLE_NAME, BaseCard, FailureCard
  from mlflow.recipes.utils import get_recipe_name
  from mlflow.recipes.utils.step import display_html
  from mlflow.tracking import MlflowClient
  from mlflow.utils.databricks_utils import is_in_databricks_runtime
label_desc: Use image node_id 18 for calling the BaseStep obj's underlying member method code with example usage: obj._generate_worst_examples_dataframe(dataframe, predictions, error, target_col, worst_k) and returns: result_df