作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
1.这里我得到了带有大数字的theta值的输出,这是不可用的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
关于python - 你能找出这个关于线性回归的正规方程实现的程序有什么问题吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59207895/
我是一名优秀的程序员,十分优秀!