Ejemplo n.º 1
0
def predict(data, model, interval=0.95, **kwargs):

    def pred(X):
        if hasattr(model, 'predict_proba'):
            Ey, Vy, ql, qu = model.predict_proba(X, interval, **kwargs)
            predres = np.hstack((Ey[:, np.newaxis], Vy[:, np.newaxis],
                                 ql[:, np.newaxis], qu[:, np.newaxis]))

        else:
            predres = np.reshape(model.predict(X, **kwargs),
                                 newshape=(len(X), 1))

        if hasattr(model, 'entropy_reduction'):
            MI = model.entropy_reduction(X)
            predres = np.hstack((predres, MI[:, np.newaxis]))

        if hasattr(model, 'krige_residual'):
            kr = model.krige_residual(lon_lat=kwargs['lon_lat'])
            predres = np.hstack((predres, kr[:, np.newaxis]))

        if hasattr(model, 'ml_prediction'):
            ml_pred = model.ml_prediction(X)
            predres = np.hstack((predres, ml_pred[:, np.newaxis]))

        return predres
    result = apply_masked(pred, data)
    return result
Ejemplo n.º 2
0
def test_apply_masked(masked_data):
    yt, Xt, ys, Xs = masked_data
    yt_masked = np.ma.masked_array(yt, mask=Xt.mask.flatten())

    def ident(X):
        return X

    def target(X):
        return yt[~Xt.mask.flatten()]

    def fit(X):
        assert np.allclose(X, Xt.data[~Xt.mask.flatten()])
        return

    assert np.ma.all(Xt == apply_masked(ident, Xt))
    assert np.ma.all(yt_masked == apply_masked(target, Xt))
    assert apply_masked(fit, Xt) is None