Open In Colab

Logistic Regression (Classification)

Installation

# To install the required package, use the following command:
# !pip install modeva

Authentication

# To get authentication, use the following command: (To get full access please replace the token to your own token)
# from modeva.utils.authenticate import authenticate
# authenticate(auth_code='eaaa4301-b140-484c-8e93-f9f633c8bacb')

Import required modules

from modeva import DataSet
from modeva import TestSuite
from modeva.models import MoLogisticRegression

Load and prepare dataset

ds = DataSet()
ds.load(name="TaiwanCredit")
ds.set_random_split()
ds.set_target("FlagDefault")

Train model

model = MoLogisticRegression(name="GLM",
                             feature_names=ds.feature_names,
                             feature_types=ds.feature_types)
model.fit(ds.train_x, ds.train_y)


# Basic accuracy analysis
# ----------------------------------------------------------
ts = TestSuite(ds, model)
results = ts.diagnose_accuracy_table()
results.table
AUC ACC F1 LogLoss Precision Recall Brier
train 0.7369 0.8019 0.3466 0.4647 0.6510 0.2362 0.1470
test 0.7371 0.8075 0.3389 0.4537 0.6578 0.2282 0.1429
GAP 0.0002 0.0056 -0.0078 -0.0110 0.0068 -0.0080 -0.0040


Coefficient interpretation

results = ts.interpret_coef(features=("PAY_1", "PAY_2", "PAY_3", "EDUCATION", "SEX"))
results.plot()


Feature importance

results = ts.interpret_fi()
results.plot()


Main effect plot

results = ts.interpret_effects(features="PAY_1")
results.plot()


Local feature importance analysis

results = ts.interpret_local_fi(dataset="train",
                                sample_index=15,
                                centered=True)
results.plot()


Local feature importance with linear coefficients

results = ts.interpret_local_linear_fi(dataset="test",
                                       sample_index=15,
                                       centered=True)
results.plot()


Total running time of the script: (0 minutes 1.610 seconds)

Gallery generated by Sphinx-Gallery