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


Python A.getFeatureVectors方法代码示例

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


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

示例1: classify

# 需要导入模块: import A [as 别名]
# 或者: from A import getFeatureVectors [as 别名]
def classify(X_train, X_test, y_train):
    '''
    Train the best classifier on (X_train, and y_train) then predict X_test labels

    :param X_train: A dictionary with the following structure
            { instance_id: [w_1 count, w_2 count, ...],
            ...
            }

    :param X_test: A dictionary with the following structure
            { instance_id: [w_1 count, w_2 count, ...],
            ...
            }

    :param y_train: A dictionary with the following structure
            { instance_id : sense_id }

    :return: results: a list of tuples (instance_id, label) where labels are predicted by the best classifier
    '''

    results = []

    trainVectors, _, trainOutcomes = A.getFeatureVectors(X_train, y_train)
    testVectors, testKeys = A.getFeatureVectors(X_test)

    # Select Features
    svm_clf = svm.LinearSVC()
    selector = RFE(svm_clf, verbose=0, step=10)
    selector = selector.fit(trainVectors, trainOutcomes)
    featMask = selector.get_support()

    # Mask Features
    nItems = testVectors.shape[0]
    testVectorsNew = np.zeros((nItems, np.sum(featMask)))
    for k in range(nItems):
        testVectorsNew[k, :] = testVectors[k, :][featMask]

    model = selector.estimator_
    svm_predict = model.predict(testVectorsNew)
    #svm_clf.fit(trainVectorsNew, trainOutcomes)
    #svm_predict = svm_clf.predict(testVectors)

    results = [(testKeys[k], svm_predict[k]) for k in range(len(testKeys))]

    return results
开发者ID:suttonbm,项目名称:umich_NLP,代码行数:47,代码来源:B.py


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