Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. #!/usr/bin/python2.7
  2. #Benjamin Schmidt Test 3 Code
  3. # Create a function that returns the mean absolute error percentage, given 2 lists in the following dictionary as input (35 pts)
  4. # Test the function by calling it with the following inputs (15 pts):
  5. dataDict = {'x1':[2,6,3,5,7,9,1,6,9,1,2,5,7,2,9], 'x2':[3,5,2,5,7,3,3,3,8,1,2,5,5,9,1]}
  6. #i guess i should just assume that list 1 is the actual and forcasted
  7. #im also going to assume "n" in the mape equation in the total number of points (lenght of one of the lists)
  8. #funcion(dictionary, key1, key2)
  9. def mape(di2,w,z):
  10.     for key in di2:
  11.         difs=[x - y for (x, y) in zip(di2[w], di2[z])]
  12.         divid=[float(c)/t for c,t in zip(difs, di2[w])]
  13.         sol = 0
  14.         for i in divid:
  15.             sol += i
  16.         sol=abs(sol)
  17.         solved=(100/(len(di2[w])))*sol
  18.     return solved
  19. solution=mape(dataDict,'x1','x2')
  20. print solution
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement