本文整理汇总了Python中A.predictions_from_data方法的典型用法代码示例。如果您正苦于以下问题:Python A.predictions_from_data方法的具体用法?Python A.predictions_from_data怎么用?Python A.predictions_from_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类A
的用法示例。
在下文中一共展示了A.predictions_from_data方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: classify
# 需要导入模块: import A [as 别名]
# 或者: from A import predictions_from_data [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
'''
# create x, y lists from training datas
x_train_list, y_train_list = A.x_y_lists_from_training(X_train, y_train)
# train svm
print 'training svm...'
svm_clf = svm.LinearSVC()
svm_clf.fit(x_train_list, y_train_list)
# predict svm results
print 'predicting svm...'
svm_results = A.predictions_from_data(svm_clf, X_test)
return svm_results