示例#1
0
def train(data_file_name, learner_opts="", liblinear_opts=""):
    """
    Return a :class:`LearnerModel`.

    *data_file_name* is the file path of the LIBSVM-format data. *learner_opts* is a
    :class:`str`. Refer to :ref:`learner_param`. *liblinear_opts* is a :class:`str` of
    LIBLINEAR's parameters. Refer to LIBLINEAR's document.
    """

    learner_prob = LearnerProblem(data_file_name)
    learner_param = LearnerParameter(learner_opts, liblinear_opts)

    idf = None
    if learner_param.inverse_document_frequency:
        idf = learner_prob.compute_idf()

    learner_prob.normalize(learner_param, idf)

    m = liblinear_train(learner_prob, learner_param)
    if not learner_param.cross_validation:
        m.x_space = None  # This is required to reduce the memory usage...
        m = LearnerModel(m, learner_param, idf)
    return m
示例#2
0
def train(data_file_name, learner_opts="", liblinear_opts=""):
    """
    Return a :class:`LearnerModel`.

    *data_file_name* is the file path of the LIBSVM-format data. *learner_opts* is a
    :class:`str`. Refer to :ref:`learner_param`. *liblinear_opts* is a :class:`str` of
    LIBLINEAR's parameters. Refer to LIBLINEAR's document.
    """

    learner_prob = LearnerProblem(data_file_name)
    learner_param = LearnerParameter(learner_opts, liblinear_opts)

    idf = None
    if learner_param.inverse_document_frequency:
        idf = learner_prob.compute_idf()

    learner_prob.normalize(learner_param, idf)

    m = liblinear_train(learner_prob, learner_param)
    if not learner_param.cross_validation:
        m.x_space = None  # This is required to reduce the memory usage...
        m = LearnerModel(m, learner_param, idf)
    return m