Skip to content

Instantly share code, notes, and snippets.

@UMU18
Last active January 23, 2019 03:44
Show Gist options
  • Save UMU18/b33c6c2d91268f63b0a9d700d8ef3b70 to your computer and use it in GitHub Desktop.
Save UMU18/b33c6c2d91268f63b0a9d700d8ef3b70 to your computer and use it in GitHub Desktop.
import numpy as np
from sklearn import linear_model
class MarketingCosts:
# param marketing_expenditure list. Expenditure for each previous campaign.
# param units_sold list. The number of units sold for each previous campaign.
# param desired_units_sold int. Target number of units to sell in the new campaign.
# returns float. Required amount of money to be invested.
@staticmethod
def desired_marketing_expenditure(marketing_expenditure, units_sold, desired_units_sold):
mar_exp=np.asarray(marketing_expenditure).reshape(-1,1)
u_sold=np.asarray(units_sold).reshape(-1,1)
regr = linear_model.LinearRegression()
regr.fit(u_sold, mar_exp)
pred=float(regr.predict(desired_units_sold))
return round(pred,1)
#For example, with the parameters below the function should return 250000.0.
print(MarketingCosts.desired_marketing_expenditure(
[300000, 200000, 400000, 300000, 100000],
[60000, 50000, 90000, 80000, 30000],
60000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment