Add missing columns to predict_proba result.

    When a multiclass classifier is fit on a dataset which only contains
    a subset of possible classes its predict_proba result only has columns
    corresponding to seen classes. This function adds missing columns.

def fix_multiclass_predict_proba(y_proba,          # type: np.ndarray
                                 seen_classes,
                                 complete_classes
                                 ):
    # type: (...) -> np.ndarray
    """
    Add missing columns to predict_proba result.

    When a multiclass classifier is fit on a dataset which only contains
    a subset of possible classes its predict_proba result only has columns
    corresponding to seen classes. This function adds missing columns.
    """
    assert set(complete_classes) >= set(seen_classes)
    y_proba_fixed = np.zeros(
        shape=(y_proba.shape[0], len(complete_classes)),
        dtype=y_proba.dtype,
    )
    class_mapping = np.searchsorted(complete_classes, seen_classes)
    y_proba_fixed[:, class_mapping] = y_proba
    return y_proba_fixed