eonu / sequentia

Scikit-Learn compatible HMM and DTW based sequence machine learning algorithms in Python.

Home Page:https://pypi.org/project/sequentia/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Don't treat single sequence input as singleton for HMMClassifier

eonu opened this issue · comments

Currently if a single sequence is provided to predict() in HMMClassifier, it is converted into a singleton list:

# Convert single observation sequence to a singleton list
X = [X] if isinstance(X, np.ndarray) else X

When returning the prediction, we assume that if X has one element, the output should not be returned as a singleton.

if len(X) == 1:
return (labels.item(), scores.flatten()) if return_scores else labels.item()
else:
return (labels, scores) if return_scores else labels

This can be unintuitive as if the user actually provides a singleton sequence as input, they will receive a prediction value that is not returned as a singleton.