← 返回题库
中级

最小二乘法

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    import numpy as np
    import matplotlib.pyplot as plt
    x = np.array(____)
    y = np.array(____)
    n = len(____)
    sum_x = np.sum(____)
    sum_y = np.sum(____)
    sum_xy = np.sum(____)
    sum_x2 = np.sum(____)
    a = (____) / (____)
    b = (____) / n
    print(____)
    plt.figure(figsize=(____, ____))
    plt.scatter(____)
    plt.plot(____)
    plt.xlabel(____)
    plt.ylabel(____)
    plt.title(____)
    plt.legend()
    plt.grid(____)
    plt.show()

示例

输入
solve()
期望输出
拟合直线: y = 1.9900x + 0.0500
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码