Skip to main content

A few useful tools for Machine Learning

Project description

mlutil

Utilities for ML models.

Whenever possibles, modules are made to be compatible with scikit-learn.

Installation

pip install mlutil

Modules

  • eval (cross-validation)
  • model (ML models)
  • transform (feature transformers)
  • tune (TBD: ML model tuning)

Eval

import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import cross_validate
from mlutil.eval import TimeSeriesSplit

X = np.vstack([np.random.normal(size=100), np.random.normal(size=100)]).T
y = np.random.normal(size=100)
m = LinearRegression()
cv = TimeSeriesSplit(test_size=50)
scores = cross_validate(m, X, y, scoring=["neg_mean_squared_error"], cv=cv)

Model

import numpy as np
from mlutil.model import GAM

m = GAM(n_splines=5)
X = np.arange(20)[:, None]
y = np.arange(20) + np.random.normal(scale=0.1, size=20)
m.fit(X, y)
X_test = np.arange(15, 25)[:, None]
y_test = np.arange(15, 25)
y_hat = m.predict(X_test)
np.testing.assert_allclose(y_test, y_hat, atol=1.0)
m.summary()

Transform

import numpy as np
import pandas as pd
from mlutil.transform import ColumnSelector, SigmaClipper

X = pd.DataFrame({
    "a": [np.nan, -1.0, 2.0, 1.0, 1.0, 302.0],
    "b": [-2.0, 1.0, 3.0, 2.0, -201, np.nan],
})
t = ColumnSelector(SigmaClipper(low_sigma=3, high_sigma=3))
X_new_ = t.fit_transform(X)

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

mlutil-0.1.15.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

mlutil-0.1.15-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file mlutil-0.1.15.tar.gz.

File metadata

  • Download URL: mlutil-0.1.15.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.14

File hashes

Hashes for mlutil-0.1.15.tar.gz
Algorithm Hash digest
SHA256 9bbf7168adb963e6dea2aad4b828883224e15e41f5bcbd9c3b21c795dc19b193
MD5 3c03850a56f59bbe52b672448bb823f5
BLAKE2b-256 9e6d4bd4b7ece6778bba7401f53df1443763eb6af9b3dda12e30053e8defdd0b

See more details on using hashes here.

File details

Details for the file mlutil-0.1.15-py3-none-any.whl.

File metadata

  • Download URL: mlutil-0.1.15-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.14

File hashes

Hashes for mlutil-0.1.15-py3-none-any.whl
Algorithm Hash digest
SHA256 45b800f0f8a6690faf9d7a8476a5121a18eccffbbce997bfa122f0566bd380fe
MD5 42310d85089584ec233b585c4deb4c86
BLAKE2b-256 e7da2c7cb35fe465db69e9d8d7d174a3f20c7cc54dcf853853fab6d1a515effe

See more details on using hashes here.

Supported by

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