python - PyStruct - 找不到匹配的签名

标签 python python-2.7 multilabel-classification

我正在尝试使用此处的代码:https://github.com/pystruct/pystruct/blob/master/examples/multi_label.py

我有形状为 (2591, 256) 的 X_train 和形状为 (2591, 175) 的 y_train。当我运行这个时:

tree = chow_liu_tree(y_train)
tree_model = MultiLabelClf(edges=tree, inference_method="max-product")
tree_ssvm = OneSlackSSVM(tree_model, inference_cache=50, C=.1, tol=0.01)
print("fitting tree model...")
tree_ssvm.fit(X_train, y_train)

我明白了:

Traceback (most recent call last):
  File "classifiers.py", line 173, in <module>
    tree_ssvm.fit(X_train, y_train)
  File "/usr/local/lib/python2.7/dist-packages/pystruct/learners/one_slack_ssvm.py", line 448, in fit
    X, Y, joint_feature_gt, constraints)
  File "/usr/local/lib/python2.7/dist-packages/pystruct/learners/one_slack_ssvm.py", line 348, in _find_new_constraint
    X, Y, self.w, relaxed=True)
  File "/usr/local/lib/python2.7/dist-packages/pystruct/models/base.py", line 95, in batch_loss_augmented_inference
    for x, y in zip(X, Y)]
  File "/usr/local/lib/python2.7/dist-packages/pystruct/models/crf.py", line 106, in loss_augmented_inference
    loss_augment_unaries(unary_potentials, np.asarray(y), self.class_weight)
  File "utils.pyx", line 21, in utils.__pyx_fused_cpdef (src/utils.c:4341)
TypeError: No matching signature found

当我直接从链接运行代码时,它可以工作(使用他们的数据集)。有谁知道应该是什么问题?

最佳答案

如果有人也会遇到该错误,y 必须是 int 类型 - 我得到的是 float。

解决方案链接:https://groups.google.com/forum/#!searchin/pystruct/matching/pystruct/T6UKEgZLmxY/297oLYQL8U8J

关于python - PyStruct - 找不到匹配的签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32298878/

相关文章:

python - 无法引用在函数外声明的一个特定变量

python - scrapy 可以单独使用 scrapy 抓取 iframe 的内容吗?

python - Timeit 对 python 函数进行计时

python - 从 youtube 下载视频并转换为 MP4

python - 无法保存模型架构(bilstm+attention)

Python 多项逻辑回归 : ValueError: bad input shape (326L, 559L)

python - tf.argmax() 用于多个索引 Tensorflow

python - 调整seaborn散点图中不同类别的不同透明度

python - 如何在脚本执行期间询问时从 python 脚本或 shell 脚本输入密码

python - 当我们使用 python-netaddr 拥有子网和 IPv4 地址时,如何获取 IP 前缀?