import numpy as np
import matplotlib.pyplot as plt
# 转化成矩阵
X = np.linspace(0,10, num =30).reshape(-1,1)# 斜率和截距,随机生成
w = np.random.randint(1,5, size =1)
b = np.random.randint(1,10, size =1)# 根据一元一次方程是计算目标值y,并加上“噪声”
y = X * w + b + np.random.randn(30,1)
plt.scatter(X, y)# 重新构造X,b,相当于系数w0,前面统一乘以1
X = np.concatenate([X, np.full(shape =(30,1), fill_value =1)], axis =1)# 正规方程求解
theta = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(y).round(2)print('一元一次方程真是的斜率和截距是:', w, b)print('通过sklearn求解的斜率和截距是:',theta)# 根据求解的斜率和截距绘制线性回归线形图
plt.plot(X[:,0], X.dot(theta), color ='green')
from sklearn.linear_model import LinearRegression
import numpy as np
import matplotlib.pyplot as plt
# 生成一列等差数据
X = np.linspace(0,9, num =10).reshape(-1,1)
w = np.random.randint(1,5, size =1)
b = np.random.randint(1,10, size =1)
y = X * w + b + np.random.randn(10,1)
plt.scatter(X, y)
model = LinearRegression()
model.fit(X, y)
w_ = model.coef_
b_ = model.intercept_
print('一元一次方程真是的斜率和截距是:', w, b)print('通过sklearn求解的斜率和截距是:',w_, b_)
plt.plot(X, X.dot(w_)+ b_, color ='green')
问题描述
当我们使用数据库管理工具连接mysql8的时候,可能遇到报错:
Public Key Retrieval is not allowed 解决办法
1、在连接属性中配置allowPublicKeyRetrieval设置为true 2、在连接URL中加上配置allowPublicKeyRetrieval为true