IndexError при подгонке модели SSVM в PyStruct

Я использую pystruct Модуль Python для структурированной задачи обучения при классификации сообщений в обсуждениях, и я столкнулся с проблемой при обучении OneSlackSSVM для использования с LinearChainCRF, Я следую примеру OCR из документов, но не могу назвать .fit() метод на SSVM. Вот ошибка, которую я получаю:

Traceback (most recent call last):

File "<ipython-input-47-da804d135818>", line 1, in <module>
ssvm.fit(X_train, y_train)

File "/Users/kylefth/anaconda/lib/python2.7/site-  
packages/pystruct/learners/one_slack_ssvm.py", line 429, in fit
joint_feature_gt = self.model.batch_joint_feature(X, Y)

File "/Users/kylefth/anaconda/lib/python2.7/site-       
packages/pystruct/models/base.py", line 40, in batch_joint_feature      
joint_feature_ += self.joint_feature(x, y)

File "/Users/kylefth/anaconda/lib/python2.7/site-    
packages/pystruct/models/graph_crf.py", line 197, in joint_feature
unary_marginals[gx, y] = 1

IndexError: index 7 is out of bounds for axis 1 with size 7

Ниже приведен код, который я написал. Я устал структурировать данные, как в примере с документами, где общая структура данных dict с ключами для data, labels, а также folds,

from pystruct.models import LinearChainCRF
from pystruct.learners import OneSlackSSVM

# Printing out keys of overall data structure
print threads.keys()
>>> ['folds', 'labels', 'data']

# Creating instances of models
crf = LinearChainCRF()
ssvm = OneSlackSSVM(model=crf)

# Splitting up data into training and test sets as in example
X, y, folds = threads['data'], threads['labels'], threads['folds']
X_train, X_test = X[folds == 1], X[folds != 1]
y_train, y_test = y[folds == 1], y[folds != 1]

# Print out dimensions of first element in data and labels
print X[0].shape, y[0].shape
>>> (8, 211), (8,)

# Fitting the ssvm model
ssvm.fit(X_train, y_train)
>>> see error above

Непосредственно после попытки подгонки модели я получаю вышеуказанную ошибку. Все случаи X_train, X_test, y_train, а также y_test иметь 211 столбцов, и все размеры меток совпадают с соответствующими данными обучения и тестирования. Любая помощь будет принята с благодарностью.

1 ответ

Решение

Я думаю, что все, что вы делаете, правильно, это https://github.com/pystruct/pystruct/issues/114. Ваши ярлыки должны начинаться с 0 до n_labels. Я думаю, что ваши начинаются с 1.

Другие вопросы по тегам