Intel Extension for Scikit-learn providing hardware-accelerated implementations of scikit-learn algorithms optimized for Intel CPUs and GPUs.
—
Utility functions for converting external gradient boosting models (XGBoost, LightGBM, CatBoost) into Intel oneDAL format for accelerated inference. This API enables users to leverage Intel hardware optimizations on models trained with other frameworks.
from daal4py.mb import GBTDAALBaseModel, convert_modelConvert external gradient boosting models to Intel oneDAL format for accelerated inference.
def convert_model(model):
"""
Convert external gradient boosting model to Intel oneDAL format.
Automatically detects model type and converts to appropriate oneDAL model
for accelerated inference with Intel optimizations.
Parameters:
model: External model instance (XGBoost, LightGBM, or CatBoost)
Supported types:
- xgboost.sklearn.XGBClassifier/XGBRegressor
- xgboost.core.Booster
- lightgbm.sklearn.LGBMClassifier/LGBMRegressor
- lightgbm.basic.Booster
- catboost.core.CatBoostClassifier/CatBoostRegressor
- catboost.core.CatBoost
Returns:
Converted oneDAL model with Intel acceleration for inference
Raises:
TypeError: If model type is not supported
Example:
import xgboost as xgb
from daal4py.mb import convert_model
# Train XGBoost model
xgb_model = xgb.XGBClassifier(n_estimators=100)
xgb_model.fit(X_train, y_train)
# Convert to Intel oneDAL format
daal_model = convert_model(xgb_model)
# Use accelerated inference
predictions = daal_model.predict(X_test)
"""
class GBTDAALBaseModel:
"""
Base class for gradient boosting tree models converted to Intel oneDAL format.
Provides common functionality for converted GBT models including parameter
extraction, model conversion, and accelerated inference methods.
Attributes:
model_type: Type of original model ('xgboost', 'lightgbm', 'catboost', or None)
n_classes_: Number of classes for classification models
n_features_in_: Number of input features
daal_model_: Internal oneDAL model object
"""
def __init__(self):
"""Initialize base model converter."""import xgboost as xgb
from daal4py.mb import convert_model
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
# Generate sample data
X, y = make_classification(n_samples=1000, n_features=20, n_classes=2, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Train XGBoost classifier
xgb_model = xgb.XGBClassifier(
n_estimators=100,
max_depth=6,
learning_rate=0.1,
random_state=42
)
xgb_model.fit(X_train, y_train)
# Convert to Intel oneDAL format for accelerated inference
daal_model = convert_model(xgb_model)
# Use accelerated inference
predictions = daal_model.predict(X_test)
probabilities = daal_model.predict_proba(X_test) if hasattr(daal_model, 'predict_proba') else None
print(f"Converted model type: {daal_model.model_type}")
print(f"Number of features: {daal_model.n_features_in_}")
print(f"Number of classes: {daal_model.n_classes_}")import lightgbm as lgb
from daal4py.mb import convert_model
# Train LightGBM regressor
lgb_model = lgb.LGBMRegressor(
n_estimators=100,
learning_rate=0.1,
num_leaves=31,
random_state=42
)
lgb_model.fit(X_train, y_train)
# Convert to Intel oneDAL format
daal_model = convert_model(lgb_model)
# Accelerated inference
predictions = daal_model.predict(X_test)from catboost import CatBoostClassifier
from daal4py.mb import convert_model
# Train CatBoost classifier
cb_model = CatBoostClassifier(
iterations=100,
learning_rate=0.1,
depth=6,
verbose=False,
random_state=42
)
cb_model.fit(X_train, y_train)
# Convert to Intel oneDAL format
daal_model = convert_model(cb_model)
# Accelerated inference
predictions = daal_model.predict(X_test)xgboost.sklearn.XGBClassifier → GBTDAALClassifierxgboost.sklearn.XGBRegressor → GBTDAALRegressorxgboost.core.Booster → GBTDAALModellightgbm.sklearn.LGBMClassifier → GBTDAALClassifierlightgbm.sklearn.LGBMRegressor → GBTDAALRegressorlightgbm.basic.Booster → GBTDAALModelcatboost.core.CatBoostClassifier → GBTDAALClassifiercatboost.core.CatBoostRegressor → GBTDAALRegressorcatboost.core.CatBoost → GBTDAALModelInstall with Tessl CLI
npx tessl i tessl/pypi-scikit-learn-intelex