A generative classifier can predict from a partially observed input by marginalizing the missing features out of the class-conditional density instead of imputing them:
where are the observed entries of a row (missing entries are np.nan).
Implement:
gda_proba_missing(X, pi, mus, Sigmas): Gaussian discriminant analysis with priors pi (C,), means mus (C, D) and full covariances Sigmas (C, D, D). For each row use the Gaussian marginal of the observed coordinates, (keep only the observed rows and columns).gnb_proba_missing(X, pi, means, variances): Gaussian naive Bayes with per-class, per-feature means and variances, both (C, D). A missing feature contributes no factor.Both return the (N, C) posterior matrix computed in log space and normalized with log-sum-exp. A row with every feature missing gets the prior pi. Rows with no missing values must give the ordinary posterior.