本文整理汇总了Python中sklearn.svm.SVC.test_score方法的典型用法代码示例。如果您正苦于以下问题:Python SVC.test_score方法的具体用法?Python SVC.test_score怎么用?Python SVC.test_score使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.svm.SVC
的用法示例。
在下文中一共展示了SVC.test_score方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: train_pca_svm
# 需要导入模块: from sklearn.svm import SVC [as 别名]
# 或者: from sklearn.svm.SVC import test_score [as 别名]
def train_pca_svm(learning_data, pca_dims, probability=True, cache_size=3000, **svm_kwargs):
(X_train, y_train, train_ids), (X_test, y_test, test_ids) = learning_data
pca = TruncatedSVD(n_components=pca_dims)
n_symbols = max(
np.max(X_train) + 1, np.max(X_test) + 1
)
logger.info("Forming CSR Matrices")
x_train, x_test = create_csr_matrix(X_train, n_symbols), create_csr_matrix(X_test, n_symbols)
logger.info("Starting PCA")
# pseudo-supervised PCA: fit on positive class only
pca = pca.fit(x_train[y_train > 0])
x_train_pca = pca.transform(x_train)
x_test_pca = pca.transform(x_test)
logger.info("Starting SVM")
svc = SVC(probability=probability, cache_size=cache_size, **svm_kwargs)
svc.fit(x_train_pca, y_train)
logger.info("Scoring SVM")
score = svc.score(x_test_pca, y_test)
logger.info(score)
svc.test_score = score
pca.n_symbols = n_symbols
return svc, pca, x_train_pca, x_test_pca