code: def _score_core(self, series: TimeSeries) -> TimeSeries:
      raise_if_not(
          self.width_trained_on == series.width,
          "Input must have the same number of components as the data used for"
          + " training the KMeans model, found number of components equal to"
          + f" {series.width} and expected {self.width_trained_on}.",
      )
  
      np_series = series.all_values(copy=False)
      np_anomaly_score = []
  
      if not self.component_wise:
          # return distance to the clostest centroid
          np_anomaly_score.append(
              self.model.transform(
                  sliding_window_view(
                      np_series, window_shape=self.window, axis=0
                  )
                  .transpose(0, 3, 1, 2)
                  .reshape(-1, self.window * series.width)
              ).min(axis=1)
          )  # only return the closest distance out of the k ones (k centroids)
      else:
          for component_idx in range(self.width_trained_on):
              score = (
                  self.models[component_idx]
                  .transform(
                      sliding_window_view(
                          np_series[:, component_idx],
                          window_shape=self.window,
                          axis=0,
                      )
                      .transpose(0, 2, 1)
                      .reshape(-1, self.window)
                  )
                  .min(axis=1)
              )
  
              np_anomaly_score.append(score)
  
      return TimeSeries.from_times_and_values(
          series.time_index[self.window - 1 :],
          list(zip(*np_anomaly_score)),
      )
  
file_path: darts/darts/ad/scorers/kmeans_scorer.py
imports: from typing import Sequence
  import numpy
  from numpy.lib.stride_tricks import sliding_window_view
  from sklearn.cluster import KMeans
  from darts.ad.scorers.scorers import FittableAnomalyScorer
  from darts.logging import raise_if_not
  from darts.timeseries import TimeSeries
label_desc: Use image node_id 4 for calling the KMeansScorer obj's underlying member method code with example usage: obj._score_core(series) and returns: TimeSeries