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

时间:2021-02-05 14:16:10

标签: python machine-learning scikit-learn neural-network regression

我正在尝试使用 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,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,"o", color = "blue")

enter image description here

0 个答案:

没有答案