我修改了线性回归代码,并将预测函数从线性更改为二次。但是,当我尝试绘制最佳拟合线时,它无法正确绘制。
pred = tf.add(tf.add(tf.multiply(tf.pow(X, 2), W1), tf.multiply(X, W2)), b)
print("Epoch:" + str((epoch+1)), "cost=" + str(c), "W1=" + str(sess.run(W1)),"W2=" + str(sess.run(W2)), "b=" + str(sess.run(b)))
plt.plot(trainX, (sess.run(W1)*(trainX**2)) + sess.run(W2)*trainX + sess.run(b), label='Fitted line')
https://i.stack.imgur.com/EE22B.png