LR回购demo(1)

from sklearn import datasets#引入数据集,sklearn包含众多数据集
from sklearn.model_selection import train_test_split#将数据分为测试集和训练集
from sklearn.model_selection import GridSearchCV #参数
from sklearn.neighbors import KNeighborsClassifier#利用邻近点方式训练数据\
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import accuracy_score
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt


x=np.array([1,2,3,4,5])
y=np.array([1,3,2,3,5])



x_mean=np.mean(x)
y_mean=np.mean(y)
num=0.0
d=0.0
for x_i,y_i in zip(x,y):
    num +=(x_i-x_mean)*(y_i-y_mean)
    d+=(x_i-x_mean)**2

a=num/d
b=y_mean-a*x_mean
print(a)
print(b)
y_hat=a*x+b

plt.scatter(x,y)
plt.plot(x,y_hat,color='r')
plt.axis([0,6,0,6])
plt.show()

在这里插入图片描述

©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页