慕无忌401737
2018-04-08 15:19
我看了一点,但是不是很明白
import numpy as np
from numpy.linalg import inv
from numpy import dot
from numpy import mat
import pandas as pd
dataset = pd.read_csv('data.csv')
print(dataset)
temp = dataset.iloc[:,2:5] #iloc :对数组进行切片
# X = mat([1,2,3]).reshape(3,1)
# Y = 2*X
# # theta = (X'X)^-1X'Y
# #theta = dot(dot(inv(dot(X.T,X)), X.T),T)
# #theta = theta - alpha*(theta*X-Y)*X
# theta = 1.
# alpha = 0.1
# for i in range(100):
# theta = theta + np.sum(alpha *(Y - dot(X,theta))*X.reshape(1,3))/3.#加权平均
# print(theta
Python实现线性回归
26151 学习 · 36 问题
相似问题