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


Python Features.make_experiment_matrices方法代码示例

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


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

示例1: error_analyze

# 需要导入模块: import Features [as 别名]
# 或者: from Features import make_experiment_matrices [as 别名]
def error_analyze(make_model, train_data, test_data, featurizer):
    matrices = Features.make_experiment_matrices(train_data, test_data, featurizer)
    model = make_model()
    model.fit(matrices['train_X'], matrices['train_Y'])
    bins = [v / 100.0 for v in range(50, 110, 5)]
    ext_preds = Models.extended_predict(model, matrices['test_X'], matrices['test_Y'])
    return Models.error_analysis(ext_preds, bins = bins)
开发者ID:josepablocam,项目名称:snlp_project,代码行数:9,代码来源:maxent_experiments.py

示例2: model_cv

# 需要导入模块: import Features [as 别名]
# 或者: from Features import make_experiment_matrices [as 别名]
def model_cv(make_model, data, featurizer, n_folds = 10, random_state = 1, getX = Features.getX, getY = Features.getY, stratified = False, **kwargs):
    """
    Run cross validation given a functino to create model, data, function to create features
    :param make_model: lambda (no-args) to create model (called once per fold)
    :param data: data to use (tuples of (x,y))
    :param featurizer: function called on x to create features. Called jointly on training and test data, as features
    can be stateful (e.g. vocabulary found in training data)
    :param n_folds: (default = 10) number of folds for evaluation
    :param random_state: seed for reproducibility
    :param getX: function to get X from data (default: Features.getX)
    :param getY: function to get Y from data (default: Features.getY)
    :param kwargs: additional (optional) arguments
    :return: tuple of mean of accuracy and std error of accuracy
    """
    nobs = len(data)
    cv_accuracies = []
    if stratified:
        folds = StratifiedKFold(getY(data), n_folds = n_folds, random_state = random_state, **kwargs)
    else:
        folds = KFold(n = nobs, n_folds= n_folds, random_state = random_state, **kwargs)
    get_elems_at = lambda vals, indices: [vals[i] for i in indices]
    for fold_id, (train_indices, test_indices) in enumerate(folds):
        print "Running fold %d" % fold_id
        train_data = get_elems_at(data, train_indices)
        test_data = get_elems_at(data, test_indices)
        # Featurize each time since our features can depend on training data
        matrices = Features.make_experiment_matrices(train_data, test_data, featurizer, getX, getY)
        # always make a new version of model...safer, not sure if model.fit would overwrite if re-trained
        # as we want
        model = make_model()
        model.fit(matrices['train_X'], matrices['train_Y'])
        accuracy = model.score(matrices['test_X'], matrices['test_Y'])
        cv_accuracies.append(accuracy)
    mean_accuracy = numpy.mean(cv_accuracies)
    std_accuracy = numpy.std(cv_accuracies)
    return (mean_accuracy, std_accuracy)
开发者ID:josepablocam,项目名称:snlp_project,代码行数:38,代码来源:Models.py

示例3: experiment

# 需要导入模块: import Features [as 别名]
# 或者: from Features import make_experiment_matrices [as 别名]
def experiment(model_report, train, test, featurizer):
    data = Features.make_experiment_matrices(train, test, featurizer)
    return model_report(data['train_X'], data['train_Y'], data['test_X'], data['test_Y'])
开发者ID:josepablocam,项目名称:snlp_project,代码行数:5,代码来源:maxent_experiments.py

示例4: feat6_generic

# 需要导入模块: import Features [as 别名]
# 或者: from Features import make_experiment_matrices [as 别名]
    return lambda train, test: feat6_generic(train, test, tw_pos, blog_pos)
def feat6_tw():
    return lambda train, test: feat6_generic(train, test, tw_pos, twitter_test_pos)


print "Experiment 6: valence + punctuation + key POS word counts blog(80%) -> blog(20%)"
experiment6_b = experiment_svm_sigK(blog_80, blog_20, feat6_b())
print "Experiment 6: valence + punctuation + key POS word counts twitter+wiki -> blog"
experiment6_twb = experiment_svm_sigK(tw, blog, feat6_tw_b())
print "Experiment 6: valence + punctuation + key POS word counts twitter+wiki -> twitter(test)"
experiment6_tw = experiment_svm_sigK(tw, twitter_test, feat6_tw())


# Cross validation for blog -> blog experiment with best accuracy (to compare to original paper)
folds = KFold(n = len(blog), n_folds= 10, random_state = 1)
test_accuracies = []
for train_indices, test_indices in folds:
    train_data = get_elems_at(blog, train_indices)
    test_data = get_elems_at(blog, test_indices)
    data = Features.make_experiment_matrices(train_data, test_data, feat4)
    model = LogisticRegression()
    model.fit(data['train_X'], data['train_Y'])
    predictions = model.predict(data['test_X'])
    accuracy = accuracy_score(data['test_Y'], predictions)
    test_accuracies.append(accuracy)


print "10-CV accuracy blog on blog:%.2f[+/-%.2f]" % (numpy.mean(test_accuracies), numpy.std(test_accuracies))


开发者ID:josepablocam,项目名称:snlp_project,代码行数:30,代码来源:svm_sigK.py

示例5: experiment_poly_svm

# 需要导入模块: import Features [as 别名]
# 或者: from Features import make_experiment_matrices [as 别名]
def experiment_poly_svm(train, test, featurizer):
    data = Features.make_experiment_matrices(train, test, featurizer)
    return Models.report_SVM_polyK(data['train_X'], data['train_Y'], data['test_X'], data['test_Y'])
开发者ID:josepablocam,项目名称:snlp_project,代码行数:5,代码来源:svm_experiments.py


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