当前位置: 首页>>代码示例>>Python>>正文


Python learning_curve.validation_curve方法代码示例

本文整理汇总了Python中sklearn.learning_curve.validation_curve方法的典型用法代码示例。如果您正苦于以下问题:Python learning_curve.validation_curve方法的具体用法?Python learning_curve.validation_curve怎么用?Python learning_curve.validation_curve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.learning_curve的用法示例。


在下文中一共展示了learning_curve.validation_curve方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GenerateValidationCurve

# 需要导入模块: from sklearn import learning_curve [as 别名]
# 或者: from sklearn.learning_curve import validation_curve [as 别名]
def GenerateValidationCurve(estimator, X, y):
    #todo: edit parameters
    #generate validation curve data
    num_resources = -1 #engage all available CPUs and GPUs
    alpha_range = [0.0001, 0.001, 0.01, 0.1, 1.0, 10.0]#alpha
    #titrating hidden layer amount and size
    num_hidden_layers = 2
    hidden_units_range1 = [32]*num_hidden_layers
    hidden_units_range2 = [64]*num_hidden_layers
    hidden_units_range3 = [128]*num_hidden_layers
    hidden_units_range4 = [256]*num_hidden_layers
    hidden_units_range5 = [512]*num_hidden_layers
    hidden_units_range6 = [1024]*num_hidden_layers
    hidden_units_range7 = [2048]*num_hidden_layers
    hidden_units_range8 = [4096]*num_hidden_layers
    hidden_units_range = [hidden_units_range1, hidden_units_range2, hidden_units_range3, hidden_units_range4,
                          hidden_units_range5, hidden_units_range6, hidden_units_range7, hidden_units_range8]

    train_scores, test_scores = validation_curve(estimator=estimator, X=X, y=y, param_name='regressor__hidden_units', param_range=hidden_units_range, cv=10, n_jobs=num_resources)
    train_mean = np.mean(train_scores, axis = 1)
    train_std = np.std(train_scores, axis=1)
    test_mean = np.mean(test_scores, axis=1)
    test_std = np.std(test_scores, axis=1)
    PlotValidationCurve(hidden_units_range, train_mean, train_std, test_mean, test_std) 
开发者ID:TeoZosa,项目名称:WaNN,代码行数:26,代码来源:policy_net_script.py

示例2: drawValidationCurve

# 需要导入模块: from sklearn import learning_curve [as 别名]
# 或者: from sklearn.learning_curve import validation_curve [as 别名]
def drawValidationCurve(self):
        """
        To draw the validation curve
        :return:NA
        """
        X, y = self.X_train, self.y_train.ravel()
        indices = np.arange(y.shape[0])
        #np.random.shuffle(indices)
        X, y = X[indices], y[indices]

        train_sizes = range(5,700)
        train_scores, valid_scores = validation_curve(self.adaReg, X, y, "n_estimators",
                                              train_sizes, cv=5, scoring='mean_squared_error')
        train_scores = -1.0/5 *train_scores
        valid_scores = -1.0/5 *valid_scores

        train_scores_mean = np.mean(train_scores, axis=1)
        train_scores_std = np.std(train_scores, axis=1)
        valid_scores_mean = np.mean(valid_scores, axis=1)
        valid_scores_std = np.std(valid_scores, axis=1)

        plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
                     train_scores_mean + train_scores_std, alpha=0.1,
                     color="r")
        plt.fill_between(train_sizes, valid_scores_mean - valid_scores_std,
                         valid_scores_mean + valid_scores_std, alpha=0.1, color="g")
        plt.plot(train_sizes, train_scores_mean, 'o-', color="r",
                 label="Training MSE")
        plt.plot(train_sizes, valid_scores_mean, '*-', color="g",
                 label="Cross-validation MSE")

        plt.legend(loc="best")

        plt.xlabel('Estimators')
        plt.ylabel('MSE')
        plt.title('Validation Curve with AdaBoost-DecisionTree Regression\n on the parameter of Estimators when the Decsion Tree has max depth=10')
        plt.grid(True)
        plt.show() 
开发者ID:junlulocky,项目名称:AirTicketPredicting,代码行数:40,代码来源:RegressionAdaBoost.py

示例3: drawValidationCurve

# 需要导入模块: from sklearn import learning_curve [as 别名]
# 或者: from sklearn.learning_curve import validation_curve [as 别名]
def drawValidationCurve(self):
        """
        To draw the validation curve
        :return:NA
        """
        X, y = self.X_train, self.y_train.ravel()
        indices = np.arange(y.shape[0])
        #np.random.shuffle(indices)
        X, y = X[indices], y[indices]

        train_sizes = range(2,60)
        train_scores, valid_scores = validation_curve(DecisionTreeRegressor(max_features=None), X, y, "max_depth",
                                              train_sizes, cv=5, scoring='mean_squared_error')
        train_scores = -1.0/5 *train_scores
        valid_scores = -1.0/5 *valid_scores

        train_scores_mean = np.mean(train_scores, axis=1)
        train_scores_std = np.std(train_scores, axis=1)
        valid_scores_mean = np.mean(valid_scores, axis=1)
        valid_scores_std = np.std(valid_scores, axis=1)

        plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
                     train_scores_mean + train_scores_std, alpha=0.1,
                     color="r")
        plt.fill_between(train_sizes, valid_scores_mean - valid_scores_std,
                         valid_scores_mean + valid_scores_std, alpha=0.1, color="g")
        plt.plot(train_sizes, train_scores_mean, 'o-', color="r",
                 label="Training MSE")
        plt.plot(train_sizes, valid_scores_mean, '*-', color="g",
                 label="Cross-validation MSE")

        plt.legend(loc="best")

        plt.xlabel('Max Depth')
        plt.ylabel('MSE')
        plt.title('Validation Curve with Decision \nTree Regression on the parameter of Max Depth')
        plt.grid(True)
        plt.show() 
开发者ID:junlulocky,项目名称:AirTicketPredicting,代码行数:40,代码来源:RegressionDecisionTree.py

示例4: drawValidationCurve

# 需要导入模块: from sklearn import learning_curve [as 别名]
# 或者: from sklearn.learning_curve import validation_curve [as 别名]
def drawValidationCurve(self):
        """
        To draw the validation curve
        :return:NA
        """
        X, y = self.X_train, self.y_train.ravel()
        indices = np.arange(y.shape[0])
        #np.random.shuffle(indices)
        X, y = X[indices], y[indices]

        train_sizes = range(2,100,2)
        train_scores, valid_scores = validation_curve(self.regr, X, y, "n_neighbors",
                                              train_sizes, cv=5, scoring='mean_squared_error')
        train_scores = -1.0/5*train_scores
        valid_scores = -1.0/5*valid_scores

        train_scores_mean = np.mean(train_scores, axis=1)
        train_scores_std = np.std(train_scores, axis=1)
        valid_scores_mean = np.mean(valid_scores, axis=1)
        valid_scores_std = np.std(valid_scores, axis=1)

        plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
                     train_scores_mean + train_scores_std, alpha=0.1,
                     color="r")
        plt.fill_between(train_sizes, valid_scores_mean - valid_scores_std,
                         valid_scores_mean + valid_scores_std, alpha=0.1, color="g")
        plt.plot(train_sizes, train_scores_mean, 'o-', color="r",
                 label="Training MSE")
        plt.plot(train_sizes, valid_scores_mean, '*-', color="g",
                 label="Cross-validation MSE")

        plt.legend(loc="best")

        plt.xlabel('K Neighbors')
        plt.ylabel('MSE')
        plt.title('Validation Curve with KNN Regression on the parameter of K Neighbors')
        plt.grid(True)
        plt.show() 
开发者ID:junlulocky,项目名称:AirTicketPredicting,代码行数:40,代码来源:RegressionKNN.py

示例5: drawValidationCurve_maxdepth

# 需要导入模块: from sklearn import learning_curve [as 别名]
# 或者: from sklearn.learning_curve import validation_curve [as 别名]
def drawValidationCurve_maxdepth(self):
        """
        To draw the validation curve
        :return:NA
        """
        X, y = self.X_train, self.y_train.ravel()
        indices = np.arange(y.shape[0])
        #np.random.shuffle(indices)
        X, y = X[indices], y[indices]

        train_sizes = range(1,60)
        train_scores, valid_scores = validation_curve(self.model, X, y, "max_depth",
                                              train_sizes, cv=5, scoring='mean_squared_error')
        train_scores = -1.0/5*train_scores
        valid_scores = -1.0/5*valid_scores

        train_scores_mean = np.mean(train_scores, axis=1)
        train_scores_std = np.std(train_scores, axis=1)
        valid_scores_mean = np.mean(valid_scores, axis=1)
        valid_scores_std = np.std(valid_scores, axis=1)

        plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
                     train_scores_mean + train_scores_std, alpha=0.1,
                     color="r")
        plt.fill_between(train_sizes, valid_scores_mean - valid_scores_std,
                         valid_scores_mean + valid_scores_std, alpha=0.1, color="g")
        plt.plot(train_sizes, train_scores_mean, 'o-', color="r",
                 label="Training MSE")
        plt.plot(train_sizes, valid_scores_mean, '*-', color="g",
                 label="Cross-validation MSE")

        plt.legend(loc="best")

        plt.xlabel('Max Depth')
        plt.ylabel('MSE')
        plt.title('Validation Curve with Random Forest Regression \non the parameter of Max Depth when n_estimators=32')
        plt.grid(True)
        plt.show() 
开发者ID:junlulocky,项目名称:AirTicketPredicting,代码行数:40,代码来源:RegressionRandomForest.py

示例6: drawValidationCurve_estimators

# 需要导入模块: from sklearn import learning_curve [as 别名]
# 或者: from sklearn.learning_curve import validation_curve [as 别名]
def drawValidationCurve_estimators(self):
        """
        To draw the validation curve
        :return:NA
        """
        X, y = self.X_train, self.y_train.ravel()
        indices = np.arange(y.shape[0])
        #np.random.shuffle(indices)
        X, y = X[indices], y[indices]

        train_sizes = range(1,40)
        train_scores, valid_scores = validation_curve(self.model, X, y, "n_estimators",
                                              train_sizes, cv=5, scoring='mean_squared_error')
        train_scores = -1.0/5*train_scores
        valid_scores = -1.0/5*valid_scores

        train_scores_mean = np.mean(train_scores, axis=1)
        train_scores_std = np.std(train_scores, axis=1)
        valid_scores_mean = np.mean(valid_scores, axis=1)
        valid_scores_std = np.std(valid_scores, axis=1)

        plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
                     train_scores_mean + train_scores_std, alpha=0.1,
                     color="r")
        plt.fill_between(train_sizes, valid_scores_mean - valid_scores_std,
                         valid_scores_mean + valid_scores_std, alpha=0.1, color="g")
        plt.plot(train_sizes, train_scores_mean, 'o-', color="r",
                 label="Training MSE")
        plt.plot(train_sizes, valid_scores_mean, '*-', color="g",
                 label="Cross-validation MSE")

        plt.legend(loc="best")

        plt.xlabel('Estimators')
        plt.ylabel('MSE')
        plt.title('Validation Curve with Random Forest Regression \non the parameter of estimators when max_depth=39')
        plt.grid(True)
        plt.show() 
开发者ID:junlulocky,项目名称:AirTicketPredicting,代码行数:40,代码来源:RegressionRandomForest.py

示例7: drawValidationCurve

# 需要导入模块: from sklearn import learning_curve [as 别名]
# 或者: from sklearn.learning_curve import validation_curve [as 别名]
def drawValidationCurve(self):
        """
        To draw the validation curve
        :return:NA
        """
        X, y = self.X_train, self.y_train.ravel()
        indices = np.arange(y.shape[0])
        np.random.shuffle(indices)
        X, y = X[indices], y[indices]

        train_sizes = range(1,60)
        train_scores, valid_scores = validation_curve(self.clf, X, y, "n_neighbors",
                                              train_sizes, cv=5)

        train_scores_mean = np.mean(train_scores, axis=1)
        train_scores_std = np.std(train_scores, axis=1)
        valid_scores_mean = np.mean(valid_scores, axis=1)
        valid_scores_std = np.std(valid_scores, axis=1)

        plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
                     train_scores_mean + train_scores_std, alpha=0.1,
                     color="r")
        plt.fill_between(train_sizes, valid_scores_mean - valid_scores_std,
                         valid_scores_mean + valid_scores_std, alpha=0.1, color="g")
        plt.plot(train_sizes, train_scores_mean, 'o-', color="r",
                 label="Training Precision")
        plt.plot(train_sizes, valid_scores_mean, '*-', color="g",
                 label="Cross-validation Precision")

        plt.legend(loc="best")

        plt.xlabel('K Neighbors')
        plt.ylabel('Precision')
        plt.title('Validation Curve with KNN on the parameter of K')
        plt.grid(True)
        plt.show() 
开发者ID:junlulocky,项目名称:AirTicketPredicting,代码行数:38,代码来源:ClassificationKNN.py

示例8: drawValidationCurve_maxdepth

# 需要导入模块: from sklearn import learning_curve [as 别名]
# 或者: from sklearn.learning_curve import validation_curve [as 别名]
def drawValidationCurve_maxdepth(self):
        """
        To draw the validation curve
        :return:NA
        """
        X, y = self.X_train, self.y_train.ravel()
        indices = np.arange(y.shape[0])
        np.random.shuffle(indices)
        X, y = X[indices], y[indices]

        train_sizes = range(2,60)
        train_scores, valid_scores = validation_curve(self.clf, X, y, "max_depth",
                                              train_sizes, cv=5)

        train_scores_mean = np.mean(train_scores, axis=1)
        train_scores_std = np.std(train_scores, axis=1)
        valid_scores_mean = np.mean(valid_scores, axis=1)
        valid_scores_std = np.std(valid_scores, axis=1)

        plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
                     train_scores_mean + train_scores_std, alpha=0.1,
                     color="r")
        plt.fill_between(train_sizes, valid_scores_mean - valid_scores_std,
                         valid_scores_mean + valid_scores_std, alpha=0.1, color="g")
        plt.plot(train_sizes, train_scores_mean, 'o-', color="r",
                 label="Training Precision")
        plt.plot(train_sizes, valid_scores_mean, '*-', color="g",
                 label="Cross-validation Precision")

        plt.legend(loc="best")

        plt.xlabel('Max Depth')
        plt.ylabel('Precision')
        plt.title('Validation Curve with Random Forest Classification\n on the parameter of Max Depth when n_stimators=20')
        plt.grid(True)
        plt.show() 
开发者ID:junlulocky,项目名称:AirTicketPredicting,代码行数:38,代码来源:ClassificationRandomForest.py

示例9: drawValidationCurve_estimators

# 需要导入模块: from sklearn import learning_curve [as 别名]
# 或者: from sklearn.learning_curve import validation_curve [as 别名]
def drawValidationCurve_estimators(self):
        """
        To draw the validation curve
        :return:NA
        """
        X, y = self.X_train, self.y_train.ravel()
        indices = np.arange(y.shape[0])
        np.random.shuffle(indices)
        X, y = X[indices], y[indices]

        train_sizes = range(2,40)
        train_scores, valid_scores = validation_curve(self.clf, X, y, "n_estimators",
                                              train_sizes, cv=5)

        train_scores_mean = np.mean(train_scores, axis=1)
        train_scores_std = np.std(train_scores, axis=1)
        valid_scores_mean = np.mean(valid_scores, axis=1)
        valid_scores_std = np.std(valid_scores, axis=1)

        plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
                     train_scores_mean + train_scores_std, alpha=0.1,
                     color="r")
        plt.fill_between(train_sizes, valid_scores_mean - valid_scores_std,
                         valid_scores_mean + valid_scores_std, alpha=0.1, color="g")
        plt.plot(train_sizes, train_scores_mean, 'o-', color="r",
                 label="Training Precision")
        plt.plot(train_sizes, valid_scores_mean, '*-', color="g",
                 label="Cross-validation Precision")

        plt.legend(loc="best")

        plt.xlabel('Estimators')
        plt.ylabel('Precision')
        plt.title('Validation Curve with Random Forest Classification\n on the parameter of Estimators when Max Depth=30')
        plt.grid(True)
        plt.show() 
开发者ID:junlulocky,项目名称:AirTicketPredicting,代码行数:38,代码来源:ClassificationRandomForest.py

示例10: drawValidationCurve

# 需要导入模块: from sklearn import learning_curve [as 别名]
# 或者: from sklearn.learning_curve import validation_curve [as 别名]
def drawValidationCurve(self):
        """
        To draw the validation curve
        :return:NA
        """
        X, y = self.X_train, self.y_train.ravel()
        indices = np.arange(y.shape[0])
        np.random.shuffle(indices)
        X, y = X[indices], y[indices]

        train_sizes = range(2,75)
        train_scores, valid_scores = validation_curve(self.ada, X, y, "n_estimators",
                                              train_sizes, cv=5)

        train_scores_mean = np.mean(train_scores, axis=1)
        train_scores_std = np.std(train_scores, axis=1)
        valid_scores_mean = np.mean(valid_scores, axis=1)
        valid_scores_std = np.std(valid_scores, axis=1)

        plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
                     train_scores_mean + train_scores_std, alpha=0.1,
                     color="r")
        plt.fill_between(train_sizes, valid_scores_mean - valid_scores_std,
                         valid_scores_mean + valid_scores_std, alpha=0.1, color="g")
        plt.plot(train_sizes, train_scores_mean, 'o-', color="r",
                 label="Training Precision")
        plt.plot(train_sizes, valid_scores_mean, '*-', color="g",
                 label="Cross-validation Precision")

        plt.legend(loc="best")

        plt.xlabel('Estimators')
        plt.ylabel('Precision')
        plt.title('Validation Curve with AdaBoost-DecisionTree on the parameter of Estimators')
        plt.grid(True)
        plt.show() 
开发者ID:junlulocky,项目名称:AirTicketPredicting,代码行数:38,代码来源:ClassificationAdaBoost.py

示例11: drawValidationCurve

# 需要导入模块: from sklearn import learning_curve [as 别名]
# 或者: from sklearn.learning_curve import validation_curve [as 别名]
def drawValidationCurve(self):
        """
        To draw the validation curve
        :return:NA
        """
        X, y = self.X_train, self.y_train.ravel()
        indices = np.arange(y.shape[0])
        np.random.shuffle(indices)
        X, y = X[indices], y[indices]

        train_sizes = range(2,60)
        train_scores, valid_scores = validation_curve(self.clf, X, y, "max_depth",
                                              train_sizes, cv=5)

        train_scores_mean = np.mean(train_scores, axis=1)
        train_scores_std = np.std(train_scores, axis=1)
        valid_scores_mean = np.mean(valid_scores, axis=1)
        valid_scores_std = np.std(valid_scores, axis=1)

        plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
                     train_scores_mean + train_scores_std, alpha=0.1,
                     color="r")
        plt.fill_between(train_sizes, valid_scores_mean - valid_scores_std,
                         valid_scores_mean + valid_scores_std, alpha=0.1, color="g")
        plt.plot(train_sizes, train_scores_mean, 'o-', color="r",
                 label="Training Precision")
        plt.plot(train_sizes, valid_scores_mean, '*-', color="g",
                 label="Cross-validation Precision")

        plt.legend(loc="best")

        plt.xlabel('Max Depth(log2(all features) to be considered) ')
        plt.ylabel('Precision')
        plt.title('Validation Curve with Decision Tree on the parameter of Max Depth')
        plt.grid(True)
        plt.show() 
开发者ID:junlulocky,项目名称:AirTicketPredicting,代码行数:38,代码来源:ClassificationDecisionTree.py

示例12: test_validation_curve

# 需要导入模块: from sklearn import learning_curve [as 别名]
# 或者: from sklearn.learning_curve import validation_curve [as 别名]
def test_validation_curve():
    '''
    test validation_curve with LinerSVC and different C
    :return:  None
    '''
    digits = load_digits()
    X,y=digits.data,digits.target
    param_name="C"
    param_range = np.logspace(-2, 2)
    train_scores, test_scores = validation_curve(LinearSVC(), X, y, param_name=param_name,
             param_range=param_range,cv=10, scoring="accuracy")

    train_scores_mean = np.mean(train_scores, axis=1)
    train_scores_std = np.std(train_scores, axis=1)
    test_scores_mean = np.mean(test_scores, axis=1)
    test_scores_std = np.std(test_scores, axis=1)

    fig=plt.figure()
    ax=fig.add_subplot(1,1,1)

    ax.semilogx(param_range, train_scores_mean, label="Training Accuracy", color="r")
    ax.fill_between(param_range, train_scores_mean - train_scores_std,
                     train_scores_mean + train_scores_std, alpha=0.2, color="r")
    ax.semilogx(param_range, test_scores_mean, label="Testing Accuracy", color="g")
    ax.fill_between(param_range, test_scores_mean - test_scores_std,
                     test_scores_mean + test_scores_std, alpha=0.2, color="g")

    ax.set_title("Validation Curve with LinearSVC")
    ax.set_xlabel("C")
    ax.set_ylabel("Score")
    ax.set_ylim(0,1.1)
    ax.legend(loc='best')
    plt.show() 
开发者ID:JasonK93,项目名称:ML-note,代码行数:35,代码来源:12.3 validation_curve.py

示例13: test_validation_curve

# 需要导入模块: from sklearn import learning_curve [as 别名]
# 或者: from sklearn.learning_curve import validation_curve [as 别名]
def test_validation_curve():
    X, y = make_classification(n_samples=2, n_features=1, n_informative=1,
                               n_redundant=0, n_classes=2,
                               n_clusters_per_class=1, random_state=0)
    param_range = np.linspace(0, 1, 10)
    with warnings.catch_warnings(record=True) as w:
        train_scores, test_scores = validation_curve(
            MockEstimatorWithParameter(), X, y, param_name="param",
            param_range=param_range, cv=2
        )
    if len(w) > 0:
        raise RuntimeError("Unexpected warning: %r" % w[0].message)

    assert_array_almost_equal(train_scores.mean(axis=1), param_range)
    assert_array_almost_equal(test_scores.mean(axis=1), 1 - param_range) 
开发者ID:angadgill,项目名称:Parallel-SGD,代码行数:17,代码来源:test_learning_curve.py


注:本文中的sklearn.learning_curve.validation_curve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。