尝试使用scipy.optimize.brute查找最佳值。 经过训练的模型的特征之一是取值介于0到55之间。
我需要确定应将此功能分配给哪个值,以获取最接近900的预测值。有人可以帮我提供python代码吗?
from scipy import optimize
target_temper = 900 # Оптимальная температура
x_range = (0, 55)
def predictor(x):
a=xg_reg.predict(x) - target_temper
return np.abs(a)
resbrute = optimize.brute(predictor, x_range, full_output=True, finish=optimize.fmin)
...
答案 0 :(得分:0)
最后找出解决方案!
target_temper = 953 # The optimal value
x_col_name = 'Навеска фторида, кг(t)' # The variable for which I need to iterate over the values from 0 to 66
x_range = (0, 66)
x_step = 0.5
rrange = (slice(x_range[0], x_range[1], x_step),)
def predictor(n):
data_line = X.tail(1)
data_line[variable_column_name] = n
a=xg_reg.predict(data_line) - target_temper
return np.abs(a)
resbrute = optimize.brute(predictor, rrange, full_output=True, finish=optimize.fmin)
optimal_value = resbrute[0]