Python binding of multi-core LIBLINEAR
liblinear-multicore provides a Python interface to the multi-core LIBLINEAR library, an OpenMP implementation designed to significantly reduce training time for large-scale linear classification, regression, and outlier detection on shared-memory systems. It is actively maintained with the current version 2.50.0 released in December 2025, offering speedups over the official LIBLINEAR in multi-core environments.
Warnings
- breaking The Python import path for high-level utilities changed after version 2.43. Using 'from liblinearutil import *' will fail in newer versions.
- gotcha Careless handling of model instances obtained through low-level C interfaces can lead to memory leaks or segmentation faults.
- gotcha Results from multi-core operations (i.e., when using the '-m' option) may be slightly different when run with a varying number of threads due to the nature of parallel computations.
- gotcha The `pip install .` or `python setup.py install` commands from the source directory can fail if not executed with specific instructions.
- gotcha If the optimization algorithm fails to converge (e.g., in scikit-learn's LogisticRegression with liblinear solver), you might encounter `ConvergenceWarning`.
Install
-
pip install liblinear-multicore -
pip install -U liblinear-multicore
Imports
- * (high-level utilities)
from liblinear.liblinearutil import *
- * (low-level C interfaces)
from liblinear.liblinear import *
Quickstart
from liblinear.liblinearutil import *
# Example data (LIBSVM format or Python list/dict/ndarray)
y = [1, -1, 1, -1]
x = [{1:1, 3:1}, {1:-1, 3:-1}, {1:1, 3:1}, {1:-1, 3:-1}]
# Create problem and parameter instances
# Use '-m nr_thread' option for multi-core training, e.g., '-m 4' for 4 threads
prob = problem(y, x)
param = parameter('-s 0 -c 4 -m 4') # -s 0: L2-regularized L2-loss SVM (dual), -c 4: cost parameter, -m 4: 4 threads
# Train the model
m = train(prob, param)
# Make predictions
p_labels, p_metrics, p_values = predict(y, x, m)
# Print results (example for classification)
ACC, MSE, SCC = evaluations(y, p_labels)
print(f"Accuracy = {ACC[0]:.2f}%")
# Save and load model
save_model('model_file', m)
loaded_m = load_model('model_file')