FLAML: A Fast Library for Automated Machine Learning and Tuning

2.5.0 · active · verified Tue Apr 14

FLAML (Fast Library for Automated Machine Learning) is an open-source Python library developed by Microsoft for efficient automation of machine learning and AI operations. It streamlines tasks such as model selection and hyperparameter optimization, and supports a wide range of models including classical machine learning algorithms, deep neural networks, and large language models. Currently at version 2.5.0, FLAML maintains an active development cycle, regularly releasing updates that include expanded Python version compatibility (e.g., Python 3.13 support), performance enhancements, and comprehensive documentation improvements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to perform a basic classification task using FLAML's AutoML functionality. It loads the Iris dataset, splits it into training and testing sets, initializes an `AutoML` instance, and trains a model within a specified time budget. The best model and its performance metric are then printed, followed by sample predictions.

from flaml import AutoML
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

# Load a sample dataset
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Initialize AutoML
automl = AutoML()

# Define settings for AutoML
automl_settings = {
    "time_budget": 10,  # in seconds
    "metric": "accuracy",
    "task": "classification",
    "log_file_name": "flaml_iris.log", # Optional: logs will be saved here
}

# Train the AutoML model
print("Starting AutoML training...")
automl.fit(X_train=X_train, y_train=y_train, **automl_settings)
print("AutoML training finished.")

# Best model details
print(f"Best estimator: {automl.model.estimator}")
print(f"Best metric: {automl.best_result['accuracy']}")

# Make predictions
predictions = automl.predict(X_test)
print(f"Sample predictions: {predictions[:5]}")

view raw JSON →