Guest User

Untitled

a guest
Jan 24th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import numpy as np
  2. from sklearn import linear_model
  3.  
  4. class MarketingCosts:
  5.  
  6. # param marketing_expenditure list. Expenditure for each previous campaign.
  7. # param units_sold list. The number of units sold for each previous campaign.
  8. # param desired_units_sold int. Target number of units to sell in the new campaign.
  9. # returns float. Required amount of money to be invested.
  10. @staticmethod
  11. def desired_marketing_expenditure(marketing_expenditure, units_sold, desired_units_sold):
  12. x = np.array(units_sold).reshape(-1,1)
  13. y = np.array(marketing_expenditure).reshape(-1,1)
  14. y_predict = np.array(desired_units_sold).reshape(-1, 1)
  15.  
  16. reg = linear_model.TheilSenRegressor()
  17. reg.fit(x,y)
  18.  
  19. desired_marketing_expenditure = reg.predict(y_predict)
  20. return float(desired_marketing_expenditure)
  21.  
  22.  
  23. #For example, with the parameters below the function should return 250000.0.
  24. print(MarketingCosts.desired_marketing_expenditure(
  25. [300000, 200000, 400000, 300000, 100000],
  26. [60000, 50000, 90000, 80000, 30000],
  27. 60000))
Add Comment
Please, Sign In to add comment