Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. def occurences(selection):
  2. if selection == 'Motorbike':
  3. return np.random.choice([1, 2], p = [0.9, 0.1])
  4. elif selection == 'Car':
  5. return np.random.choice([2, 3, 4], p = [0.35, 0.6, 0.05])
  6. elif selection == 'Bus':
  7. return np.random.choice([3, 4, 5], p = [0.05, 0.9, 0.05])
  8.  
  9. def readings(vehicle_type):
  10. repetition = occurences(vehicle_type)
  11. vehicle_type_list = repetition*[vehicle_type]
  12. if vehicle_type == 'Motorbike':
  13. readings_list = list(np.random.normal(0.5, 0.2, repetition))
  14. elif vehicle_type == 'Car':
  15. readings_list = list(np.random.normal(5.5, 0.3, repetition))
  16. elif vehicle_type == 'Bus':
  17. readings_list = list(np.random.normal(3.5, 0.4, repetition))
  18. sample = pd.DataFrame({'vehicle_type':vehicle_type_list,
  19. 'amp_reading':readings_list})
  20. return sample
  21.  
  22. for count in range(1,301):
  23. choice = np.random.choice(['Motorbike','Car','Bus'], p=[0.333,0.333,0.334])
  24. if choice == 'Motorbike':
  25. new_df = new_df.append(readings(choice))
  26. elif choice == 'Car':
  27. new_df = new_df.append(readings(choice))
  28. elif choice == 'Bus':
  29. new_df = new_df.append(readings(choice))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement