← 返回题库
中级

绘制LDA决策边界

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    import matplotlib
    matplotlib.use(____)
    import matplotlib.pyplot as plt
    import numpy as np
    from sklearn.datasets import load_iris
    from sklearn.linear_model import LogisticRegression
    from sklearn.preprocessing import StandardScaler
    iris = load_iris()
    X = iris.data[:, :____]
    y = (____).astype(____)
    scaler = StandardScaler()
    X_s = scaler.fit_transform(____)
    x_min, x_max = X_s[:, ____].min() - ____, X_s[:, ____].max() + ____
    y_min, y_max = X_s[:, ____].min() - ____, X_s[:, ____].max() + ____
    xx, yy = np.meshgrid(np.arange(____), np.arange(____))
    model = LogisticRegression(____).fit(____)
    Z = model.predict(np.c_[xx.ravel(), yy.ravel()]).reshape(____)
    plt.contourf(____)
    plt.scatter(____)
    plt.title(____)
    plt.tight_layout()
    plt.show()
    print(len(np.unique(____)))

示例

输入
solve()
期望输出
2
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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