PREDICT_LOGISTIC_REG

Applies a logistic regression model on an input table or view.

Important: Before using a machine learning function, be aware that all the ongoing transactions might be committed.

Syntax

PREDICT_LOGISTIC_REG ( col1, col2, ... coln
                         USING PARAMETERS model_name = 'name_of_model'
                                         [, type = 'prediction_type',]
                                         [cutoff = probability_cutoff,] 
                                         [match_by_pos = 'method'])

Arguments

col1, col2, ..., coln

The columns to use from the input table or view.

Parameters

model_name = 'name_of_model'

The name of the logistic regression model.

type = 'prediction_type'

(Optional) Determines the type of prediction for logistic regression.

When response is selected the predicted values are 0 or 1. When probability is selected, the output will be the probability of the predicted category to be 1.

Valid Values

  • response (Default Value)
  • probability
cutoff = probability_cutoff

(Optional). Used in conjunction with type. Valid responses are between 0 and 1, exclusive. When the value of type is "response", the returned value of prediction would be 1 if its corresponding probability is bigger than or equal to the value of cutoff; otherwise, it is 0.

Default Value: 0.5

match_by_pos= 'method'

(Optional) Valid Values:

  • false (default): Input columns will be matched to features in the model based on their names.

  • true: Input columns will be matched to features in the model based on their position in the list of indicated input columns.

Return

Return data type: FLOAT

Returns the predicted class or the probability of the predicted class, depending on the response input. The return can be cast to INT or other numeric types when the return is in the probability of the predicted class.

Examples

The following example shows how you can use the PREDICT_LOGISTIC_REG function on an input table.

=> SELECT car_model,
            PREDICT_LOGISTIC_REG(mpg, cyl, disp, drat, wt, qsec, vs, gear, carb
                                 USING PARAMETERS model_name='myLogisticRegModel')
          FROM mtcars;
      car_model      | PREDICT_LOGISTIC_REG
---------------------+----------------------
 Camaro Z28          |                    0
 Fiat 128            |                    1
 Fiat X1-9           |                    1
 Ford Pantera L      |                    1
 Merc 450SE          |                    0
 Merc 450SL          |                    0
 Toyota Corona       |                    0
 AMC Javelin         |                    0
 Cadillac Fleetwood  |                    0
 Datsun 710          |                    1
 Dodge Challenger    |                    0
 Hornet 4 Drive      |                    0
 Lotus Europa        |                    1
 Merc 230            |                    0
 Merc 280            |                    0
 Merc 280C           |                    0
 Merc 450SLC         |                    0
 Pontiac Firebird    |                    0
 Porsche 914-2       |                    1
 Toyota Corolla      |                    1
 Valiant             |                    0
 Chrysler Imperial   |                    0
 Duster 360          |                    0
 Ferrari Dino        |                    1
 Honda Civic         |                    1
 Hornet Sportabout   |                    0
 Lincoln Continental |                    0
 Maserati Bora       |                    1
 Mazda RX4           |                    1
 Mazda RX4 Wag       |                    1
 Merc 240D           |                    0
 Volvo 142E          |                    1
(32 rows)

The following example shows how you can use the PREDICT_LOGISTIC_REG function on an input table, using the match_by_pos parameter. Note that you can any of the column inputs with a constant that does not match an input column. In this example, the mpg column was replaced with the constant 20:

=> SELECT car_model,
            PREDICT_LOGISTIC_REG(20, cyl, disp, drat, wt, qsec, vs, gear, carb
                                 USING PARAMETERS model_name='myLogisticRegModel', match_by_pos='true')
          FROM mtcars;
      car_model     | PREDICT_LOGISTIC_REG
--------------------+----------------------
AMC Javelin         |                    0
Cadillac Fleetwood  |                    0
Camaro Z28          |                    0
Chrysler Imperial   |                    0
Datsun 710          |                    1
Dodge Challenger    |                    0
Duster 360          |                    0
Ferrari Dino        |                    1
Fiat 128            |                    1
Fiat X1-9           |                    1
Ford Pantera L      |                    1
Honda Civic         |                    1
Hornet 4 Drive      |                    0
Hornet Sportabout   |                    0
Lincoln Continental |                    0
Lotus Europa        |                    1
Maserati Bora       |                    1
Mazda RX4           |                    1
Mazda RX4 Wag       |                    1
Merc 230            |                    0
Merc 240D           |                    0
Merc 280            |                    0
Merc 280C           |                    0
Merc 450SE          |                    0
Merc 450SL          |                    0
Merc 450SLC         |                    0
Pontiac Firebird    |                    0
Porsche 914-2       |                    1
Toyota Corolla      |                    1
Toyota Corona       |                    0
Valiant             |                    0
Volvo 142E          |                    1
 
(32 rows)