Advertisement
evangambit

Untitled

Mar 21st, 2021
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. numStudents = 500
  5. numClasses = 30
  6. numClassesPerStudent = 5
  7.  
  8. studentGoodness = np.random.uniform(0, 4, numStudents)
  9. classDifficulty = np.random.uniform(0, 4, numClasses)
  10.  
  11. def noise():
  12. return np.random.normal(0, 1)
  13.  
  14. X, Y, naiveGpa = [], [], []
  15. for i in range(numStudents):
  16. I = np.arange(numClasses)
  17. # Randomly choose class for students. In this case we have strong students (above
  18. # 75th percentile) prefer harder classes and weaker students prefer easier classes.
  19. if studentGoodness[i] > 3.0:
  20. I = np.argsort(-classDifficulty + np.random.normal(0, 1, numClasses))
  21. else:
  22. I = np.argsort( classDifficulty + np.random.normal(0, 1, numClasses))
  23. for j in I[:numClassesPerStudent]:
  24. X.append([0] * (numStudents + numClasses))
  25. X[-1][i] = 1
  26. X[-1][numStudents + j] = 1
  27. Y.append(studentGoodness[i] - classDifficulty[j] + noise())
  28. naiveGpa.append(sum(Y[-10:]) / 10)
  29.  
  30. X = np.array(X)
  31. Y = np.array(Y)
  32. naiveGpa = np.array(naiveGpa)
  33. w = np.linalg.lstsq(X, Y, rcond=0.0001)[0]
  34. gpa = w[:numStudents]
  35. classDifficulty = w[numStudents:]
  36.  
  37. w -= w.mean(); w /= w.std()
  38. studentGoodness -= studentGoodness.mean(); studentGoodness /= studentGoodness.std()
  39. naiveGpa -= naiveGpa.mean(); naiveGpa /= naiveGpa.std()
  40.  
  41. plt.scatter(studentGoodness, naiveGpa, label='naive gpa')
  42. plt.scatter(studentGoodness, w[:numStudents], label='corrected gpa')
  43. plt.legend()
  44. plt.show()
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement