2) Output Logistic Regression Model as Probability and set Threshold Function.

This Blog entry is from the Linear Regression section in Learn Palisade.

Logistic regression output is constructed in exactly the same manner as in Linear Regression, in so far as there is a constant representing the starting point, thereafter the addition of the independent variable values multiplied by a coefficient, in this example:

= -0.899434346 + (High_Risk_Country * 2.926138785)

1.png

Fill down and name the column Model_1:

2.png

The output ranges from -5 to +5, however, it is not linear, rather it is a logarithm:

3.png

The output is substantially more intuitive if converted to a probability which ranges from 0 to 100 (or 0 to 1 if being represented as a pure probability), the formula to convert the current output to a probability is:

P = exp(Ouput) / (1+exp(Ouput))

The formula above uses the exp function in excel.  As if creating a model output, select the last cell in the spreadsheet, in this example AW2:

4.png

The function will reference the output of the first model, which in our example is cell AV2 start entering the formula:

=exp(

Select cell AV2 as the model output in its raw state:

5.png

Then complete the formula referencing the output in the same manner:

P = exp(AV2) / (1+exp(AV2))

6.png

Fill down and label the column Model_1_P:

7.png

Unlike the Linear Regression models which simply give an output of a numeric value for use, classification models creating a score, probability or otherwise, rely on the setting of a threshold as an activation function to declare, in this example, fraud.  In our example, the threshold is 80% probability of fraud for the prediction to be considered as such.  Once again, the IF function will be brought to bear for the purposes of creating an activation function.

Select the last cell in the spreadsheet, in this example AX2, and begin an IF function referencing the Model_1_P value in cell AW2:

=IF(AW2>

8.png

A probability is expressed between 0 and 1, therefore .8 would represent 80% likelihood.  It follows that the threshold value would be .8, which would complete the IF function:

=IF(AW2>0.8

9.png

Enter the remaining parameter that will be returned try as 1, then the false return value as 0:

=IF(AW2>0.8,1,0

10.png

Complete the formula by closing the parentheses, fill down and name the column Model_1_Is_Fraud.  Accordingly, any example with a value of one, would be considered activated:

11.png