code: def regret(
      experiment,
      with_evc_tree=True,
      order_by="suggested",
      verbose_hover=True,
      **kwargs,
  ):
      """Plotly implementation of `orion.plotting.regret`"""
  
      def build_frame():
          """Builds the dataframe for the plot"""
          df = experiment.to_pandas(with_evc_tree=with_evc_tree)
  
          names = list(experiment.space.keys())
          df["params"] = df[names].apply(
              _format_hyperparameters, args=(names,), axis=1
          )
  
          df = df.loc[df["status"] == "completed"]
          df = df.sort_values(order_by)
          df = orion.analysis.regret(df)
          return df
  
      ORDER_KEYS = ["suggested", "reserved", "completed"]
  
      if not experiment:
          raise ValueError("Parameter 'experiment' is None")
  
      if order_by not in ORDER_KEYS:
          raise ValueError(
              f"Parameter 'order_by' is not one of {ORDER_KEYS}"
          )
  
      df = build_frame()
  
      fig = go.Figure()
  
      if df.empty:
          return fig
  
      trial = experiment.fetch_trials_by_status(
          "completed", with_evc_tree=with_evc_tree
      )[0]
  
      fig.add_scatter(
          y=df["objective"],
          mode="markers",
          name="trials",
          customdata=list(zip(df["id"], df[order_by], df["params"])),
          hovertemplate=_template_trials(verbose_hover),
      )
      fig.add_scatter(
          y=df["best"],
          mode="lines",
          name="best-to-date",
          customdata=list(zip(df["best_id"], df["best"])),
          hovertemplate=_template_best(),
      )
  
      if trial is None:
          y_axis_label = "Objective unknown"
      else:
          y_axis_label = f"{trial.objective.type.capitalize()} '{trial.objective.name}'"
  
      fig.update_layout(
          title=f"Regret for experiment '{experiment.name}'",
          xaxis_title=f"Trials ordered by {order_by} time",
          yaxis_title=y_axis_label,
      )
  
      return fig
  
imports: import functools
  from collections.abc import Iterable
  import numpy
  import pandas
  import plotly.express
  import plotly.graph_objects
  from plotly.subplots import make_subplots
  import orion.analysis
  import orion.analysis.base
  from orion.algo.space import Categorical, Fidelity
  from orion.core.worker.transformer import build_required_space
label_desc: Use image node_id 5 for calling a global function with example usage: regret(experiment, with_evc_tree, order_by, verbose_hover) and returns: fig, df, fig