Linear Regression_Intro page 10 生成数据 NumberObservations=100 minVal=1 maxVal=20 X = np.random.uniform(minVal,maxVal,(NumberObservations,1)) print(X.shape) #Add you code below to define error and Y based on the information above def generateY(x): Y = np.array(100) Y = 10 + 5*x #print(Y) gaussian_noise = np.random.normal(0, 1, 100).reshape(100,1) #print(gaussian_noise) Y = Y + gaussian_noise return Y Y = generateY(X) print(Y) 线性回归 def calculate_RSS(B0, B1, testX, testY): testX = np.array(testX) testY = np.array(testY) predictY = testX*B1+B0 RSS = sum((testY-predictY)*(testY-predictY)) return RSS def linear_regression(B0, B1, trainX, trainY, iteration=10000, learning_rate=0.……

阅读全文