code: def plot_tsice_with_observed_features(explanation, feature_per_row=2):
      df = pd.DataFrame(explanation["data_x"])
      n_row = int(
          np.ceil(len(explanation["feature_names"]) / feature_per_row)
      )
      feat_values = np.array(explanation["feature_values"])
  
      spec = [
          [{} for _ in range(feature_per_row)] for _ in range(n_row)
      ]
  
      fig = make_subplots(n_row, feature_per_row, specs=spec)
  
      row_id = 1
      col_id = 1
      showlegend = True
      for i, feat in enumerate(explanation["feature_names"]):
          x_feat = feat_values[i, :, 0]
          trend_fit = LinearRegression()
          trend_line = trend_fit.fit(
              x_feat.reshape(-1, 1), explanation["signed_impact"]
          )
          x_trend = np.linspace(min(x_feat), max(x_feat), 101)
          y_trend = trend_line.predict(x_trend[..., np.newaxis])
  
          fig.add_trace(
              go.Scatter(
                  x=x_feat,
                  y=explanation["signed_impact"],
                  mode="markers",
                  showlegend=False,
              ),
              row=row_id,
              col=col_id,
          )
  
          fig.add_trace(
              go.Scatter(
                  x=x_trend,
                  y=y_trend,
                  line=dict(color="green"),
                  mode="lines",
                  name="correlation between forecast and observed feature",
                  showlegend=showlegend,
              ),
              row=row_id,
              col=col_id,
          )
          current_value = explanation["current_feature_values"][i][0]
          reference_line = go.Scatter(
              x=[current_value, current_value],
              y=[
                  np.min(explanation["signed_impact"]) - 1,
                  np.max(explanation["signed_impact"]) + 1,
              ],
              mode="lines",
              line=go.scatter.Line(color="firebrick", dash="dash"),
              showlegend=showlegend,
              name="current value",
          )
          fig.add_trace(reference_line, row=row_id, col=col_id)
  
          fig.update_xaxes(
              title=f"<b>{feat}<b>", row=row_id, col=col_id
          )
          fig.update_yaxes(
              title=f"<b>&#916; forecast<b>", row=row_id, col=col_id
          )
  
          showlegend = False
          if col_id == feature_per_row:
              col_id = 1
              row_id += 1
          else:
              col_id += 1
  
      fig.update_layout(
          title="<b>Impact of Derived Variable On The Forecast</b>",
          plot_bgcolor="white",
          showlegend=True,
          legend=dict(yanchor="top", y=0.99, xanchor="left", x=0.01),
      )
      return fig
  
file_path: AIX360/examples/tsice/plots.py
imports: from typing import Union
  import numpy
  import pandas
  from sklearn.linear_model import LinearRegression
label_desc: Use image node_id 4 for calling a global function with example usage: plot_tsice_with_observed_features(explanation, feature_per_row) and returns: fig