MLP 回归器用两个变量预测函数

问题描述

我正在尝试使用 sklearn 库中的 MLP 回归器来预测 f(x,T) 曲线。主要目标是为训练数据挑选 5 条曲线并预测其他 3 条此时我只能预测给定值 T 的曲线点,这是获得 f(x) 预测的主要目标) 每个值 T 的曲线。有人可以帮我修改我的代码以实现该意图。Image of curves to predict 谢谢

import numpy as np
import matplotlib.pylab as plt
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPRegressor
from sklearn.metrics import r2_score

x = np.linspace(1,40,100) 
T = np.array([1,2,3,4,5,6,7,8])
def f(x,T):
    return T * x**2

X_train,X_test,y_train,y_test = train_test_split(x.reshape(-1,1),f(x,1).reshape(-1,test_size = 0.5)
model = MLPRegressor(hidden_layer_sizes = 40,activation = "relu",random_state = 1,max_iter = 512,solver ='lbfgs')
model.fit(X_train,y_train)
expected_y  = y_test 
predicted_y = model.predict(X_test)
print(metrics.r2_score(expected_y1,predicted_y1))

plt.figure(figsize = (16,9))
plt.plot(X_test,y_test,"o",color = "red")
plt.plot(X_test,predicted_y,color = "blue")

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)