Tool to automagically save scikit-learn scaler properties to a portable, readable format.
Project description
bridgescaler
Bridge your scikit-learn scaler parameters between Python sessions and users. Bridgescaler allows you to save the properties of a scikit-learn scaler object to a json file, and then repopulate a new scaler object with the same properties.
Dependencies
- scikit-learn
- numpy
- pandas
Installation
git clone https://github.com/NCAR/bridgescaler.git
cd bridgescaler
pip install .
Usage
bridgescaler supports all the common scikit-learn scaler classes:
- StandardScaler
- RobustScaler
- MinMaxScaler
- MaxAbsScaler
- QuantileTransformer
- PowerTransformer
- SplineTransformer
First, create some synthetic data to transform.
import numpy as np
import pandas as pd
# specify distribution parameters for each variable
locs = np.array([0, 5, -2, 350.5], dtype=np.float32)
scales = np.array([1.0, 10, 0.1, 5000.0])
names = ["A", "B", "C", "D"]
num_examples = 205
x_data_dict = {}
for l in range(locs.shape[0]):
# sample from random normal with different parameters
x_data_dict[names[l]] = np.random.normal(loc=locs[l], scale=scales[l], size=num_examples)
x_data = pd.DataFrame(x_data_dict)
Now, let's fit and transform the data with StandardScaler.
from sklearn.preprocessing import StandardScaler
from bridgescaler import save_scaler, load_scaler
scaler = StandardScaler()
scaler.fit_transform(x_data)
filename = "x_standard_scaler.json"
# save to json file
save_scaler(scaler, filename)
# create new StandardScaler from json file information.
new_scaler = load_scaler(filename) # new_scaler is a StandardScaler object
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for bridgescaler-0.1b1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f26eb799d7f0c24253cb25ce935fdeffffe0d8a3b3d99fd940acd965813806d |
|
MD5 | 0d8b57caf1bca5ac65de3b352d36c38b |
|
BLAKE2b-256 | 136a338dabd4ba404b528c12c6ce06d0ae8889d585dc59525e5253bb4d19fa66 |