python多元线性回归及三维可视化⽬标函数:Y=A*X1+B*X2+C 代码:
import numpy as np
from io import StringIO
from urllib import request
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import ssl
中国 东盟自由贸易区import numpy as np
蔗糖浓硫酸def costFunc(X,Y,theta): inner = np.power((X*theta.T)-Y,2)
return np.sum(inner)/(2*len(X))
def gradientDescent(X,Y,theta,alpha,iters):
temp = np.s(theta.shape))
cost = np.zeros(iters)
thetaNums = int(theta.shape[1])乡村
社会学 print(thetaNums)
基尔霍夫定律for i in range(iters):
error = (X*theta.T-Y)
for j in range(thetaNums):
西安pm2.5
derivativeInner = np.multiply(error,X[:,j])
temp[0,j] = theta[0,j] - (alpha*np.sum(derivativeInner)/len(X))
theta = temp
c