cc_tk.relationship.significance package
Submodules
cc_tk.relationship.significance.base module
Evaluate the significance of the relationship between 2 variables.
Usually this consists in evaluating the relationship between a feature and the target variable.
- class cc_tk.relationship.significance.base.Constants[source]
Bases:
objectConstants for the relationship functions.
- STRONG_THRESHOLD = 0.05
- WEAK_THRESHOLD = 0.1
- class cc_tk.relationship.significance.base.SignificanceCategoricalCategorical[source]
Bases:
ABCBase class for the categorical/categorical significance.
- class cc_tk.relationship.significance.base.SignificanceCategoricalNumeric[source]
Bases:
ABCBase class for the categorical/numeric significance.
- class cc_tk.relationship.significance.base.SignificanceEnum(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
str,EnumDefines the significance levels.
- MEDIUM_VALUE = 'medium'
- STRONG_VALUE = 'strong'
- WEAK_VALUE = 'weak'
- class cc_tk.relationship.significance.base.SignificanceNumericCategorical[source]
Bases:
ABCBase class for the numeric/categorical significance.
- class cc_tk.relationship.significance.base.SignificanceNumericNumeric[source]
Bases:
ABCBase class for the numeric/numeric significance.
- class cc_tk.relationship.significance.base.SignificanceOutput(*, pvalue: float, influence: Series, statistic: float, message: str = '')[source]
Bases:
BaseModelOutput of the significance functions.
- influence: Series
- message: str
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- pvalue: float
- property significance: SignificanceEnum
Computing significativity based on pvalue.
- statistic: float
cc_tk.relationship.significance.predictiveness module
Significance tests based predictiveness scores.
- class cc_tk.relationship.significance.predictiveness.PredictivenessCategoricalCategorical(*, model: ~sklearn.base.ClassifierMixin = <factory>, scoring: str = 'roc_auc', cv: int = 5, n_bootstrap: int = 100, n_sample: int | None = None)[source]
Bases:
PredictivenessSignificance,SignificanceCategoricalCategoricalPredictiveness categorical/categorical significance test. Significance test based on predictiveness scores.
- Parameters:
model (Union[RegressorMixin, ClassifierMixin]) – Model to use for the predictiveness score, depends on the type of the target. Advised to use a model that can handle non-linear relationships such as a tree-based model.
scoring (Union[str, callable]) – Scoring function to use for the predictiveness score. It should be an increasing function, the higher the better.
cv (int, optional) – Number of folds for the cross-validation, by default 5.
n_bootstrap (int, optional) – Number of bootstrap samples to compute the pvalue, by default 100.
n_sample (Optional[int], optional) – Number of samples to use for the predictiveness score, by default None will use all the samples.
- model: ClassifierMixin
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- scoring: str
- class cc_tk.relationship.significance.predictiveness.PredictivenessCategoricalNumeric(*, model: ~sklearn.base.RegressorMixin = <factory>, scoring: str = 'r2', cv: int = 5, n_bootstrap: int = 100, n_sample: int | None = None)[source]
Bases:
PredictivenessSignificance,SignificanceCategoricalNumericPredictiveness categorical/numeric significance test. Significance test based on predictiveness scores.
- Parameters:
model (Union[RegressorMixin, ClassifierMixin]) – Model to use for the predictiveness score, depends on the type of the target. Advised to use a model that can handle non-linear relationships such as a tree-based model.
scoring (Union[str, callable]) – Scoring function to use for the predictiveness score. It should be an increasing function, the higher the better.
cv (int, optional) – Number of folds for the cross-validation, by default 5.
n_bootstrap (int, optional) – Number of bootstrap samples to compute the pvalue, by default 100.
n_sample (Optional[int], optional) – Number of samples to use for the predictiveness score, by default None will use all the samples.
- model: RegressorMixin
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- scoring: str
- class cc_tk.relationship.significance.predictiveness.PredictivenessNumericCategorical(*, model: ~sklearn.base.ClassifierMixin = <factory>, scoring: str = 'roc_auc', cv: int = 5, n_bootstrap: int = 100, n_sample: int | None = None)[source]
Bases:
PredictivenessSignificance,SignificanceNumericCategoricalPredictiveness numeric/categorical significance test. Significance test based on predictiveness scores.
- Parameters:
model (Union[RegressorMixin, ClassifierMixin]) – Model to use for the predictiveness score, depends on the type of the target. Advised to use a model that can handle non-linear relationships such as a tree-based model.
scoring (Union[str, callable]) – Scoring function to use for the predictiveness score. It should be an increasing function, the higher the better.
cv (int, optional) – Number of folds for the cross-validation, by default 5.
n_bootstrap (int, optional) – Number of bootstrap samples to compute the pvalue, by default 100.
n_sample (Optional[int], optional) – Number of samples to use for the predictiveness score, by default None will use all the samples.
- model: ClassifierMixin
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- scoring: str
- class cc_tk.relationship.significance.predictiveness.PredictivenessNumericNumeric(*, model: ~sklearn.base.RegressorMixin = <factory>, scoring: str = 'r2', cv: int = 5, n_bootstrap: int = 100, n_sample: int | None = None)[source]
Bases:
PredictivenessSignificance,SignificanceNumericNumericPredictiveness numeric/numeric significance test. Significance test based on predictiveness scores.
- Parameters:
model (Union[RegressorMixin, ClassifierMixin]) – Model to use for the predictiveness score, depends on the type of the target. Advised to use a model that can handle non-linear relationships such as a tree-based model.
scoring (Union[str, callable]) – Scoring function to use for the predictiveness score. It should be an increasing function, the higher the better.
cv (int, optional) – Number of folds for the cross-validation, by default 5.
n_bootstrap (int, optional) – Number of bootstrap samples to compute the pvalue, by default 100.
n_sample (Optional[int], optional) – Number of samples to use for the predictiveness score, by default None will use all the samples.
- model: RegressorMixin
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- scoring: str
- class cc_tk.relationship.significance.predictiveness.PredictivenessSignificance(*, model: RegressorMixin | ClassifierMixin, scoring: str, cv: int = 5, n_bootstrap: int = 100, n_sample: int | None = None)[source]
Bases:
BaseModelSignificance test based on predictiveness scores.
- Parameters:
model (Union[RegressorMixin, ClassifierMixin]) – Model to use for the predictiveness score, depends on the type of the target. Advised to use a model that can handle non-linear relationships such as a tree-based model.
scoring (Union[str, callable]) – Scoring function to use for the predictiveness score. It should be an increasing function, the higher the better.
cv (int, optional) – Number of folds for the cross-validation, by default 5.
n_bootstrap (int, optional) – Number of bootstrap samples to compute the pvalue, by default 100.
n_sample (Optional[int], optional) – Number of samples to use for the predictiveness score, by default None will use all the samples.
- cv: int
- model: RegressorMixin | ClassifierMixin
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- n_bootstrap: int
- n_sample: int | None
- score_predictiveness(x: Series, y: Series) float[source]
Compute predictiveness score.
- Parameters:
x (pd.Series) – Feature values
y (pd.Series) – Target values
- Returns:
Predictiveness score
- Return type:
float
- scoring: str
- cc_tk.relationship.significance.predictiveness.estimate_pvalue(statistic_value: float, statistic_array: ndarray, kind: Literal['both', 'left', 'right'] = 'both') float[source]
Estimate the pvalue of a statistic.
- Parameters:
statistic_value (float) – Value of the statistic
statistic_array (np.ndarray) – Array of the statistic
kind (Literal["both", "left", "right"], optional) –
- Tail-kind of the test:
”both” : two-sided test
”left” : one-sided test, left tail
”right” : one-sided test, right tail
, by default “both”.
- Returns:
Pvalue estimation
- Return type:
float
cc_tk.relationship.significance.statistical module
Significance tests based on statistical methods.
- class cc_tk.relationship.significance.statistical.AnovaSignificance[source]
Bases:
objectBase class for ANOVA significance tests.
- compute_significance(numeric_values: Series, categorical_values: Series) SignificanceOutput[source]
Anova or Kruskal-Wallis significance test.
- Parameters:
numeric_values (pd.Series) – Numeric values which we are interested in knowing if there is a difference in distribution
categorical_values (pd.Series) – Categorical values to divide the numeric values in groups
- Returns:
Output of the significance function
- Return type:
- class cc_tk.relationship.significance.statistical.AnovaSignificanceCategoricalTarget[source]
Bases:
SignificanceNumericCategorical,AnovaSignificanceAnova significance test with categorical target.
- class cc_tk.relationship.significance.statistical.AnovaSignificanceNumericTarget[source]
Bases:
SignificanceCategoricalNumeric,AnovaSignificanceAnova significance test with numeric target.
- class cc_tk.relationship.significance.statistical.Chi2Significance(hypotheses_threshold: int | None = 5)[source]
Bases:
SignificanceCategoricalCategoricalSignificance based on Chi2 test.
- class cc_tk.relationship.significance.statistical.PearsonSignificance[source]
Bases:
SignificanceNumericNumericSignificance test based on Pearson correlation.
Module contents
Significance functions for different input types and significance types.
- cc_tk.relationship.significance.get_significance(feature_type: Literal[VariableType.NUMERIC], target_type: Literal[VariableType.NUMERIC], significance_type: SignificanceType) SignificanceNumericNumeric[source]
- cc_tk.relationship.significance.get_significance(feature_type: Literal[VariableType.NUMERIC], target_type: Literal[VariableType.CATEGORICAL], significance_type: SignificanceType) SignificanceNumericCategorical
- cc_tk.relationship.significance.get_significance(feature_type: Literal[VariableType.CATEGORICAL], target_type: Literal[VariableType.NUMERIC], significance_type: SignificanceType) SignificanceCategoricalNumeric
- cc_tk.relationship.significance.get_significance(feature_type: Literal[VariableType.CATEGORICAL], target_type: Literal[VariableType.CATEGORICAL], significance_type: SignificanceType) SignificanceCategoricalCategorical
Get significance function based on variable types and significance type.
- Parameters:
feature_type (VariableType) – Input type of the feature.
target_type (VariableType) – Input type of the target.
significance_type (SignificanceType) – Significance type.
**kwargs – Additional keyword arguments passed to the significance initialization.
- Returns:
Significance instance.
- Return type:
Significance
- Raises:
ValueError – If the feature type and target type are not supported or incompatible with the significance type.