Skip to content

Instantly share code, notes, and snippets.

@ra312
Created June 6, 2020 10:17
Show Gist options
  • Save ra312/c5e911ad66a74fd953d6f6f16b97d5f7 to your computer and use it in GitHub Desktop.
Save ra312/c5e911ad66a74fd953d6f6f16b97d5f7 to your computer and use it in GitHub Desktop.
correctly solves example case, but linear codependency failed
import numpy as np
from sklearn import linear_model
def desired_marketing_expenditure(marketing_expenditure, units_sold, desired_units_sold):
"""
:param marketing_expenditure: (list) A list of integers with the expenditure for each previous campaign.
:param units_sold: (list) A list of integers with the number of units sold for each previous campaign.
:param desired_units_sold: (integer) Target number of units to sell in the new campaign.
:returns: (float) Required amount of money to be invested.
"""
regr = linear_model.TheilSenRegressor()
units_sold_shaped = np.array(units_sold).reshape(-1,1)
desired_units_sold_shaped = np.array(desired_units_sold).reshape(-1,1)
regr.fit(X=units_sold_shaped, y=marketing_expenditure)
needed_marketing_expenditure = round(regr.predict(desired_units_sold_shaped)[0])
return needed_marketing_expenditure
#For example, with the parameters below, the function should return 250000.0
print(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