zoukankan      html  css  js  c++  java
  • 莫烦python教程学习笔记——learn_curve曲线用于过拟合问题

    # View more python learning tutorial on my Youtube and Youku channel!!!
    
    # Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
    # Youku video tutorial: http://i.youku.com/pythontutorial
    
    """
    Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
    """
    from __future__ import print_function
    from sklearn.learning_curve import  learning_curve
    from sklearn.datasets import load_digits
    from sklearn.svm import SVC
    import matplotlib.pyplot as plt
    import numpy as np
    
    digits = load_digits()
    X = digits.data
    y = digits.target
    train_sizes, train_loss, test_loss= learning_curve(
            SVC(gamma=0.01), X, y, cv=10, scoring='mean_squared_error',
            train_sizes=[0.1, 0.25, 0.5, 0.75, 1])
    train_loss_mean = -np.mean(train_loss, axis=1)
    test_loss_mean = -np.mean(test_loss, axis=1)
    
    plt.plot(train_sizes, train_loss_mean, 'o-', color="r",
                 label="Training")
    plt.plot(train_sizes, test_loss_mean, 'o-', color="g",
                 label="Cross-validation")
    
    plt.xlabel("Training examples")
    plt.ylabel("Loss")
    plt.legend(loc="best")
    plt.show()
  • 相关阅读:
    php hash_hmac HMAC_SHA1 加密
    文件上传最好用绝对路径
    composer 安装插件
    php 账单生成
    php 求当前日期到下一年的实际天数
    php 求两个日期之间相差的天数
    PHP闭包 function() use()
    php 验证参数为0 但不为空
    php 原生mysqli
    前端框架选择
  • 原文地址:https://www.cnblogs.com/simpleDi/p/9964385.html
Copyright © 2011-2022 走看看