def exposure_machine_learner(ml_model, xdata, ydata, pdata):
    """Internal function to fit custom_models for the exposure nuisance model and generate the predictions.

    Parameters
    ----------
    ml_model :
        Unfitted model to be fit.
    xdata : array
        Covariate data to fit the model with
    ydata : array
        Outcome data to fit the model with
    pdata : array
        Covariate data to generate the predictions with.

    Returns
    -------
    array
        Predicted values for the outcome (probability if binary, and expected value otherwise)
    """
    # Fitting model
    try:
        fm = ml_model.fit(X=xdata, y=ydata)
    except TypeError:
        raise TypeError("Currently custom_model must have the 'fit' function with arguments 'X', 'y'. This "
                        "covers both sklearn and supylearner. If there is a predictive model you would "
                        "like to use, please open an issue at https://github.com/pzivich/zepid and I "
                        "can work on adding support")

    # Generating predictions
    if hasattr(fm, 'predict_proba'):
        g = fm.predict_proba(pdata)
        if g.ndim == 1:  # allows support for pygam.LogisticGAM
            return g
        else:
            return g[:, 1]
    elif hasattr(fm, 'predict'):
        g = fm.predict(pdata)
        return g
    else:
        raise ValueError("Currently custom_model must have 'predict' or 'predict_proba' attribute")