您能否确定该程序关于线性回归的正态方程实现有什么问题



1.在这里我得到了带有大数字的θ值的输出,这是不可用的 2.你能确定它有什么问题吗

import pandas as pd
import matplotlib.pyplot as plt
data=pd.read_csv("headbrain.csv")
data.head()
x=np.array(data["Head Size(cm^3)"].values)
y=np.array(data["Brain Weight(grams)"].values)
print(x.shape
x1=np.ones(len(y))
X=np.array([x,x1])
X.shape
#normal equation creating (x.transpose*x)*(x.transpose*y)
first=np.matmul(X,X.transpose())     #first part in normal equation(x.transpose*x)
second=np.matmul(X,y)                #second part in nornal equation(x.transpose*y)
theta=np.matmul(first,second)         #normal equation for theta
print(theta)
#i return theata values large number which includes e also``` 
import pandas as pd
import matplotlib.pyplot as plt
data=pd.read_csv("headbrain.csv")
data.head()
x=np.array(data["Head Size(cm^3)"].values)
y=np.array(data["Brain Weight(grams)"].values)
print(x.shape)
x1=np.ones(len(y))
X=np.array([x,x1])

X_b = np.c_[np.ones((100, 1)), X]  # add x0 = 1 to each instance
theta_best = np.linalg.inv(X_b.T.dot(X_b)).dot(X_b.T).dot(y)
X_new = np.array([[0], [2]])
X_new_b = np.c_[np.ones((2, 1)), X_new]  # add x0 = 1 to each instance
y_predict = X_new_b.dot(theta_best)
y_predict

相关内容

  • 没有找到相关文章

最新更新