IsModelValid
IsModelValid
The function calculates whether the model meets prespecified requirements.
Parameters:
- model:
LogitModel
An object of LogitModel class. - coef_expectation:
pd.DataFrame
A pandas DataFrame object containing variable names and their sign expectations. - p_value:
float, default = 0.05
Variable significance level. - check_sample:
str, {'test', 'train'}, default = 'test'
The sample to perform the test. - metric:
str, {'gini', 'auc'}, default = 'gini'
A metric used to measure the model accuracy. - gini_cutoff:
float, default = 0.4
A cutoff value for Gini. - auc_cutoff:
float, default = 0.7
A cutoff value for AUC.
Exceptions:
-
TypeError: Raised if the
modelparameter is not of type LogitModel.
Raised if thecoef_expectationparameter is not a pandas DataFrame. -
ValueError: Raised if the
check_sampleparameter is not in ['train', 'test'].
Raised if themetricparameter is not in ['gini', 'auc'].
Raised if thep_valueparameter is not a float from 0 to 0.5.
Raised if thegini_cutoffparameter is not a float from 0 to 1.
Raised if theauc_cutoffparameter is not a float from 0 to 1.
Example:
from combat.models import LogitModel
from combat.combat import IsModelValid
import pandas as pd
# Sample input data
model = LogitModel()
coef_expectation = pd.DataFrame({'variable': ['var1', 'var2'], 'sign_expectation': [1, -1]})
p_value = 0.05
check_sample = 'test'
metric = 'gini'
gini_cutoff = 0.4
auc_cutoff = 0.7
# Check if the model is valid
validity = IsModelValid(model, coef_expectation, p_value, check_sample, metric, gini_cutoff, auc_cutoff)
print("Is the model valid?", validity)