Skip to main content

mlfast

This Python machine learning package is built on top of scikit-learn and provides a simple API for regression and classification modeling. The main function in this package is called Regression() and Classification() which takes in the following arguments:

X: The independent variables (features) of the data set

y: The dependent variable (target) of the data set

model: The name of the regression and classification algorithm to be used (e.g. lr for Linear Regression, or rf for Random Forest Classifier, etc.)

scaler: The name of the data scaler to be used (e.g. "standard" for StandardScaler, "robust" for RobustScaler, etc.)

cat: A boolean indicating [True or False] whether the data set has categorical variables that need to be one-hot encoded

  • PYPI link for this package - mlfast

Getting Started

Installations

note "Installation steps"

First let's do an easy pip installation of the library by running the following command -

pip install mlfast

Usage

Regression Algorithms

!!! note "For Regression Modeling" Import Regression Model -

from mlfast import Regression

Linear Regression -> 'lr'

Regression(X, y, model = 'lr')

Ridge Regression -> 'ridge '

Regression(X, y, model = 'ridge', scaler =  'standard')

Lasso Regression -> 'lasso'

Regression(X, y, model = 'lasso', scaler =  'robust')

ElasticNet -> 'enet'

Regression(X, y, model = 'enet', cat=True)

Random Forest Regressor -> 'rf'

Regression(X, y, model = 'rf',scaler = 'standard', cat=True)

Decision Tree Regressor -> 'dt'

Regression(X, y, model = 'dt')

Support Vector Machine Regression -> 'svm '

Regression(X, y, model = 'svm', scaler =  'standard')

KNeighbors Regressor -> 'knn'

Regression(X, y, model = 'knn', scaler =  'robust')

Gradient Boosting Regressor -> 'gb'

Regression(X, y, model = 'gb', cat=True)

AdaBoost Regressor -> 'ada'

Regression(X, y, model = 'ada',scaler = 'standard', cat=True)

XGBoost Regressor -> 'xgb'

Regression(X, y, model = 'xgb',scaler = 'standard', cat=True)

Classification Algorithms

note "For Classification Modeling" Import Classification Model -

from mlfast import Classification

Logistic Regression -> 'lr'

Classification(X, y, model = 'lr')

Random Forest Classifier -> 'rf'

Classification(X, y, model = 'rf',scaler = 'standard', cat=True)

Decision Tree Classifier -> 'dt'

Classification(X, y, model = 'dt')

Support Vector Machine Classifier -> 'svm '

Classification(X, y, model = 'svm', scaler =  'standard')

KNeighbors Classifier -> 'knn'

Classification(X, y, model = 'knn', scaler =  'robust')

Gradient Boosting Classifier -> 'gb'

Classification(X, y, model = 'gb', cat=True)

AdaBoost Classifier -> 'ada'

Classification(X, y, model = 'ada',scaler = 'standard', cat=True)

XGBoost Classifier -> 'xgb'

Classification(X, y, model = 'xgb',scaler = 'standard', cat=True)

Regression hyperparameter

note "For Regression Hyperparameter Modeling" Import Regression Hyperparameter Model -

from mlfast.Hyperparameter.Regression import Regression

Ridge regression

hyperparams_ridge = {
    "alpha": [0.01, 0.1, 1.0, 10.0],
    "fit_intercept": [True, False],
    "solver": ["auto", "svd", "cholesky", "lsqr", "sparse_cg", "sag", "saga"],
}

Regression(X, y, model="ridge", scaler="standard", hyperparams=hyperparams_ridge)

Lasso Regression

hyperparams_lasso = {
    "alpha": [0.01, 0.1, 1.0, 10.0],
}
Regression(X, y, model="lasso", scaler="standard", hyperparams=hyperparams_lasso, save_pkl=False)

ElasticNet Regression

hyperparams_enet = {
    "alpha": [0.01, 0.1, 1.0, 10.0],
    "l1_ratio": [0.25, 0.5, 0.75],
}
Regression(X, y, model="enet", scaler="standard", hyperparams=hyperparams_enet, save_pkl=False)

Decision Tree Regression

hyperparams_dt = {
    "max_depth": [None, 5, 10, 20],
    "min_samples_split": [2, 5, 10],
}
Regression(X, y, model="dt", scaler="standard",  hyperparams=hyperparams_dt, save_pkl=False)

Random Forest Regression

hyperparams_rf = {
    "n_estimators": [5, 10, 20],
    "max_depth": [None, 5, 10, 20],
    "min_samples_split": [2, 5, 10],
}
Regression(X, y, model="rf", scaler="standard",  hyperparams=hyperparams_rf, save_pkl=False)

Support Vector Regression (SVR)

hyperparams_svm = {
    "C": [0.1, 1.0, 10.0],
    "kernel": ["linear", "rbf", "poly"],
}
Regression(X, y, model="svm", scaler="standard",  hyperparams=hyperparams_svm, save_pkl=False)

K-Nearest Neighbors Regression (KNN)

hyperparams_knn = {
    "n_neighbors": [2, 3, 5],
    "weights": ["uniform", "distance"],
}
Regression(X, y, model="knn", scaler="standard",  hyperparams=hyperparams_knn, save_pkl=False)

Gradient Boosting Regression

hyperparams_gb = {
    "n_estimators": [5, 10, 20],
    "learning_rate": [0.01, 0.1, 0.2],
}
Regression(X, y, model="gb", scaler="standard", hyperparams=hyperparams_gb, save_pkl=False)

AdaBoost Regression

hyperparams_ada = {
    "n_estimators": [5, 10, 20],
    "learning_rate": [0.01, 0.1, 0.2],
}
Regression(X, y, model="ada", scaler="standard",  hyperparams=hyperparams_ada, save_pkl=False)

XGBoost Regression

hyperparams_xgb = {
    "n_estimators": [5, 10, 20],
    "learning_rate": [0.01, 0.1, 0.2],
}
Regression(X, y, model="xgb", scaler="standard",  hyperparams=hyperparams_xgb, save_pkl=False)

Classification Hyperparameter

from mlfast.Hyperparameter.Classification import Classification

Logistic Regression

hyperparams_lr = {
    "C": [0.1, 1.0],
}
Classification(X, y, model="lr", scaler="robust", hyperparams=hyperparams_lr, save_pkl=True)

Decision Tree Classifier

hyperparams_dt = {
    "max_depth": [None, 5, 10, 20],
    "min_samples_split": [2, 5, 10],
}
Classification(X, y, model="dt", scaler="standard", hyperparams=hyperparams_dt)

Random Forest Classifier

rf_hyperparams = {
    "n_estimators": [100, 200, 300],
    "max_depth": [None, 10, 20, 30],
    "min_samples_split": [2, 5, 10],
    "min_samples_leaf": [1, 2, 4],
    "bootstrap": [True, False],
}

Classification(X, y, model="rf", scaler="standard", cat=True, hyperparams=rf_hyperparams, save_pkl=False)

Support Vector Classifier (SVC)

hyperparams_svm = {
    "C": [0.1, 1.0, 10.0],
    "kernel": ["linear", "rbf", "poly"],
}
Classification(X, y, model="svm", scaler="standard", hyperparams=hyperparams_svm)

K-Nearest Neighbors Classifier (KNN)

hyperparams_knn = {
    "n_neighbors": [3, 5, 10],
    "weights": ["uniform", "distance"],
}
Classification(X, y, model="knn", scaler="standard", hyperparams=hyperparams_knn)

Gradient Boosting Classifier

hyperparams_gb = {
    "n_estimators": [5, 10, 20],
    "learning_rate": [0.01, 0.1, 0.2],
}
Classification(X, y, model="gb", scaler="standard", hyperparams=hyperparams_gb)

AdaBoost Classifier

hyperparams_ada = {
    "n_estimators": [5, 10, 20],
    "learning_rate": [0.01, 0.1, 0.2],
}
Classification(X, y, model="ada", scaler="standard", cat=True, hyperparams=hyperparams_ada)

XGBoost Classifier

hyperparams_xgb = {
    "n_estimators": [5, 10, 20],
    "learning_rate": [0.01, 0.1, 0.2],
}
Classification(X, y, model="xgb", scaler="standard", hyperparams=hyperparams_xgb)

Text Preprocessing

The provided code snippet applies Text Preprocessing to a series or column of text data. It allows for flexible control over different preprocessing steps through boolean flags. Here is a summary of the options:

  • stem: Determines whether stemming should be performed. Set to True to enable stemming, or False to disable it.
  • lemmatize: Controls lemmatization. Set to True to enable lemmatization, or False to disable it.
  • remove_html: Specifies whether HTML tags should be removed. Use True to remove HTML tags, or False to keep them.
  • remove_emoji: Determines whether emojis should be removed from the text. Set to True to remove emojis, or False to retain them.
  • remove_special_chars: Controls the removal of special characters. Use True to remove special characters, or False to keep them.
  • remove_extra_spaces: Specifies whether extra spaces should be removed. Set to True to remove extra spaces, or False to keep them.

By setting these flags to either True or False, you can customize the preprocessing steps according to your requirements. The code applies the specified preprocessing steps to each text element in the series or column and returns the processed text.

Text preprocessing sample code

from mlfast import Text_preprocessing


df['review'].apply(Text_preprocessing,
                  stem=False,
                  lemmatize=True,
                  remove_html=True,
                  remove_emoji=True,
                  remove_special_chars=True,
                  remove_extra_spaces=True)

Chatbot

Import the Chatbot class: In your Python script, import the Chatbot class from mlfast. You can do this by adding the following line at the beginning of your code:

from mlfast import Chatbot
  • Obtain an OpenAI API key: To use the mlfast library, you'll need an API key from OpenAI. If you don't have one, sign up on the OpenAI website and obtain an API key.

  • Create a Chatbot instance: Initialize the Chatbot class with your OpenAI API key and specify the desired role for your chatbot. Here's an example of creating a Chatbot instance:

  • Replace "YOUR-OPENAI-API-KEY" with your actual OpenAI API key, and "ENTER-YOUR-CHATBOT-ROLE" with the desired role for your chatbot.

  • Deploy the chatbot: Set the deploy parameter to True when creating the Chatbot instance. This will deploy the chatbot and make it available for use.

  • To deploy or terminate the deployment of a chatbot created using the mlfast library, you can set the deploy parameter to True or False when creating the Chatbot instance, respectively.

Chatbot(api_key="YOUR-OPENAI-API-KEY",
        role="ENTER-YOUR-CHATBOT-ROLE",
        deploy=True)

Chatbot feature is depreciated will be added soon on different library

Announcement

  • Unsupervised Machine Learning Algorithms
  • Bag of words, TFIDF and Word2Vec
  • Image Preprocessing
  • And many more

ADDED SOON

Release files for mlfast 0.0.22

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mlfast 0.0.22
File Size Uploaded
mlfast-0.0.22.tar.gz 13.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mlfast 0.0.22
File Interpreter ABI Platform
mlfast-0.0.22-py3-none-any.whl Python 3 none any Details

Total release size: 27.5 kB

Release files / mlfast-0.0.22.tar.gz

Download URL mlfast-0.0.22.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
15d87e41c85596854de2a2f3bcca6e33d7c02557b4b815583bc8897c6232dbfd
BLAKE2b-256 checksum
How to use checksums
812a1ab2b323dac60af64f489c0a1eea07fd93de71345dde6cb8954f59db413f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / mlfast-0.0.22-py3-none-any.whl

Download URL mlfast-0.0.22-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
93e301c78d8baaf2b1eecf07130ca8ab262dede48ef84e1197eb80bb9b996198
BLAKE2b-256 checksum
How to use checksums
05b4d3884587a89efabdcc6cb8023be04b20ce470ec202206b133ee2ab2d30e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.0.22 This release

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page