Lenora  Hauck

Lenora Hauck

1597579200

Tree-Boosted Mixed Effects Models

This article shows how tree-boosting (sometimes also referred to as “gradient tree-boosting”) can be combined with mixed effects models using the GPBoost algorithm. Background is provided on both the methodology as well as on how to apply the GPBoost library using Python. We show how (i) models are trained, (ii) parameters tuned, (iii) model are interpreted, and (iv) predictions are made. Further, we do a comparison of several alternative approaches.

Image for post

Introduction

Tree-boosting with its well-known implementations such as XGBoost, LightGBM, and CatBoost, is widely used in applied data science. Besides state-of-the-art predictive accuracy, tree-boosting has the following advantages:

  • Automatic modeling of non-linearities, discontinuities, and complex high-order interactions
  • Robust to outliers in and multicollinearity among predictor variables
  • Scale-invariance to monotone transformations of the predictor variables
  • Automatic handling of missing values in predictor variables

Mixed effects models are a modeling approach for clustered, grouped, longitudinal, or panel data. Among other things, they have the advantage that they allow for more efficient learning of the chosen model for the regression function (e.g. a linear model or a tree ensemble).

As outlined in Sigrist (2020), combined gradient tree-boosting and mixed effects models often performs better than (i) plain vanilla gradient boosting, (ii) standard linear mixed effects models, and (iii) alternative approaches for combing machine learning or statistical models with mixed effects models.

Modeling grouped data

Grouped data (aka clustered data, longitudinal data, panel data) occurs naturally in many applications when there are multiple measurements for different units of a variable of interest . Examples include:

  • One wants to investigate the impact of some factors (e.g. learning technique, nutrition, sleep, etc.) on students’ test scores and every student does several tests. In this case, the units, i.e. the grouping variable, are the students and the variable of interest is the test score.
  • A company gathers transaction data about its customers. For every, customer there are several transactions. The units are then the customers and the variable of interest can be any attribute of the transactions such as prices

#data-science #machine-learning #python #artificial-intelligence #mixed-effects

What is GEEK

Buddha Community

Tree-Boosted Mixed Effects Models
Lenora  Hauck

Lenora Hauck

1597579200

Tree-Boosted Mixed Effects Models

This article shows how tree-boosting (sometimes also referred to as “gradient tree-boosting”) can be combined with mixed effects models using the GPBoost algorithm. Background is provided on both the methodology as well as on how to apply the GPBoost library using Python. We show how (i) models are trained, (ii) parameters tuned, (iii) model are interpreted, and (iv) predictions are made. Further, we do a comparison of several alternative approaches.

Image for post

Introduction

Tree-boosting with its well-known implementations such as XGBoost, LightGBM, and CatBoost, is widely used in applied data science. Besides state-of-the-art predictive accuracy, tree-boosting has the following advantages:

  • Automatic modeling of non-linearities, discontinuities, and complex high-order interactions
  • Robust to outliers in and multicollinearity among predictor variables
  • Scale-invariance to monotone transformations of the predictor variables
  • Automatic handling of missing values in predictor variables

Mixed effects models are a modeling approach for clustered, grouped, longitudinal, or panel data. Among other things, they have the advantage that they allow for more efficient learning of the chosen model for the regression function (e.g. a linear model or a tree ensemble).

As outlined in Sigrist (2020), combined gradient tree-boosting and mixed effects models often performs better than (i) plain vanilla gradient boosting, (ii) standard linear mixed effects models, and (iii) alternative approaches for combing machine learning or statistical models with mixed effects models.

Modeling grouped data

Grouped data (aka clustered data, longitudinal data, panel data) occurs naturally in many applications when there are multiple measurements for different units of a variable of interest . Examples include:

  • One wants to investigate the impact of some factors (e.g. learning technique, nutrition, sleep, etc.) on students’ test scores and every student does several tests. In this case, the units, i.e. the grouping variable, are the students and the variable of interest is the test score.
  • A company gathers transaction data about its customers. For every, customer there are several transactions. The units are then the customers and the variable of interest can be any attribute of the transactions such as prices

#data-science #machine-learning #python #artificial-intelligence #mixed-effects

Macey  Kling

Macey Kling

1597762800

Tree-Boosted Mixed Effects Models

This article shows how tree-boosting (sometimes also referred to as “gradient tree-boosting”) can be combined with mixed effects models using the GPBoost algorithm. Background is provided on both the methodology as well as on how to apply the GPBoost library using Python. We show how (i) models are trained, (ii) parameters tuned, (iii) model are interpreted, and (iv) predictions are made. Further, we do a comparison of several alternative approaches.

Image for post

Introduction

Tree-boosting with its well-known implementations such as XGBoost, LightGBM, and CatBoost, is widely used in applied data science. Besides state-of-the-art predictive accuracy, tree-boosting has the following advantages:

  • Automatic modeling of non-linearities, discontinuities, and complex high-order interactions
  • Robust to outliers in and multicollinearity among predictor variables
  • Scale-invariance to monotone transformations of the predictor variables
  • Automatic handling of missing values in predictor variables

Mixed effects models are a modeling approach for clustered, grouped, longitudinal, or panel data. Among other things, they have the advantage that they allow for more efficient learning of the chosen model for the regression function (e.g. a linear model or a tree ensemble).

As outlined in Sigrist (2020), combined gradient tree-boosting and mixed effects models often performs better than (i) plain vanilla gradient boosting, (ii) standard linear mixed effects models, and (iii) alternative approaches for combing machine learning or statistical models with mixed effects models.

Modeling grouped data

Grouped data (aka clustered data, longitudinal data, panel data) occurs naturally in many applications when there are multiple measurements for different units of a variable of interest . Examples include:

  • One wants to investigate the impact of some factors (e.g. learning technique, nutrition, sleep, etc.) on students’ test scores and every student does several tests. In this case, the units, i.e. the grouping variable, are the students and the variable of interest is the test score.
  • A company gathers transaction data about its customers. For every, customer there are several transactions. The units are then the customers and the variable of interest can be any attribute of the transactions such as prices.

Basically, such grouped data can be modeled using four different approaches:

  1. Ignore the grouping structure. This is rarely a good idea since important information is neglected.
  2. Model each group (i.e. each student or each customer) separately. This is also rarely a good idea as the number of measurements per group is often small relative to the number of different groups.
  3. Include the grouping variable (e.g. student or customer ID) in your model of choice and treat it as a categorical variable. While this is a viable approach, it has the following disadvantages. Often, the number of measurements per group (e.g. number of tests per student, number of transactions per customer) is relatively small and the number of different groups is large (e.g. number of students, customers, etc.). In this case, the model needs to learn many parameters (one for every group) based on relatively little data which can make the learning inefficient. Further, for trees, high cardinality categorical variables can be problematic.
  4. **Model the grouping variable using so-called random effects in a mixed effects model. **This is often a sensible compromise between the approaches 2. and 3. above. In particular, as illustrated below and outlined in Sigrist (2020), this is beneficial compared to the other approaches in the case of tree-boosting.

#data-science #machine-learning #python #artificial-intelligence #mixed-effects

Abdullah  Kozey

Abdullah Kozey

1658559780

Boost.GIL: Generic Image Library | Requires C++14 Since Boost 1.80

 

DocumentationGitHub ActionsAppVeyorAzure PipelinesRegressionCodecov
developGitHub ActionsAppVeyorAzuregilcodecov
masterGitHub ActionsAppVeyorAzuregilcodecov

Boost.GIL

Introduction

Boost.GIL is a part of the Boost C++ Libraries.

The Boost Generic Image Library (GIL) is a C++14 header-only library that abstracts image representations from algorithms and allows writing code that can work on a variety of images with performance similar to hand-writing for a specific image type.

Documentation

See RELEASES.md for release notes.

See CONTRIBUTING.md for instructions about how to build and run tests and examples using Boost.Build or CMake.

See example/README.md for GIL usage examples.

See example/b2/README.md for Boost.Build configuration examples.

See example/cmake/README.md for CMake configuration examples.

Requirements

The Boost Generic Image Library (GIL) requires:

  • C++14 compiler (GCC 6, clang 3.9, MSVC++ 14.1 (1910) or any later version)
  • Boost header-only libraries

Optionally, in order to build and run tests and examples:

  • Boost.Filesystem
  • Boost.Test
  • Headers and libraries of libjpeg, libpng, libtiff, libraw for the I/O extension and some of examples.

Branches

The official repository contains the following branches:

master This holds the most recent snapshot with code that is known to be stable.

develop This holds the most recent snapshot. It may contain unstable code.

Community

There is number of communication channels to ask questions and discuss Boost.GIL issues:

Contributing (We Need Your Help!)

If you would like to contribute to Boost.GIL, help us improve the library and maintain high quality, there is number of ways to do it.

If you would like to test the library, contribute new feature or a bug fix, see the CONTRIBUTING.md where the whole development infrastructure and the contributing workflow is explained in details.

You may consider performing code reviews on active pull requests or help with solving reported issues, especially those labelled with:

Any feedback from users and developers, even simple questions about how things work or why they were done a certain way, carries value and can be used to improve the library.

License

Distributed under the Boost Software License, Version 1.0.


Author:  boostorg
Source code: https://github.com/boostorg/gil
License: BSL-1.0 license

#cpluplus 

Tyshawn  Braun

Tyshawn Braun

1603112400

Carryover and Shape Effects in Media Mix Modeling: Paper Review

The full paper can be found here: link

Table of Contents

— — —

To begin, media mix models (MMM) aim to uncover the causal effect of paid media on a metric of interest, typically sales. Historically, the problem has largely been modeled via linear regression and the causal impact has been derived using Rubin’s potential outcomes framework.

In simple (data science) terms, this translates to

  1. Training a regression model that predicts sales using media spend and control variables.
  2. Deriving causal impact by comparing sales when media spend is at observed amount and when it is set to zero.

Estimating casual impact from observational data has a number of issues i.e. “correlation doesn’t equal causation” for starters. And media mix models have a host of unique issues to take note of. An excellent review of these issues can be found here: Challenges And Opportunities In Media Mix Modeling

This paper focuses on two specific issues:

  • Carryover Effects i.e. lagged effects
  • Shape Effects i.e. diminishing returns

While also providing a Bayesian model, ROAS calculations and optimization methods.

Carryover Effects

Carryover effects, often called lagged effects, occur when media spend effects sales across a number of days. For example, if we spend $100 on display advertising today, we may not see the effects of this spend for several days. The adstock function attempts to parameterize this phenomenon and the paper takes two approaches to adstock modeling:

Geometric

  • This is a weighted average going back L days, where L can vary by media channel.
  • The effect has the largest impact on the day of spend and decays thereafter.

Delayed Adstock

  • The effect of media spend spikes T (theta) days after media spend.

Implementation

def geoDecay(alpha, L):
    '''
    weighted average with geometric decay

    weight_T = alpha ^ T-1 

    returns: weights of length L to calculate weighted averages with. 
    '''
    return alpha**(np.ones(L).cumsum()-1)

def delayed_adstock(alpha, theta, L):
        '''
    weighted average with dealyed adstock function

    weight_T = 

    returns: weights of length L to calculate weighted averages with. 
    '''
    return alpha**((np.ones(L).cumsum()-1)-theta)**2

def carryover(x, alpha, L, theta = None, func='geo'):
    '''
    1\. x is a vector of media spend going back L timeslots, so it should be len(x) == L

    2\. Weights is a vector of length L showing how much previous time periods spend has on current period. 

    3\. L is max length of Lag.

    returns transformed vector of spend

    ## update with numpy average 
    ## np.average(x[:2], weights=[1,.9])
    '''
    transformed_x = []
    if func=='geo':
        weights = geoDecay(alpha, L)

    elif func=='delayed':
        weights = delayed_adstock(alpha, theta, L)

    for t in range(x.shape[0]):
        upper_window = t+1
        lower_window = max(0,upper_window-L)
        current_window_x = x[:upper_window]
        t_in_window = len(current_window_x)
        if t < L:
            new_x = (current_window_x*np.flip(weights[:t_in_window], axis=0)).sum()
            transformed_x.append(new_x/weights[:t_in_window].sum())
        elif t >= L:
            current_window_x = x[upper_window-L:upper_window]
            ext_weights = np.flip(weights, axis=0) 
            new_x = (current_window_x*ext_weights).sum()
            transformed_x.append(new_x/ext_weights.sum())

    return np.array(transformed_x)

#causality #causal-inference #data-science #modeling #media-mix-modeling

Remove all leaf nodes from a Generic Tree or N-ary Tree

Given a Generic tree, the task is to delete the leaf nodes from the tree.

** Examples:**

Input: 
              5
          /  /  \  \
         1   2   3   8
        /   / \   \
       15  4   5   6 

Output:  
5 : 1 2 3
1 :
2 :
3 :

Explanation: 
Deleted leafs are:
8, 15, 4, 5, 6

Input:      
              8
         /    |    \
       9      7       2
     / | \    |    / / | \ \
    4  5 6    10  11 1 2  2 3
Output:  
8: 9 7 2
9:
7:
2:

**Approach: **Follow the steps given below to solve the problem

  • Take tree into the vector.
  • Traverse the tree and check the condition:
  • If current node is leaf then
  • Delete the leaf from vector
  • Else
  • Recursively call for every child.

Below is the implementation of the above approach:

#data structures #recursion #tree #n-ary-tree #tree-traversal #data analysis