← 返回题库
中级

残差诊断

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    from sklearn.datasets import load_diabetes
    from sklearn.linear_model import LinearRegression
    from sklearn.model_selection import train_test_split
    from scipy import stats
    import matplotlib.pyplot as plt
    import numpy as np
    diabetes = load_diabetes()
    X_train, X_test, y_train, y_test = train_test_split(____)
    model = LinearRegression()
    model.fit(____)
    y_pred = model.predict(____)
    residuals = y_test - y_pred
    fig, axes = plt.subplots(____, ____, figsize=(____, ____))
    axes[____, ____].scatter(____)
    axes[____, ____].axhline(____, color='____', linestyle='____')
    axes[____, ____].set_xlabel(____)
    axes[____, ____].set_ylabel(____)
    axes[____, ____].set_title(____)
    axes[____, ____].grid(____)
    axes[____, ____].hist(____)
    x = np.linspace(residuals.min(), residuals.max(), ____)
    axes[____, ____].plot(x, stats.norm.pdf(x, np.mean(____), np.std(____)), '____', linewidth=____)
    axes[____, ____].set_xlabel(____)
    axes[____, ____].set_title(____)
    axes[____, ____].grid(____)
    stats.probplot(____)
    axes[____, ____].set_title(____)
    axes[____, ____].scatter(y_pred, np.abs(____), alpha=____, edgecolor='____')
    axes[____, ____].set_xlabel(____)
    axes[____, ____].set_ylabel(____)
    axes[____, ____].set_title(____)
    axes[____, ____].grid(____)
    plt.tight_layout()
    plt.show()
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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