How to use the causality.analysis.dataframe.KernelModelWrapper function in causality

To help you get started, we’ve selected a few causality examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github akelleh / causality / causality / analysis / dataframe.py View on Github external
if kwargs.get('kind') == 'line':
                treatment = kwargs.get('x')
                outcome = kwargs.get('y')
                variable_types = kwargs.get('z', {}).copy()
                confounders = kwargs.get('z', {}).keys()
                variable_types[treatment] = 'c'

                if kwargs.get('model'):
                    model = kwargs.get('model')()
                    del kwargs['model']
                    model.fit(self[[treatment] + confounders], self[outcome])
                elif kwargs.get('fit_model'):
                    model = kwargs.get('fit_model')
                    del kwargs['fit_model']
                elif kwargs.get('model_type', '') == 'kernel':
                    model = KernelModelWrapper()
                    del kwargs['model_type']
                    model.fit(self[[treatment] + confounders], self[outcome], variable_types=variable_types)
                else:
                    model = RandomForestRegressor()
                    model.fit(self[[treatment] + confounders], self[outcome])


                xs = []
                ys = []
                xmin, xmax = kwargs.get('xlim', (self[treatment].quantile(0.01), self[treatment].quantile(0.99)))
                for xi in np.arange(xmin, xmax, (xmax - xmin) / 100.):
                    df = self.copy()
                    df[treatment] = xi
                    df['$E[Y|X=x,Z]$'] = model.predict(df[[treatment] + confounders])
                    yi = df.mean()['$E[Y|X=x,Z]$']
                    xs.append(xi)