Last active
January 19, 2019 06:03
-
-
Save atyrachma/23de33d66bba24acf139057407662333 to your computer and use it in GitHub Desktop.
JDS-Marketing-aty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn import linear_model, metrics | |
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): | |
market_exp = np.array(marketing_expenditure) | |
sold = np.array(units_sold) | |
LM = linear_model.LinearRegression() | |
LM.fit(np.reshape(sold,(len(sold),1)),np.reshape(market_exp,(len(market_exp),1))) | |
dapred = LM.predict(np.reshape(sold,(len(sold),1))) | |
mse = metrics.mean_squared_error(np.reshape(market_exp,(len(market_exp),1)), dapred) | |
rmse = np.sqrt(mse) #nilai root mean square error | |
mae = metrics.mean_absolute_error(np.reshape(market_exp,(len(market_exp),1)), dapred) #nilai mean absolute error | |
pred = LM.predict(desired_units_sold) | |
return float(pred) #tanpa pembulatan | |
# return np.round(float(pred),-4) :::untuk melakukan pembulatan ke 250000 | |
#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