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


Python Model.train_k_fold方法代码示例

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


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

示例1: test

# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import train_k_fold [as 别名]
def test(X_train_files, y_train_files, X_test_files, y_test_files, train_out_file, test_out_file,
         train_bad_out_file=None, test_bad_out_file=None,
         model=None, C_set=None, gamma_set=None, epsilon_set=None, k=None):
    X_train = []
    y_train = []
    X_test = []
    y_test = []
    for file in X_train_files:
        X_train.extend(load_data_X(file))
    for file in y_train_files:
        y_train.extend(load_data_y(file))
    for file in X_test_files:
        X_test.extend(load_data_X(file))
    for file in y_test_files:
        y_test.extend(load_data_y(file))

    if model is None:
        if C_set is None:
            C_set = [2 ** x for x in range(-5, 15 + 1)]
        if gamma_set is None:
            gamma_set = [2 ** x for x in range(-15, 3 + 1)]
        if epsilon_set is None:
            epsilon_set = [0.0001, 0.0005, 0.001, 0.005, 0.01, 0.02, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.4, 0.5, 0.6,
                           0.7, 0.8, 0.9, 1, 2]
        if k is None:
            k = 10
        model = Model()
        model.train_k_fold(X_train, y_train, C_set, gamma_set, epsilon_set, k)

    print 'C:', model.get_param_C()
    print 'epsilon:', model.get_param_epsilon()
    print 'gamma:', model.get_param_gamma()

    if train_out_file != '':
        # print "Tocni (train): ", y_train
        predicted_train = model.predict(X_train)
        # print "Dobiveni (train): ", predicted_train
        write_output(train_out_file, predicted_train)
        if (train_bad_out_file is not None):
            write_low_scored(train_bad_out_file, X_train, y_train, predicted_train, 50)

    if test_out_file != '':
        # print "Tocni (test): ", y_test
        predicted_test = model.predict(X_test)
        # print "Dobiveni (test): ", predicted_test
        write_output(test_out_file, predicted_test)
        if (test_bad_out_file is not None):
            write_low_scored(test_bad_out_file, X_test, y_test, predicted_test, 50)

    return model
开发者ID:kbiscanic,项目名称:apt_project,代码行数:52,代码来源:Main.py


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