fork download
  1.  
  2.  
Success #stdin #stdout 0.02s 7216KB
stdin
import numpy as np
from sklearn.tree import DecisionTreeRegressor

# 定义数据
# 特征:[投资成本, 需求紧俏概率, 需求低弥概率, 服务期, 需求紧俏年收益, 需求低弥年收益]
data = [
    [300, 0.7, 0.3, 10, 100, -20],  # 方案1
    [140, 0.7, 0.3, 10, 40, 30],   # 方案2
    [340, 0.7, 0.3, 10, 95, 30]    # 方案3(考虑扩建后的总投资和收益)
]

# 目标:净现值(NPV)
target = [340, 230, 436]

# 创建决策树模型
model = DecisionTreeRegressor(random_state=42)
model.fit(data, target)

# 预测
predictions = model.predict(data)
print("预测的净现值:", predictions)

# 选择最佳方案
best_scheme = np.argmax(predictions) + 1
print(f"最佳方案是方案{best_scheme},净现值为{predictions[best_scheme - 1]:.2f}万元")
stdout
Standard output is empty