t - table and degrees of freedom












1












$begingroup$


I am interested if someone can review this process and give me some tips. (I don't have any data science coworkers or friends to collaborate with...) When the script (.py file) below runs, it will output/print:



The total savings are 9793 kWh + - 192 kWh
The total savings are 9793 kWh + - 2.0 %


Ultimately I am attempting calculate "precision" with my results (+ - 192 kWh AND + - 2.0 %) ..



For starters, I cant find this info online so here's a snip from a book I am referencing on calculating data set standard error, then absolute precision, relative precision.



enter image description here



For retrieving my critical t value, I am following these steps from machinelearningmastery.com. This is where the scipy.stats import t package is required.



I cant remember where degrees of freedom comes into play. The machinelearningmastery example, the author uses df = 10 So until I can figure out this, I left that as a default value in my code below. If someone wanted to copy and paste the code below it should run...



I cant remember from college where degrees of freedom comes into play and how to utilize it. The length of the data when its converted into df2 Pandas dataframe is 31, which represents one months data 31 days. Any tips greatly appreciated..



import os
import numpy as np
import pandas as pd
import math
from scipy.stats import t

#actual electrical energy in kWh
actual = 40000

#calculated savings in kWh, output from Keras regression
data = [np.array([[1083.8748]], dtype='float32'), np.array([[998.98773]], dtype='float32'), np.array([[1137.0487]], dtype='float32'), np.array([[1077.2798]], dtype='float32'), np.array([[926.41284]], dtype='float32'),
np.array([[1030.7125]], dtype='float32'), np.array([[1028.0048]], dtype='float32'), np.array([[523.9799]], dtype='float32'), np.array([[1125.092]], dtype='float32'), np.array([[1119.7738]], dtype='float32'),
np.array([[918.6966]], dtype='float32'), np.array([[1112.5186]], dtype='float32'), np.array([[555.6942]], dtype='float32'), np.array([[1096.5643]], dtype='float32'), np.array([[826.35657]], dtype='float32'),
np.array([[1014.35406]], dtype='float32'), np.array([[1027.6962]], dtype='float32'), np.array([[924.20087]], dtype='float32'), np.array([[1035.217]], dtype='float32'), np.array([[1008.9658]], dtype='float32'),
np.array([[970.54047]], dtype='float32'), np.array([[847.0671]], dtype='float32'), np.array([[913.5519]], dtype='float32'), np.array([[1047.0747]], dtype='float32'), np.array([[920.0606]], dtype='float32'),
np.array([[994.2266]], dtype='float32'), np.array([[991.4501]], dtype='float32'), np.array([[972.43256]], dtype='float32'), np.array([[934.8802]], dtype='float32'), np.array([[912.04004]], dtype='float32'), np.array([[1131.297]], dtype='float32')]

#convert data to pandas series then DataFrame
df = pd.Series(data)
df2 = pd.DataFrame(df)

#define sum, standard deviation, mean of calculated savings data
total = df2.sum()
totalStd = np.std(df2.values)
totalMean = df2.mean()

#calculate saings
diff = int(actual - total)

#compute precision of results, starting with standard error
stdErr = totalStd / math.sqrt(len(total.index))

# define probability & degrees of freedom
p = 0.90
degf = 10

# retrieve t value <= probability
t = t.ppf(p, degf)

#calculate absolute precision
absPrec = t * stdErr

#calculate relative precision
relPrec = (100 * (absPrec / diff)).round(decimals=1)


#print results
absSavings = f'The total savings are {int(diff)} kWh + - {int(absPrec)} kWh'
print(absSavings)

relSavings = f'The total savings are {int(diff)} kWh + - {float(relPrec)} %'
print(relSavings)









share|improve this question









$endgroup$

















    1












    $begingroup$


    I am interested if someone can review this process and give me some tips. (I don't have any data science coworkers or friends to collaborate with...) When the script (.py file) below runs, it will output/print:



    The total savings are 9793 kWh + - 192 kWh
    The total savings are 9793 kWh + - 2.0 %


    Ultimately I am attempting calculate "precision" with my results (+ - 192 kWh AND + - 2.0 %) ..



    For starters, I cant find this info online so here's a snip from a book I am referencing on calculating data set standard error, then absolute precision, relative precision.



    enter image description here



    For retrieving my critical t value, I am following these steps from machinelearningmastery.com. This is where the scipy.stats import t package is required.



    I cant remember where degrees of freedom comes into play. The machinelearningmastery example, the author uses df = 10 So until I can figure out this, I left that as a default value in my code below. If someone wanted to copy and paste the code below it should run...



    I cant remember from college where degrees of freedom comes into play and how to utilize it. The length of the data when its converted into df2 Pandas dataframe is 31, which represents one months data 31 days. Any tips greatly appreciated..



    import os
    import numpy as np
    import pandas as pd
    import math
    from scipy.stats import t

    #actual electrical energy in kWh
    actual = 40000

    #calculated savings in kWh, output from Keras regression
    data = [np.array([[1083.8748]], dtype='float32'), np.array([[998.98773]], dtype='float32'), np.array([[1137.0487]], dtype='float32'), np.array([[1077.2798]], dtype='float32'), np.array([[926.41284]], dtype='float32'),
    np.array([[1030.7125]], dtype='float32'), np.array([[1028.0048]], dtype='float32'), np.array([[523.9799]], dtype='float32'), np.array([[1125.092]], dtype='float32'), np.array([[1119.7738]], dtype='float32'),
    np.array([[918.6966]], dtype='float32'), np.array([[1112.5186]], dtype='float32'), np.array([[555.6942]], dtype='float32'), np.array([[1096.5643]], dtype='float32'), np.array([[826.35657]], dtype='float32'),
    np.array([[1014.35406]], dtype='float32'), np.array([[1027.6962]], dtype='float32'), np.array([[924.20087]], dtype='float32'), np.array([[1035.217]], dtype='float32'), np.array([[1008.9658]], dtype='float32'),
    np.array([[970.54047]], dtype='float32'), np.array([[847.0671]], dtype='float32'), np.array([[913.5519]], dtype='float32'), np.array([[1047.0747]], dtype='float32'), np.array([[920.0606]], dtype='float32'),
    np.array([[994.2266]], dtype='float32'), np.array([[991.4501]], dtype='float32'), np.array([[972.43256]], dtype='float32'), np.array([[934.8802]], dtype='float32'), np.array([[912.04004]], dtype='float32'), np.array([[1131.297]], dtype='float32')]

    #convert data to pandas series then DataFrame
    df = pd.Series(data)
    df2 = pd.DataFrame(df)

    #define sum, standard deviation, mean of calculated savings data
    total = df2.sum()
    totalStd = np.std(df2.values)
    totalMean = df2.mean()

    #calculate saings
    diff = int(actual - total)

    #compute precision of results, starting with standard error
    stdErr = totalStd / math.sqrt(len(total.index))

    # define probability & degrees of freedom
    p = 0.90
    degf = 10

    # retrieve t value <= probability
    t = t.ppf(p, degf)

    #calculate absolute precision
    absPrec = t * stdErr

    #calculate relative precision
    relPrec = (100 * (absPrec / diff)).round(decimals=1)


    #print results
    absSavings = f'The total savings are {int(diff)} kWh + - {int(absPrec)} kWh'
    print(absSavings)

    relSavings = f'The total savings are {int(diff)} kWh + - {float(relPrec)} %'
    print(relSavings)









    share|improve this question









    $endgroup$















      1












      1








      1





      $begingroup$


      I am interested if someone can review this process and give me some tips. (I don't have any data science coworkers or friends to collaborate with...) When the script (.py file) below runs, it will output/print:



      The total savings are 9793 kWh + - 192 kWh
      The total savings are 9793 kWh + - 2.0 %


      Ultimately I am attempting calculate "precision" with my results (+ - 192 kWh AND + - 2.0 %) ..



      For starters, I cant find this info online so here's a snip from a book I am referencing on calculating data set standard error, then absolute precision, relative precision.



      enter image description here



      For retrieving my critical t value, I am following these steps from machinelearningmastery.com. This is where the scipy.stats import t package is required.



      I cant remember where degrees of freedom comes into play. The machinelearningmastery example, the author uses df = 10 So until I can figure out this, I left that as a default value in my code below. If someone wanted to copy and paste the code below it should run...



      I cant remember from college where degrees of freedom comes into play and how to utilize it. The length of the data when its converted into df2 Pandas dataframe is 31, which represents one months data 31 days. Any tips greatly appreciated..



      import os
      import numpy as np
      import pandas as pd
      import math
      from scipy.stats import t

      #actual electrical energy in kWh
      actual = 40000

      #calculated savings in kWh, output from Keras regression
      data = [np.array([[1083.8748]], dtype='float32'), np.array([[998.98773]], dtype='float32'), np.array([[1137.0487]], dtype='float32'), np.array([[1077.2798]], dtype='float32'), np.array([[926.41284]], dtype='float32'),
      np.array([[1030.7125]], dtype='float32'), np.array([[1028.0048]], dtype='float32'), np.array([[523.9799]], dtype='float32'), np.array([[1125.092]], dtype='float32'), np.array([[1119.7738]], dtype='float32'),
      np.array([[918.6966]], dtype='float32'), np.array([[1112.5186]], dtype='float32'), np.array([[555.6942]], dtype='float32'), np.array([[1096.5643]], dtype='float32'), np.array([[826.35657]], dtype='float32'),
      np.array([[1014.35406]], dtype='float32'), np.array([[1027.6962]], dtype='float32'), np.array([[924.20087]], dtype='float32'), np.array([[1035.217]], dtype='float32'), np.array([[1008.9658]], dtype='float32'),
      np.array([[970.54047]], dtype='float32'), np.array([[847.0671]], dtype='float32'), np.array([[913.5519]], dtype='float32'), np.array([[1047.0747]], dtype='float32'), np.array([[920.0606]], dtype='float32'),
      np.array([[994.2266]], dtype='float32'), np.array([[991.4501]], dtype='float32'), np.array([[972.43256]], dtype='float32'), np.array([[934.8802]], dtype='float32'), np.array([[912.04004]], dtype='float32'), np.array([[1131.297]], dtype='float32')]

      #convert data to pandas series then DataFrame
      df = pd.Series(data)
      df2 = pd.DataFrame(df)

      #define sum, standard deviation, mean of calculated savings data
      total = df2.sum()
      totalStd = np.std(df2.values)
      totalMean = df2.mean()

      #calculate saings
      diff = int(actual - total)

      #compute precision of results, starting with standard error
      stdErr = totalStd / math.sqrt(len(total.index))

      # define probability & degrees of freedom
      p = 0.90
      degf = 10

      # retrieve t value <= probability
      t = t.ppf(p, degf)

      #calculate absolute precision
      absPrec = t * stdErr

      #calculate relative precision
      relPrec = (100 * (absPrec / diff)).round(decimals=1)


      #print results
      absSavings = f'The total savings are {int(diff)} kWh + - {int(absPrec)} kWh'
      print(absSavings)

      relSavings = f'The total savings are {int(diff)} kWh + - {float(relPrec)} %'
      print(relSavings)









      share|improve this question









      $endgroup$




      I am interested if someone can review this process and give me some tips. (I don't have any data science coworkers or friends to collaborate with...) When the script (.py file) below runs, it will output/print:



      The total savings are 9793 kWh + - 192 kWh
      The total savings are 9793 kWh + - 2.0 %


      Ultimately I am attempting calculate "precision" with my results (+ - 192 kWh AND + - 2.0 %) ..



      For starters, I cant find this info online so here's a snip from a book I am referencing on calculating data set standard error, then absolute precision, relative precision.



      enter image description here



      For retrieving my critical t value, I am following these steps from machinelearningmastery.com. This is where the scipy.stats import t package is required.



      I cant remember where degrees of freedom comes into play. The machinelearningmastery example, the author uses df = 10 So until I can figure out this, I left that as a default value in my code below. If someone wanted to copy and paste the code below it should run...



      I cant remember from college where degrees of freedom comes into play and how to utilize it. The length of the data when its converted into df2 Pandas dataframe is 31, which represents one months data 31 days. Any tips greatly appreciated..



      import os
      import numpy as np
      import pandas as pd
      import math
      from scipy.stats import t

      #actual electrical energy in kWh
      actual = 40000

      #calculated savings in kWh, output from Keras regression
      data = [np.array([[1083.8748]], dtype='float32'), np.array([[998.98773]], dtype='float32'), np.array([[1137.0487]], dtype='float32'), np.array([[1077.2798]], dtype='float32'), np.array([[926.41284]], dtype='float32'),
      np.array([[1030.7125]], dtype='float32'), np.array([[1028.0048]], dtype='float32'), np.array([[523.9799]], dtype='float32'), np.array([[1125.092]], dtype='float32'), np.array([[1119.7738]], dtype='float32'),
      np.array([[918.6966]], dtype='float32'), np.array([[1112.5186]], dtype='float32'), np.array([[555.6942]], dtype='float32'), np.array([[1096.5643]], dtype='float32'), np.array([[826.35657]], dtype='float32'),
      np.array([[1014.35406]], dtype='float32'), np.array([[1027.6962]], dtype='float32'), np.array([[924.20087]], dtype='float32'), np.array([[1035.217]], dtype='float32'), np.array([[1008.9658]], dtype='float32'),
      np.array([[970.54047]], dtype='float32'), np.array([[847.0671]], dtype='float32'), np.array([[913.5519]], dtype='float32'), np.array([[1047.0747]], dtype='float32'), np.array([[920.0606]], dtype='float32'),
      np.array([[994.2266]], dtype='float32'), np.array([[991.4501]], dtype='float32'), np.array([[972.43256]], dtype='float32'), np.array([[934.8802]], dtype='float32'), np.array([[912.04004]], dtype='float32'), np.array([[1131.297]], dtype='float32')]

      #convert data to pandas series then DataFrame
      df = pd.Series(data)
      df2 = pd.DataFrame(df)

      #define sum, standard deviation, mean of calculated savings data
      total = df2.sum()
      totalStd = np.std(df2.values)
      totalMean = df2.mean()

      #calculate saings
      diff = int(actual - total)

      #compute precision of results, starting with standard error
      stdErr = totalStd / math.sqrt(len(total.index))

      # define probability & degrees of freedom
      p = 0.90
      degf = 10

      # retrieve t value <= probability
      t = t.ppf(p, degf)

      #calculate absolute precision
      absPrec = t * stdErr

      #calculate relative precision
      relPrec = (100 * (absPrec / diff)).round(decimals=1)


      #print results
      absSavings = f'The total savings are {int(diff)} kWh + - {int(absPrec)} kWh'
      print(absSavings)

      relSavings = f'The total savings are {int(diff)} kWh + - {float(relPrec)} %'
      print(relSavings)






      python statistics scipy






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 12 hours ago









      HenryHubHenryHub

      1617




      1617






















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "557"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f47742%2ft-table-and-degrees-of-freedom%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Data Science Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f47742%2ft-table-and-degrees-of-freedom%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to label and detect the document text images

          Vallis Paradisi

          Tabula Rosettana