class_docstr: Slope-by-segment transformation.
  
  Class to perform the Slope transformation on a time series
  dataframe. It splits a time series into num_intervals segments.
  Then within each segment, it performs a total least
  squares regression to extract the gradient of the segment.
  
  Parameters
  ----------
  num_intervals : int, number of approx equal segments
                  to split the time series into.
class_docstr_tok: ["Slope-by-segment","transformation",".","Class","to","perform","the","Slope","transformation","on","a","time","series","dataframe",".","It","splits","a","time","series","into","num_intervals","segments",".","Then","within","each","segment",",","it","performs","a","total","least","squares","regression","to","extract","the","gradient","of","the","segment",".","Parameters","--","--","--","--","--","num_intervals",":","int",",","number","of","approx","equal","segments","to","split","the","time","series","into","."]
docstr: Get gradient of lines.
  
  Function to get the gradient of the line of best fit given a
  section of a time series.
  
  Equation adopted from:
  real-statistics.com/regression/total-least-squares
  
  Parameters
  ----------
  Y : a numpy array of shape = [interval_size]
  
  Returns
  -------
  m : an int corresponding to the gradient of the best fit line.
docstr_tok: ["Get","gradient","of","lines",".","Function","to","get","the","gradient","of","the","line","of","best","fit","given","a","section","of","a","time","series",".","Equation","adopted","from",":","real-statistics.com\/regression\/total-least-squares","Parameters","--","--","--","--","--","Y",":","a","numpy","array","of","shape","=","[","interval_size","]","Returns","--","--","--","-","m",":","an","int","corresponding","to","the","gradient","of","the","best","fit","line","."]
code: def _get_gradient(self, Y):
      """Get gradient of lines.
  
      Function to get the gradient of the line of best fit given a
      section of a time series.
  
      Equation adopted from:
      real-statistics.com/regression/total-least-squares
  
      Parameters
      ----------
      Y : a numpy array of shape = [interval_size]
  
      Returns
      -------
      m : an int corresponding to the gradient of the best fit line.
      """
      # Create a list that contains 1,2,3,4,...,len(Y) for the x coordinates.
      X = [(i + 1) for i in range(len(Y))]
  
      # Calculate the mean of both lists
      meanX = statistics.mean(X)
      meanY = statistics.mean(Y)
  
      # Calculate the list (yi-mean(y))^2
      yminYbar = [(y - meanY) ** 2 for y in Y]
      # Calculate the list (xi-mean(x))^2
      xminXbar = [(x - meanX) ** 2 for x in X]
  
      # Sum them to produce w.
      w = sum(yminYbar) - sum(xminXbar)
  
      # Calculate the list (xi-mean(x))*(yi-mean(y))
      temp = []
      for x in range(len(X)):
          temp.append((X[x] - meanX) * (Y[x] - meanY))
  
      # Sum it and multiply by 2 to calculate r
      r = 2 * sum(temp)
  
      if r == 0:
          # remove nans
          m = 0
      else:
          # Gradient is defined as (w+sqrt(w^2+r^2))/r
          m = (w + math.sqrt(w**2 + r**2)) / r
  
      return m
  
file_path: sktime/sktime/transformations/panel/slope.py
imports: import math
  import statistics
  import numpy
  import pandas
  from sktime.datatypes import convert
  from sktime.transformations.base import BaseTransformer
label_desc: Use image node_id 4 for calling the SlopeTransformer obj's underlying member method code with example usage: obj._get_gradient(Y) and returns: m