zoukankan      html  css  js  c++  java
  • 莫烦python教程学习笔记——validation_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  validation_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
    param_range = np.logspace(-6, -2.3, 5)
    train_loss, test_loss = validation_curve(
            SVC(), X, y, param_name='gamma', param_range=param_range, cv=10,
            scoring='mean_squared_error')
    train_loss_mean = -np.mean(train_loss, axis=1)
    test_loss_mean = -np.mean(test_loss, axis=1)
    
    plt.plot(param_range, train_loss_mean, 'o-', color="r",
                 label="Training")
    plt.plot(param_range, test_loss_mean, 'o-', color="g",
                 label="Cross-validation")
    
    plt.xlabel("gamma")
    plt.ylabel("Loss")
    plt.legend(loc="best")
    plt.show()
  • 相关阅读:
    最优匹配问题
    树的最大独立集
    koa2学习(一)
    vue源码阅读(一)
    一直以为错的一个问题,记录一下
    关于 vuex 的使用忠告
    《javascript设计模式与开发实践》--- (单一职责原则)
    心累
    node 学习(二)
    node 学习(一)
  • 原文地址:https://www.cnblogs.com/simpleDi/p/9964391.html
Copyright © 2011-2022 走看看