【发布时间】:2018-12-08 21:58:23
【问题描述】:
我尝试从 TestDome 回答这个 question 并得到 250877.19298245612 而不是建议的 250000。请让我出了什么问题。谢谢
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):
X = [[i] for i in units_sold]
reg = linear_model.LinearRegression()
reg.fit(X, marketing_expenditure)
return float(reg.predict(desired_units_sold))
#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))
【问题讨论】:
-
我认为 250877 已经足够接近 25000 了。相差不到 0.5%。代码似乎正确。
-
也许您可以对输出进行后处理以四舍五入
-
您的答案通过了 1 次测试。如果将其舍入到 25000,则您通过了另一项测试,但未通过您之前通过的测试。不知道如何通过最后的测试。好像坏了。
标签: python python-3.x scikit-learn