本文整理汇总了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