Compatibility#
This page states what a release of kivi may change and what it keeps: the versions it supports, the public names, the layout of the tables it returns, its exception types and the files of BinningSpec and FeatureSpec. The rules that every function follows, such as the order of the arguments, are on Conventions, and they are part of the API too.
Releases and deprecations#
From version 1.0, kivi follows semantic versioning:
A major release, such as 2.0, may remove or change any part of the public API.
A minor release, such as 1.3, adds functions, arguments, table columns or format versions, and may deprecate a part of the API.
A patch release, such as 1.3.1, only fixes errors.
A deprecated function, argument or behavior keeps working, with a
FutureWarningthat says what to use instead, for the rest of the major version. It changes in the next major release, so a deprecation of 1.4 takes effect in 2.0. The release notes list each deprecation under Changed.A fix of a wrong result can come in any release, minor or patch, even when code relies on the wrong result. The release notes list such fixes under Fixed.
Before 1.0 a shorter rule applied: what 0.9 deprecated changed in 1.0, as Migration guide lists. To find the calls that a release will change, run the code or its tests with FutureWarning turned into an error, as python -W error::FutureWarning or pytest -W error::FutureWarning do.
Supported versions#
kivi supports Python 3.10 or newer, NumPy 1.24 or newer and pandas 2.0 or newer, and its tests run on these oldest versions and on the newest releases. The charts of kivi.plotting also need matplotlib 3.7 or newer, which pip install "kivi[plot]" installs; no other module imports it. From 1.0, a minimum version rises only in a minor release, and the notes of the release before it announce the change. A patch release never raises a minimum.
What is public#
The names that a public module lists in its
__all__:kivi.features,kivi.binning,kivi.woe,kivi.stability,kivi.univariate,kivi.selection,kivi.scorecard,kivi.expert,kivi.metrics,kivi.calibration,kivi.lgd,kivi.strategy,kivi.reject_inference,kivi.spec,kivi.monitoring,kivi.capital,kivi.vintage,kivi.lifetime,kivi.plottingandkivi.datasets. Each has a page in this reference that documents every such name.kivi.__version__is public too.The documented members of
BinningSpec: its fields,FORMAT_VERSION,format_versionandcolumns, its methods, and its equality, hashing, pickling anddataclasses.replace. The same holds forFeatureSpec, which hasFORMAT_VERSIONandcolumnsbut noformat_version, because its format has one version so far.SeparationError, whichplatt_fit()raises as well, stays inkivi.selection.The names of the arguments. A keyword is part of a call, so renaming an argument needs a deprecation, even one that is usually passed by position.
Everything else is private: the modules and names that start with an underscore, and the modules that a public module imports, such as
kivi.binning.np. They can change in any release.
Results that are pairs of parameters, such as the (factor, offset) of score_scaling(), the (slope, intercept) of platt_fit(), the (edges, probability) of isotonic_fit(), the (statistic, p_value) of hosmer_lemeshow() and spiegelhalter_test() and the (probability, correlation) of vasicek_fit(), are tuples. A minor release may turn them into named tuples, which unpack in the same way.
Tables#
The index name, the column names and the order of the columns of every table are public. A minor release may append columns at the end of a table, but renames, reorders or removes a column only after a deprecation, so select columns by name rather than by position. The attrs of logistic_regression() and fractional_regression() are set on the returned frame, and pandas drops them in many operations.
Function |
Index |
Columns |
|---|---|---|
The index of |
For each window in turn |
|
The index of |
For each window in turn |
|
The index of |
The columns of each group of |
|
|
|
|
|
A Series named |
|
|
|
|
|
|
|
|
|
|
|
|
|
A Series with the index |
||
A Series with the index |
||
|
|
|
|
|
|
|
|
|
|
|
|
A Series with the index |
||
|
|
|
|
|
|
|
|
|
A Series named |
||
A |
||
|
|
|
|
|
|
The index of |
One column per variable of |
|
The index of |
|
|
A Series named |
||
A Series with the index |
||
A Series named |
||
|
|
|
|
|
|
|
|
|
|
|
|
The index of |
|
|
The index of |
|
|
A Series named |
||
|
|
|
|
One per column of |
|
|
|
|
|
|
|
A Series named |
||
A range, one row per loan and month |
|
|
|
One per month on book, in columns named |
|
|
One per state, in columns named |
|
A Series named |
||
A Series with the index |
||
|
|
|
|
One per horizon, in columns named |
|
|
|
|
|
|
|
A range |
|
|
A range |
|
|
A range, sorted by applicant and time |
|
|
A range, sorted by default date |
|
|
A range, in the order of the loans of |
|
|
A range |
The 16 columns of the UCI data and |
The feature names follow from the arguments. Column names and prefixes are kept as given, and kivi’s own parts of the names, the aggregations, the windows and the names of the panel features, are in lower case, with windows written as 3m, 90d or 6m_3m. The dtypes are public too: the events, count and nunique features and the counts of panel_features() are int64, worst_status has the dtype of the status column, and the other features are float64. A window without values gives 0 for these counts and for sum, a missing status for worst_status, and NaN for the other features.
load_bank() always returns the same data. make_loan_panel(), make_applications(), make_transactions(), make_defaults() and make_recoveries() keep their columns and dtypes, including the categories of kind, merchant_category and segment, but the values that they simulate for a given rng stay the same only within a minor version, so that a minor release can improve the simulation.
woe_trend() returns one of six labels, "increasing", "decreasing", "u_shaped", "inverted_u", "irregular" and "flat", which are public like column names, and so is its rule that neighbouring bins whose WOE differ by at most a relative \(10^{-10}\) neither rise nor fall.
The random indices of ahp_consistency(), the table of Tone (1986) for 3 to 15 factors, are constants. A release changes them only to correct a wrong value, as a fix that the release notes list under Fixed, so the consistency ratio of a matrix stays the same from release to release.
Charts#
The functions of kivi.plotting keep the data that they draw from each table, which column goes on which axis, their arguments, the errors they raise and what they return: every function returns the matplotlib.axes.Axes it drew on, except woe_chart(), the one chart with two y-axes, which returns the pair of Axes of its bars and its line. distribution_chart() draws the shares of the raw non_event and event counts, not the smoothed share columns of a WOE table, and precision_recall_chart() draws the rows of a ROC table that have a precision and a line at the precision of its last row, the event rate. Colors, line styles, figure sizes, the placement of legends and annotations, tick formats and the number of matplotlib artists that make up a chart may change in any release, so that a release can improve how the charts look. Code that styles a chart further should work on the returned Axes rather than on the artists inside it.
Errors and warnings#
The exception types are public. Invalid input raises
ValueError, and a model that cannot be fitted raisesSeparationError, a subclass ofValueError. A call that Python itself rejects, such as one with a missing or an unknown argument, raisesTypeError.The warning categories are public: a
UserWarningmeans that a result differs from the request, aRuntimeWarningthat a fit did not converge, and aFutureWarningthat a part of the API is deprecated.The wording of a message is not public and may change in any release. The rule that a message names the argument and the value received stays.
Saved specifications#
BinningSpec.to_json and FeatureSpec.to_json write files that later releases read; Binning specifications and Time-window features describe their formats.
formatis always"kivi.BinningSpec"or"kivi.FeatureSpec", andformat_versionis an integer. A binning specification has version 1 without category groupings and 2 when it groups a column. A feature specification has version 1, the format of kivi 1.3.0, whose keys afterkivi_versionare the arguments ofFeatureSpecas it takes them:id,observation_time,events,ratiosandpanel, with every key of each group.Every 1.x release reads every format version of a binning specification written by kivi 0.6.0 or later, and of a feature specification written by kivi 1.3.0 or later.
A specification is written in the lowest format version that can hold it, so a file that uses no newer feature stays readable by older releases. A new format version only adds content, and within a major version the meaning of an existing key never changes.
A file with a newer format version raises
ValueErrorand names the version, instead of being read in part. Unknown keys raise as well, so a new key always comes with a new format version. A feature specification also raises for a missing key and for a key repeated within one JSON object.kivi_versionrecords the release that wrote the specification and never changes how a file is read. Equality and hashing include it, as they include every field, so a specification saved by an earlier release differs from the same fit today; Saving and loading a specification shows how to compare their content.Encoding with a binning specification reads only the
binandwoeof each table row. The other columns describe the fit and are loaded as written.
The tests of kivi keep binning specifications written by 0.6.0, in format version 1, and by 0.8.0, in format version 2, and check that each loads and encodes a fixed sample exactly as the release that wrote it did, and that it matches a fresh fit apart from kivi_version and the rounding of the last digits. They keep a feature specification of 1.3.0 in the same way, with window and panel groups and ratios, and check that it loads, writes the same JSON again and computes the same features of a fixed sample.