赞
踩
提示:以下是本篇文章正文内容,下面案例可供参考
代码如下(示例):
x = [1, 1, 2, 2, 2, 4] y = [3, 4, 5, 5, 5, 8] avg_x = 0 sum_square_x = 0 for i in x: avg_x += i/len(x) sum_square_x += i*i print('avg_x: ', avg_x, '\nsum_square_x: ', sum_square_x) avg_y = 0 for i in y: avg_y += i/len(y) print('avg_y: ', avg_y) sum_x_y = 0 for i, j in zip(x, y): sum_x_y += i*j print('sum_x_y: ', sum_x_y) proxy_c = 0 proxy_x1 = 0 proxy_x1 = (sum_x_y - avg_x*avg_y*len(x))/(sum_square_x - avg_x*avg_x*len(x)) proxy_c = avg_y - avg_x * proxy_x1 print(f'求得的回归方程为:\ty = {proxy_c} + {proxy_x1} * x1')
实现的结果::
代码如下(示例):
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns import warnings warnings.filterwarnings('ignore') import ssl ssl._create_default_https_context
回归方程在拟合数据和预测未来发展,等等领域都具有巨大的作用,多多了解,有益无害哦
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。