Package: sibyl-api
An open source project from Data to AI Lab at MIT.Sibyl-APIAPIs for explainable ML.API Documentation:https://sibyl-ml.dev/sibyl-api/OverviewInterpretability is perhaps most impactful in situations where humans make decisions with input from amachine learning model. In such situations, humans have traditionally made decisions without ML models, and as such use the ML model predictions as an aideto improve their effectiveness or speed.
In these cases, explanations can serve many functions. They may help build user trust in the model, identify possible mistakes in the model’s prediction, expedite decisionmaking, maintain accountability, validate their hypotheses, or satisfy curiosity.Sibylapp is an online interactive tool built on the top of Sibyl (python library) to provide explanations to predictive models on tabular data.InstallRequirementsSibyl-APIhas been developed and tested onPython 3.9, 3.10, and 3.11, and onMongoDB version 6 and 7.To install MongoDB, follow the instructionshere.Install from PyPiSibyl-API can be installed from pypi:pipinstallsibyl-apiInstall from sourceSibyl-API usesPoetryfor dependency management. If you do not havePoetryinstalled, please head topoetry installation guideand install poetry according to the instructions.
Run the following command to make sure poetry is activated. You may need to close and reopen the terminal.poetry--versionThen, you can clone this repository and install it from
source by runningpoetry install:gitclonehttps://github.com/sibyl-dev/sibyl-api.gitcdsibyl-api
poetryinstallQuickstartFollow these steps to get started with the built-in Ames Housing dataset example.
You can prepare and load the Ames Housing dataset by runningsibylprepare-sample-db⚠️ This function will overwrite any
existing database on localhost:27017 with the namehousing):You can now run Sibyl-API with the sample dataset with:poetryrunsibylrun-Dhousing-vOnce Sibyl-API is running, you can access and test your APIs manually atlocalhost:3000/apidocsPreparing databaseSibyl-API uses a MongoDB-based database system. We offer several methods to setup your database.Preparing dataRequired inputsAt minimum, sibyl-API requires the following inputs (either as a DataFrame or csv, see creation options below):entities: A table with the entities to be explained. Each row should correspond to a single observation.Columns:eid(required): unique identifier specifying which entity this observation corresponds torow_id: unique identifier specifying the observation ID. Together,eidandrow_idshould uniquely identify each observation.label: the ground-truth label for this observation[FEATURES]: additional columns for each feature used to make predictions. These columns should be named the same as the features used in the model.Sample table:eidrow_idlabelfeature1feature2feature3entity110100.10.20.3entity110210.20.30.4entity220410.30.40.5features: A table with the features used to make predictions. Each row should correspond to a single feature.Columns:feature(required): the name of the featuretype(required): the type of the feature. This can becategorical,numerical, orbooleandescription: a description of the featurenegative_description: a description of the feature when it is not present. Only for boolean featuresvalues: a list of possible values for the feature. Only for categorical features.Sample table:featuretypedescriptionnegative_descriptionvaluessizenumericalsize in square feethas_acbooleanhas air conditioningdoes not have air conditioningnghbrhcategoricalneighborhood[Oceanview, Ridge, Oakvale]realapp: A pickledpyreal.RealAppobject. This object is used to generate explanations for the model.Optional inputsAdditionally, you can configure APIs futher with:config: a configuration file (YAML or python dictionary) specifying
additional settings. Seesibyl/db/config_template.ymlfor options.categories: a table with the categories used to make predictions. Each row should correspond to a single category.Columns:category(required): the name of the categorydescription: a description of the categorycolor: color to use for the categoryabbreviation: abbreviation to use for the categoryCreating the Mongo databaseWith the prepare-db scriptBe sure tostartyour mongodb service before preparing the databaseCopysibyl/db/config_template.ymland fill it in with your configurations. Place required data
in a common directory.Next, run the preprocessing script with:sibylrunprepare-db[CONFIG_NAME].yml[DIRECTORY]where[CONFIG_NAME].ymlis the path to your configuration file and[DIRECTORY]is
the directory containing your data.With the Setup WizardCurrently, the setup wizard is only available when installing from source.
First, install the optional setup dependencies withpoetryinstall--withsetupThen, run the setup wizard withpoetryrunstreamlitrunsetup-wizard/main.pyRunning APIsOnce the library has been installed, you can run the APIs locally with:poetryrunsibylrun-v-D[DATABASE_NAME]Or, to run in development mode:poetryshell

sibylrun-Edevelopment-v-D[DATABASE_NAME]You can then access your APIs locally athttp://localhost:3000/apidocsContributing GuideWe appreciate contributions of all kinds! To contribute code to the repo please follow these steps:Clone and install the library and load in your test database(s) following the instructions above.Make a new branch off ofdevwith a descriptive name describing your change.Make changes to that branch, committing and pushing code as you go.Run the following commands to ensure your code passed required code style guidelines and tests:# Run all tests
poetry run invoke test

# Run unit tests only
poetry run invoke test-unit

# Fix most linting errors
poetry run invoke fix-lint

# Ensure no linting errors remain
poetry run invoke lintYou can manually runsibyl/test_apis_on_database.ipynbon your database(s) to test further.Before making a PR with your final changes, update the api docs by running Sibyl with the -G flag, ie.# Generate docs
poetry run sibyl run -GOnce all tests/linting pass, push all code and make a pull request. One all checks pass and the PR has been approved, merge your code and delete the branch.