Guest User

Untitled

a guest
Jan 23rd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 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. mar_exp=np.asarray(marketing_expenditure).reshape(-1,1)
  13. u_sold=np.asarray(units_sold).reshape(-1,1)
  14. regr = linear_model.LinearRegression()
  15. regr.fit(u_sold, mar_exp)
  16. pred=float(regr.predict(desired_units_sold))
  17. return round(pred,1)
  18.  
  19.  
  20.  
  21. #For example, with the parameters below the function should return 250000.0.
  22. print(MarketingCosts.desired_marketing_expenditure(
  23. [300000, 200000, 400000, 300000, 100000],
  24. [60000, 50000, 90000, 80000, 30000],
  25. 60000))
Add Comment
Please, Sign In to add comment