8月 302017
 

The analytical community is getting increasingly interested the concept of attribution. And while much of this is focused on digital marketing attribution, I want to take a step back to describe the wider application of attribution and the traditional techniques that can be used to solve a range of attribution challenges.

I’ll use as an example a UK bank that I worked with that was collecting debt on customers that had defaulted on loans. For many businesses, there is a clear result in customer engagements (i.e., the customer responded, purchased, etc.) In this instance, while it’s known which customers made a payment, it might be unclear which action (or combination of actions) triggered payment.

Collections teams often have paths of activities that are analogous to customer journeys (how’s that for lateral thinking?). It may be that a high-risk customer will receive a text message five days after they have defaulted, a letter at 10 days, and a telephone call at 15 days. Collections teams will often have different paths for high-risk and low-risk customer. A low-risk customer may receive the same contact escalation path (text/letter/phone call) but on a longer cycle (e.g., at 10/15/20 days).

Multivariate testing helps reveal hidden relationships

My banking client had wisely created a test of the two different paths using two similar sets of customers. The more aggressive path collected more debt, but the costs were higher. However, there were options to improve upon this, and we chose to build two customer-level predictive models – one for each path – to predict the likelihood of payment.

This led to the creation of four segments that enabled much more effective decisions:

  • Model 1: High-probability to pay (for both paths)
    • Action: Apply low-risk path to save cost
  • Model 2: Low probability to pay (for both paths)
    • Action: Apply low-risk path to save cost (but also test an accelerated strategy)
  • Model 3: High probability to pay for high-risk path (but low probability to pay on low-risk path)
    • Action: Apply high risk path to maximise uplift
  • Low probability to pay for high-risk path, (but high probability to pay for low-risk path)
    • Action: Apply low-risk path

These models uncovered ways to improve collected debt by 2 percent with no increase in cost, which is a significant performance improvement. More importantly, it highlights the value of attributing outcomes to actions because many collections departments focus on perceived risk as they begin collection paths and do not attribute collected debt to specific activities.

Lessons for marketers

This example is a good first step towards a detailed attribution solution because by treating the path as one action, the halo and cannibalisation effects of the different actions are accounted for. Of course, there are opportunities to dive deeper and understand which of the underlying activities are driving the behaviour and multivariate testing can support this.

There are a few clear takeaways here for marketers:

  • Good test data is essential to achieve good attribution results.
  • Customer-level attribution can deliver results that are applicable across all channels.
  • Traditional modelling techniques can support building conditional models or net-lift models using different paths.
  • Simplifying the problem (as much as possible) will give you results that are more easily incorporated into your campaign strategies.

To learn more about how SAS Customer Intelligence 360 uses multivariate testing to create better customer experiences, read this blog post by Suneel Grover.

How is debt collection like attribution modelling? was published on Customer Intelligence Blog.

8月 302017
 

Aa previous article discussed the mathematical properties of the singular value decomposition (SVD) and showed how to use the SVD subroutine in SAS/IML software. This article uses the SVD to construct a low-rank approximation to an image. Applications include image compression and denoising an image.

Construct a grayscale image

The value of each pixel in a grayscale image can be stored in a matrix where each element of the matrix is a value between 0 (off) and 1 (full intensity). I want to create a small example that is easy to view, so I'll create a small matrix that contains information for a low-resolution image of the capital letters "SVD." Each letter will be five pixels high and three pixels wide, arranges in a 7 x 13 array of 0/1 values. The following SAS/IML program creates the array and displays a heat map of the data:

ods graphics / width=390px height=210px;
proc iml;
SVD = {0 0 0 0 0 0 0 0 0 0 0 0 0,
       0 1 1 1 0 1 0 1 0 1 1 0 0,
       0 1 0 0 0 1 0 1 0 1 0 1 0,
       0 1 1 1 0 1 0 1 0 1 0 1 0,
       0 0 0 1 0 1 0 1 0 1 0 1 0,
       0 1 1 1 0 0 1 0 0 1 1 0 0,
       0 0 0 0 0 0 0 0 0 0 0 0 0 };
A = SVD;
/* ColorRamp:  White    Gray1    Gray2    Gray3    Black   */
ramp =        {CXFFFFFF CXF0F0F0 CXBDBDBD CX636363 CX000000};
call heatmapcont(A) colorramp=ramp showlegend=0 title="Original Image" range={0,1};
Rank-5 data matrix for singular value decomposition (SVD)

A low-rank approximation to an image

Because the data matrix contains only five non-zero rows, the rank of the A matrix cannot be more than 5. The following statements compute the SVD of the data matrix and create a plot of the singular values. The plot of the singular values is similar to the scree plot in principal component analysis, and you can use the plot to help choose the number of components to retain when approximating the data.

call svd(U, D, V, A);  /* A = U*diag(D)*V` */
title "Singular Values";
call series(1:nrow(D), D) grid={x y} xvalues=1:nrow(D) label={"Component" "Singular Value"};
Singular values of rank-5 data matrix

For this example, it looks like retaining three or five components would be good choices for approximating the data. To see how low-rank approximations work, let's generate and view the rank-1, rank-2, and rank-3 approximations:

keep = 1:3;          /* use keep=1:5 to see all approximations */
do i = 1 to ncol(keep);
   idx = 1:keep[i];                           /* components to keep */
   Ak = U[ ,idx] * diag(D[idx]) * V[ ,idx]`;  /* rank k approximation */
   Ak = (Ak - min(Ak)) / range(Ak);           /* for plotting, stdize into [0,1] */
   s = "Rank = " + char(keep[i],1);
   call heatmapcont(Ak) colorramp=ramp showlegend=0 title=s range={0, 1};
end;
Low-rank approximation: Rank-1 approximation via SVD of a data matrix

The rank-1 approximation does a good job of determining the columns and do not contain that contain the letters. The approximation also picks out two rows that contain the horizontal strokes of the capital "S."

Low-rank approximation: Rank-2 approximation via SVD of a data matrix

The rank-2 approximation refines the image and adds additional details. You can begin to make out the letters "SVD." In particular, all three horizontal strokes for the "S" are visible and you can begin to see the hole in the capital "D."

Low-rank approximation: Rank-3 approximation via SVD of a data matrix

The rank-3 approximation contains enough details that someone unfamiliar with the message can read it. The "S" is reconstructed almost perfectly and the space inside the "V" and "D" is almost empty. Even though this data is five-dimensional, this three-dimensional approximation is very good.

Not only is a low-rank approximation easier to work with than the original five-dimensional data, but a low-rank approximation represents a compression of the data. The original image contains 7 x 13 = 91 values. For the rank-3 approximation, three columns of the U matrix contain 33 numbers and three columns of VT contain 15 numbers. So the total number of values required to represent the rank-3 approximation is only 48, which is almost half the number of values as for the original image.

Denoising an image

You can use the singular value decomposition and low-rank approximations to try to eliminate random noise that has corrupted an image. Every TV detective series has shown an episode in which the police obtain a blurry image of a suspect's face or license plate. The detective asks the computer technician if she can enhance the image. With the push of a button, the blurry image is replaced by a crystal clear image that enables the police to identify and apprehend the criminal.

The image reconstruction algorithms used in modern law enforcement are more sophisticated than the SVD. Nevertheless, the SVD can do a reasonable job of removing small random noise from an image, thereby making certain features easier to see. The SVD has to have enough data to work with, so the following statements duplicate the "SVD" image four times before adding random Gaussian noise to the data. The noise has a standard deviation equal to 25% of the range of the data. The noisy data is displayed as a heat map on the range [-0.25, 1.25] by using a color ramp that includes yellow for negative values and blue for values greater than 1.

call randseed(12345);
A = (SVD // SVD) || (SVD // SVD);                     /* duplicate the image */
A = A + randfun( dimension(A), "Normal", 0, 0.25);    /* add Gaussian noise */
/*       Yellow   White    Gray1    Gray2    Gray3    Black    Blue    */
ramp2 = {CXFFEDA0 CXFFFFFF CXF0F0F0 CXBDBDBD CX636363 CX000000 CX3182BD};
call heatmapcont(A) colorramp=ramp2 showlegend=0 title="Noisy Image" range={-0.5, 1.5};
Image corrupted by Gaussian noise

I think most police officers would be able to read this message in spite of the added noise, but let's see if the SVD can clean it up. The following statements compute the SVD and create a plot of the singular values:

call svd(U, D, V, A);  /* A = U*diag(D)*V` */
call series(1:nrow(D), D) grid={x y} xvalues=1:nrow(D) label={"Component" "Singular Value"};
Plot of singular values for a small image that is corrupted by Gaussian noise

There are 14 non-zero singular values. In theory, the main signal is contained in the components that correspond to the largest singular values whereas the noise is captured by the components for the smallest singular values. For these data, the plot of the singular values suggests that three or five (or nine) components might capture the main signal while ignoring the noise. The following statements create and display the rank-3 and rank-5 approximations. Only the rank-5 approximation is shown.

keep = {3 5};        /* which components to examine? */
do i = 1 to ncol(keep);
   idx = 1:keep[i];
   Ak = U[ ,idx] * diag(D[idx]) * V[ ,idx]`;
   Ak = (Ak - min(Ak)) / range(Ak); /* for plotting, standardize into [0,1] */
   s = "Rank = " + char(keep[i],2);
   call heatmapcont(Ak) colorramp=ramp showlegend=0 title=s range={0, 1};
end;
Low-rank approximation: Rank-5 reconstruction via SVD of a small image that is corrupted by Gaussian noise

The denoised low-rank image is not as clear as Hollywood depicts, but it is quite readable. It is certainly good enough to identify a potential suspect. I can hear the detective mutter, "Book 'em, Danno! Murder One."

Summary and further reading

In summary, the singular value decomposition (SVD) enables you to approximate a data matrix by using a low-rank approximation. This article uses a small example for which the full data matrix is rank-5. A plot of the singular values can help you choose the number of components to retain. For this example, a rank-3 approximation represents the essential features of the data matrix.

For similar analyses and examples that use the singular value decomposition, see

In SAS software, the SVD is heavily used in the SAS Text Miner product. For an overview of how a company can use text mining to analyze customer support issues, see Sanders and DeVault (2004) "Using SAS at SAS: The Mining of SAS Technical Support."

The post The singular value decomposition and low-rank approximations appeared first on The DO Loop.

8月 292017
 

I hate hard-coding variable lists in my SAS code. I love the special variable lists SAS provides, like name:, _numeric_, etc. But back in 2011, I wrote a post titled Jedi SAS Tricks - Building a Name Suffix variable list lamenting the lack of a special variable list in base [...]

The post Jedi SAS Tricks - Variable Lists by Text Pattern appeared first on SAS Learning Post.

8月 292017
 

Widespread flooding. Downed power lines. Broken poles. Failed transformers and breakers. Leaking pipes. Shut down refineries. The toll that a catastrophic storm takes on the energy value chain is significant.  A functioning power grid, clean water and reliable fuel sources are critical for public safety and economic recovery. Even with [...]

After the storm: Analytics help energy companies anticipate and recover was published on SAS Voices by Alyssa Farrell

8月 282017
 

My daughter is a junior in high school, and for almost every semester she’s taken an online course as part of her studies. This semester she’s taking Spanish 3, an advanced level course where every word of instruction is spoken in Spanish. Each morning she joins the class from our [...]

The post Learn SAS from wherever you are: Live Web classes go global appeared first on SAS Learning Post.

8月 282017
 

The singular value decomposition (SVD) could be called the "billion-dollar algorithm" since it provides the mathematical basis for many modern algorithms in data science, including text mining, recommender systems (think Netflix and Amazon), image processing, and classification problems. Although the SVD was mathematically discovered in the late 1800s, computers have made the SVD an indispensable tool in computational statistics and data science.

SVD: A fundamental theorem of linear algebra

Mathematically, the singular value decomposition is a fundamental theorem of linear algebra. )You could argue that it is THE fundamental theorem, but Gil Strang names a different result.) The singular value decomposition says that every n x p matrix can be written as the product of three matrices: A = U Σ VT where

  • U is an othogonal n x n matrix
  • Σ is a diagonal n x p matrix. In practice, the diagonal elements are ordered so that Σii ≥ Σjj for all i < j.
  • V is an othogonal p x p matrix and VT represents a matrix transpose.

The SVD represents the essential geometry of a linear transformation. It tells us that every linear transformation is a composition of three fundamental actions. Reading the equation from right to left:

  1. The matrix V represents a rotation or reflection of vectors in the p-dimensional domain.
  2. The matrix Σ represents a linear dilation or contraction along each of the p coordinate directions. If np, this step also canonically embeds (or projects) the p-dimensional domain into (or onto) the n-dimensional range.
  3. The matrix U represents a rotation or reflection of vectors in the n-dimensional range.

Thus the SVD specifies that every linear transformation is fundamentally a rotation or reflection, followed by a scaling, followed by another rotation or reflection. The Strang (1993) article about the fundamental theorem of linear algebra includes the following geometric interpretation of the singular value decomposition of a 2 x 2 matrix:

Geometric interpretation of the singular value decomposition (SVD) as the product of a rotation/reflection, followed by a scaling, followed by another rotation/reflection.

The diagram shows that the transformation induced by the matrix A (the long arrow across the top of the diagram) is equivalent to the composition of the three fundamental transformations, namely a rotation, a scaling, and another rotation.

SVD: The fundamental theorem of multivariate data analysis

Because of its usefulness, the singular value decomposition is a fundamental technique for multivariate data analysis. A common goal of multivariate data analysis is to reduce the dimension of the problem by choosing a small linear subspace that captures important properties of the data. The SVD is used in two important dimension-reducing operations:

  • Low-rank approximations: Recall that the diagonal elements of the Σ matrix (called the singular values) in the SVD are computed in decreasing order. The SVD has a wonderful mathematical property: if you choose some integer k ≥ 1 and let D be the diagonal matrix formed by replacing all singular values after the k_th by 0, then then matrix U D VT is the best rank-k approximation to the original matrix A.
  • Principal components analysis: The principal component analysis is usually presented in terms of eigenvectors of a correlation matrix, but you can show that the principal component analysis follows directly from the SVD. (In fact, you can derive the eigenvalue decomposition of a matrix, from the SVD.) The principal components of AT A are the columns of the V matrix; the scores are the columns of U. Dimension reduction is achieved by truncating the number of columns in U, which results in the best rank-k approximation of the data.

Compute the SVD in SAS

In SAS, you can use the SVD subroutine in SAS/IML software to compute the singular value decomposition of any matrix. To save memory, SAS/IML computes a "thin SVD" (or "economical SVD"), which means that the U matrix is an n x p matrix. This is usually what the data analyst wants, and it saves considerable memory in the usual case where the number of observations (n) is much larger than the number of variables (p). Technically speaking, the U for an "economical SVD" is suborthogonal: UT U is the identity when np and U UT is the identity when np.

As for eigenvectors, the columns of U and V are not unique, so be careful if you compare the results in SAS to the results from MATLAB or R. The following example demonstrates a singular value decomposition for a 3 x 2 matrix A. For the full SVD, the U matrix would be a 3 x 3 matrix and Σ would be a 3 x 2 diagonal matrix. For the "economical" SVD, U is 3 2 and Σ is a 2 x 2 diagonal matrix, as shown:

proc iml;
A = {0.3062 0.1768,
    -0.9236 1.0997,
    -0.4906 1.3497 };
 
call svd(U, D, V, A);  /* A = U*diag(D)*V` */
print U[f=6.3], D[f=6.3], V[f=6.3];

Notice that, to save memory, only the diagonal elements of the matrix &Signa; are returns in the vector D. You can explicitly form &Sigma = diag(D) if desired. Geometrically, the linear transformation that corresponds to V rotates a vector in the domain by about 30 degrees, the matrix D scales it by 2 and 0.5 in the coordinate directions, and U inserts it into a three-dimensional space, and applies another rotation.

My next blog post shows how the SVD enables you to reduce the dimension of a data matrix by using a low-rank approximation, which has applications to image compression and de-noising.

The post The singular value decomposition: A fundamental technique in multivariate data analysis appeared first on The DO Loop.

8月 262017
 

News flash: My favorite SAS code editor is SAS Enterprise Guide. However, my favorite general purpose text editor is Notepad++, and I often find myself using that tool for viewing SAS log files and for making small modifications to SAS programs. Judging from the popularity of this SAS Support Communities discussion, I'm not alone. In this post, I'll share the steps for turning Notepad++ into a more useful home for SAS programs.

You can download Notepad++ for Windows from here -- you can use it for free, no cost. That's one reason that it's one of the first tools that I install on any new PC I get my hands on!

1. Associate SAS files with Notepad++

You accomplish this in the usual way with Windows. In Windows Explorer, right-click (or SHIFT+right-click depending on your setup) on a .SAS file (SAS program), and select Open with...

Open with menu

► You might see Notepad++ in the menu, but don't select it, Instead, select Choose another app.

Choose another app

► In this menu, select Notepad++ and check the "Always use this app" checkbox.

Repeat this step for SAS program logs (.LOG files) and listing output (.LST files) if you want.

2. Run a SAS program from Notepad++

You can add new program actions to the Run menu in Notepad++. Here's how to add a command to run a SAS program, if you have SAS for Windows installed. Note: These steps assume that the SAS program is open in Notepad++ and is saved in a file.

► Select Run... from the Run menu. In the program to run field, enter this command:

"C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -sysin "$(FULL_CURRENT_PATH)" -log "$(CURRENT_DIRECTORY)\$(NAME_PART).log" -print "$(CURRENT_DIRECTORY)\$(NAME_PART).lst"

all on one line. You might need to adjust the SAS.EXE path for your install. The command options use some Notepad++ environment variables to direct the SAS log and listing output to the same path as the SAS program file.

Click Save (not Run).

Click Save

Optionally, assign a shortcut key to the action, and name it "Run program file in SAS" (or whatever you want). This adds the command to your Run menu.

Run in SAS command

When you select it, Notepad++ will launch SAS, run your program in batch, and direct the output to the same folder where the program is stored.

3. Adding SAS syntax color coding to Notepad++

It's simple to "teach" Notepad++ to recognize the keywords from SAS and other languages. You can download new language definitions files from here -- follow the instructions on the page to have your Notepad++ recognize them. I've created an expanded definition file that includes more SAS keywords (many, many more!) -- you can grab that from my GitHub repo here.

Here's what SAS code looks like in my Notepad++:

my Notepad++ SAS look

What else?

I'm sure that some of you have spent more time than I have in creating a souped-up Notepad++ environment, or perhaps you've taken it to another level with other popular editors like Sublime or Vim or UltraEdit. If you have other tips to share, I'd love to hear from you in the comments.

The post Using Notepad++ as your SAS code editor appeared first on The SAS Dummy.

8月 252017
 

The Payment Services Directive 2 (PSD2) is a new European-wide regulation that requires European banks to make it easier to share customer transaction and account data (where the customer has given their consent) with third party providers, and it's the current hot topic across the payments industry in Europe. As [...]

PSD2: How new European payment regulations could elevate fraud risk was published on SAS Voices by Sundeep Tengur