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