微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。