title: Multiple inputs, how to calculate pewma as output?
body: <p>I'm trying to calculate Pewma using 6 different temperature inputs, but don't understand how to train the model. I successfully read in the data, create 2 different dataframes, one with inputs and one is the column with the values I would like to generate Pewma for. But the closest I've gotten is using the <code>ewm() + mean()</code> function in pandas together, but it doesn't require anything but the data you want to test on.</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import matplotlib.pyplot as plt
  
  T = 20
  t = 0
  alpha_0 = 0.95
  beta = 0.5
  threshold = 0.05
  #newpewma = 0 #first initialization of
  oldpewma = 0
  pewma = 0
  alpha = 0
  
  def calc_alpha(dataset, t, T, col, beta, alpha_calc):
      if t &lt; T:
          alpha = 1-1.0/t
          print("EWMA calc in progress (initialization of MA) - ")
      else:
          alpha = (1 - beta*dataset[col])*alpha_calc
          print("EWMA calc in progress - ")
      return alpha
  
  def calc_pewma(oldpewma, alpha_0, beta, fulldata, testingdata, T, prob, col):
  
      firstcalc = 1-beta*prob
      secondcalc = alpha_0*firstcalc*oldpewma
      thirdcalc = (1-alpha_0*firstcalc)*testingdata[col]
      newpewma = secondcalc + thirdcalc
      return newpewma
  
  #calculate zero-mean
  def calc_zed(std, dataset, lastpewma, col):
      zed = (dataset[col] - lastpewma)/std
      return zed
  
  #calculate probability
  def calc_prob(zed):
      partone = 1/m.sqrt(2*m.pi)
      parttwo = m.pow(zed, 2)
      partthree = -(parttwo/2)
      prob = partone*m.pow(partthree, 1)
      prob = m.fabs(prob)
      return prob
  
  def calc_std(t, y, column):
      deviationPrediction = np.std(y.iloc[1:t, 0])
      return deviationPrediction
  
  
  # Read Excel file, limit to temp columns
  print("Reading in sensor data")
  fullDataTemp = pd.read_excel('tempData.xlsx')
  fullDataTemp = fullDataTemp[["TempLR", "TempK", "TempNW", "TempSW", "TempW", "TempTV", "TempO"]]
  
  # data_cols in lambda function
  predictThisTemp = "TempK"
  print(predictThisTemp + " Chosen for prediction")
  
  #Split data into 2 numpy arrays
  X = np.array(fullDataTemp.drop([predictThisTemp], 1))
  y = np.array(fullDataTemp[predictThisTemp])
  arraylength = len(y)
  
  #split data reformatted to pandas
  df_predict = pd.DataFrame(y)
  df_fulldata = pd.DataFrame(X)
  
  #rolling averages of the data
  df_predict = df_predict.rolling(T).mean()
  df_fulldata = df_fulldata.rolling(T).mean()
  
  pewmaArray = []
  for col in y:
      t= 3
      #t = len(y[col])
      #print(t)
      alpha = calc_alpha(df_predict, t, T, col, beta, alpha)
      std = calc_std(t, df_predict, predictThisTemp)
      zed = calc_zed(std, df_predict, oldpewma, col)
      prob = calc_prob(zed)
      pewma = calc_pewma(pewma, alpha, beta, df_fulldata, df_predict, T, prob)
      pewmaArray.append(pewma)
  
  
  plt.plot(pewmaArray, 'r--')
  plt.show()
  </code></pre>