← 返回题库
中级

验证曲线

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    import matplotlib
    matplotlib.use(____)
    import matplotlib.pyplot as plt
    import numpy as np
    from sklearn.datasets import load_iris
    from sklearn.model_selection import validation_curve
    from sklearn.tree import DecisionTreeClassifier
    iris = load_iris()
    X = iris.data
    y = iris.target
    depths = range(____, ____)
    train_scores, test_scores = validation_curve(
        DecisionTreeClassifier(____), X, y,
        param_name='____', param_range=depths, cv=____)
    plt.figure(figsize=(____, ____))
    plt.plot(depths, train_scores.mean(____), label='____')
    plt.plot(depths, test_scores.mean(____), label='____')
    plt.legend()
    plt.title(____)
    plt.tight_layout()
    plt.show()
    print(len(____))

示例

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

登录后即可练习

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