The Logistic Regression Model

Quick Review

Basic Flow

Import LogisticRegression module from Biopython

Define a list containing the distance and the score of similarity in expression profile between the 2 genes

Define a list specifies if the gene pair belongs to the same operon (1) or different operons (0)

Run logistic regression on the training data to esitmate coefficients

Output the weights estimated from logistic regression training model

Using the logistic regression model for classification

Let's predict gene pair yxcE — yxcD

Let's predict gene pair yxiB — yxiA

The above prediction agrees with the biological literature

Hooray! Let's celebrate!!!

Fancier Analyses

To run the code in this section, the following keys steps must be run ahead of time

  1. Import LogisticRegression module from Biopython

  2. Define a list containing the distance and the score of similarity in expression profile between the 2 genes

  3. Define a list specifies if the gene pair belongs to the same operon (1) or different operons (0)

Using arguments in train function

We can use update_fn argument in the train function to track the progress of the model calculation

First define a fundtion show_progress to print the desired outputs

Then call train function with update_fn argument to output log-likelihood at each iteration

The iteration stops once the increase in the log-likelihood function is less than 0.01. If no convergence is reached after 500 iterations, the train function returns with an AssertionError.

We can also apply typecode argument in train function to save memory for gigantic data it may be necessary to use single-precision floats rather than double

Take a look at the estimated weights

Print the classification results in more intuitive ways

Output

Output

Obtain the probabilities

Obtain the probabilities to find out how confident we can be in these predictions

Output

Prediction Accuracy

To get some idea of the prediction accuracy of the logistic regression model, we can apply it to the training data:

Output

A more reliable estimate of the prediction accuracy can be found from a leave-one-out analysis the model is recalculated from the training data after removing the gene to be predicted:

Output

Using optional arguments in classify function to specify distance and weight

By default, the Euclidean distance is used.

Instead, we could use the city-block (Manhattan) distance:

Output:

Using weight function to assign higher weight for closer pairs

Output:

Call the calculate function to calculate the confidence in predictions

This will calculate the total weight assigned to the classes OP and NOP

Output:

Output:

Prediction Accuracy

Output:

The prediction is correct for all but two of the gene pairs

A more reliable estimate of the prediction accuracy can be found from a leave-one-out analysis The model is recalculated from the training data after removing the gene to be predicted:

Output:

The prediction is correct for 13 out of 17 gene pairs, 76%

Last updated

Was this helpful?