Skip to main content

Calibratiing model scores/probabilites with pyspark dataframes

Project description

Model calibration with pyspark

This package provides a Betacal class which allows the user to fit the default beta calibration model and predict calibrated scores

Setup

spark-calibration is uploaded to PyPi and can be installed with this command:

pip install spark-calibration

Usage

Training

train_df should be a pyspark dataframe with score and label columns

from spark_calibration import Betacal
from spark_calibration import display_classification_calib_metrics
from spark_calibration import plot_calibration_curve


bc = Betacal(parameters="abm")

# training
train_df = spark.read.parquet("s3://train/")
bc.fit(train_df)


# Get the logistic regression model and individual coefficients
print(bc.lr_model, a, b)

# a,b -> coefficients of lr model
# lr_model -> pyspark ml logistic regression model

Prediction

test_df is a pyspark dataframe with score as one of the columns. The predict function adds a new column prediction which has the calibrated score

test_df = spark.read.parquet("s3://test/")
test_df = bc.predict(test_df)

Pre post calibration metrics comparison

The test_df should have score, prediction & label columns. The display_classification_calib_metrics functions displays brier_score_loss, log_loss, area_under_PR_curve and area_under_ROC_curve

display_classification_calib_metrics(test_df)

plot the calibration curve

Computes true, predicted probabilites (pre & post calibration) using quantile binning strategy with 50 bins and plots the calibration curve

plot_calibration_curve(test_df)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spark_calibration-1.0.7.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spark_calibration-1.0.7-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file spark_calibration-1.0.7.tar.gz.

File metadata

  • Download URL: spark_calibration-1.0.7.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for spark_calibration-1.0.7.tar.gz
Algorithm Hash digest
SHA256 422eff933ec2dd7a868857673c528f8cbadf6dd8797c4e902acc09faeb3f5964
MD5 ebb607220018741537c70c6aefd29028
BLAKE2b-256 6c9a771d2f0338037a72a26af542b80be80dd435e3ede1f7a2c42406693dac04

See more details on using hashes here.

File details

Details for the file spark_calibration-1.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for spark_calibration-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 4d1442c4f6cc28be27322f2a7f4062fde846ec8575d16e3b50603091f650b6b2
MD5 b37b28f6b730c9300acf3a405c4e8246
BLAKE2b-256 a30bc59f77e1a538f13c74cd1e6dea46aaadc05e6a452260b724e6c09dcbecb2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page