Skip to main content

A package to facilitate your model training

Project description

easytrainer

Prepare your data and train your models easily.

Works with scikit-learn.

Installation

pip install easytrainer

Usage

Preparator


Data preparators integrate preparation methods. When instantiating the preparator, simply choose the order of execution for each method and fill in the parameters if needed.

from easytrainer.data.text import TextualPreparator

preparator = TextualPreparator(
    to_lower=1,
    drop_stopwords=2
)

easytrainer.data.text.TextualPreparator

Method Name Description Type
to_lower Order in which to apply lowercase transformation (Optional[int])
to_upper Order in which to apply uppercase transformation (Optional[int])
drop_stopwords Order in which to remove French stopwords (Optional[int])
drop_digits Order in which to remove digits (Optional[int])
lemmatize Order in which to apply lemmatization using spaCy (Optional[int])
drop_special_characters Order to remove special characters (punctuation etc.) (Optional[int])
drop_accents Order in which to remove accents from characters (Optional[int])
drop_words_less_than_N_letters Either the order (int), or a tuple (order, n_letters, isalpha_flag) indicating the order, minimum number of letters, and whether to filter only alphabetic words (Optional[Union[int, Tuple[int, int, bool]]])

Coming soon: easytrainer.data.numeric easytrainer.data.image easytrainer.data.video easytrainer.data.audio

Then call prepare() to preprocess your data:

data = [
    "J'adore cette musique, elle est magnifique.",
    "Je déteste ce film, il est ennuyeux."
]

results = preparator.prepare(data)
print(results["data"])
>>> ["j'adore musique, magnifique.", 'déteste film, ennuyeux.']

TextualPreparator.prepare()

Parameters Description Type
data Text data to preprocess. If a numpy array is provided, it will be converted to a Series (1D) or DataFrame (2D) (List[str] or pd.Series or pd.DataFrame or np.ndarray)
all If True and data is a DataFrame, apply transformations to all columns (converted to str). If False, apply only to object/string columns bool (default : False)
encoder_name_to_fit If specified, encode the processed data using this method ('tfidf', 'word2vec') (Optional[str])
custom_encoder_to_fit A user-provided encoder with a fit_transform() method (Optional[object])
custom_encoder_fit A user-provided fitted encoder with a transform() method (Optional[object])

Returns a dictionary:

  • If no encoder: a dict containing 'data' (the preprocessed data).
  • If encoder is specified: a dict containing 'data', 'encoded_data', and 'vectorizer'.

Models


Easily train and evaluate your models.

from sklearn.ensemble import RandomForestClassifier

from easytrainer.models.classifier import SklearnClassifierModel

SCM = SklearnClassifierModel(
    model=RandomForestClassifier(n_estimators=100, random_state=42),
)

# Training
SCM.fit(X_train, y_train, param_grid={'n_estimators': [50, 100]}, cv=3)

# Testing
report = SCM.test(X_test, y_test)
print(report)

# Validation
validation_results = SCM.validation(X_val, y_val, fallback_class=0)

# Prediction
predictions = SCM.predict(X_test, threshold=0.7, fallback_class=0)

easytrainer.models

Method Name Description Args Returns
fit Trains the model, with optional hyperparameter tuning using GridSearchCV. (X, y, param_grid=None, **kwargs) self.best_fit_model (fitted model)
test Evaluates the model on a test set, returning a classification report. (X, y) pd.DataFrame containing precision, recall, f1-score, support per class
evaluate Evaluates model performance across different probability thresholds, optionally using a fallback class if prediction confidence is too low. (X, y, fallback_class, validation_thresholds=None) pd.DataFrame with scores (accuracy, weighted/macro F1, per-threshold metrics)
predict Makes predictions, optionally applying a threshold and fallback class. (X, threshold=None, fallback_class=None) np.ndarray (predicted labels)
save Saves the fitted model to disk. (path) None
load Loads a previously saved model from disk. (path) SklearnClassifierModel instance with loaded model

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

easytrainer-0.1.4.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

easytrainer-0.1.4-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file easytrainer-0.1.4.tar.gz.

File metadata

  • Download URL: easytrainer-0.1.4.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.10.0 Windows/10

File hashes

Hashes for easytrainer-0.1.4.tar.gz
Algorithm Hash digest
SHA256 cd641beff9c6d3430f0bd9f0f11b2c8ed01f21089656eebe645c0e1afbf5bf81
MD5 4c4484cf8d80ffd373b98164f491741c
BLAKE2b-256 380c8cf108dc672df2efbfea027f50bf2b3bb228153749bb04e7652045271ebe

See more details on using hashes here.

File details

Details for the file easytrainer-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: easytrainer-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.10.0 Windows/10

File hashes

Hashes for easytrainer-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 461d3f9e4913b00cbb8ee4b6c24494798cfe56fc74e626dbc1590fd0449b0e8a
MD5 a178605a8ba7d7ff73e8d7520a5d9449
BLAKE2b-256 da860daee9ad25f347a7aa0ac4cfb339d8425f05c7b05c55b4fe6aef498ed4ad

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