scikit-misc
scikit-misc is a Python library providing a collection of miscellaneous tools for data analysis and scientific computing. It includes algorithms that were once part of SciPy's `scipy.misc` module but were removed or deemed unstable, now offered in a more robust form. The library is currently at version 0.5.2 and maintains an active development and release cadence, requiring Python >=3.10.
Common errors
-
ModuleNotFoundError: No module named 'scikit-misc'
cause The `scikit-misc` package is either not installed or not installed in the Python environment currently in use.fixRun `pip install scikit-misc` or `conda install conda-forge::scikit-misc` in your active environment. Verify the environment is correctly activated. -
For loess smoothing, install 'scikit-misc'
cause This error typically occurs when another library (e.g., `plotnine` or `scanpy`) tries to use `skmisc.loess` but cannot find the installed `scikit-misc` package in the execution environment.fixConfirm `scikit-misc` is installed in the *same* Python environment where the calling library is installed and being executed. Reinstalling `scikit-misc` with `pip install --user scikit-misc --force` or ensuring the correct `PYTHONPATH` can sometimes resolve this. -
ERROR: Command `/usr/bin/python3 -c 'import os os.chdir(os.path.join("..", "tools")) import numpy as np try: incdir = os.path.relpath(np.get_include()) except Exception: incdir = np.get_include() print(incdir) '` failed with status 1.cause This is a build-time error, often related to `meson-python` failing to find `numpy` headers during compilation, particularly with newer Python versions (e.g., 3.13) where build dependencies might not be automatically linked.fixThis issue has been addressed in recent `scikit-misc` commits. Ensure you are using the latest version of `scikit-misc`. If building from source, ensure `numpy` is correctly installed in your build environment. Prefer installing pre-built wheels if available.
Warnings
- gotcha Users often encounter 'ModuleNotFoundError' even after installation, particularly in complex environments like Anaconda or when using different Python interpreters.
- breaking Older SciPy users might recall algorithms (e.g., `scipy.misc.face`, `scipy.misc.ascent`) that were deprecated or removed from `scipy.misc`. `scikit-misc` aims to re-introduce some of these or similar functionalities, but direct `scipy.misc` imports will no longer work and require migrating to `scikit-misc` or other SciPy submodules.
- gotcha Building `scikit-misc` from source, especially on less common platforms or with pre-release Python versions (e.g., Python 3.13, or sometimes on Windows), can lead to compilation errors due to dependencies on Fortran/C/Cython code and build system interactions with `numpy`.
Install
-
pip install scikit-misc -
conda install conda-forge::scikit-misc
Imports
- loess
from skmisc.loess import loess
Quickstart
import numpy as np
from skmisc.loess import loess
# Generate some sample data
x = np.linspace(0, 10, 100)
y = np.sin(x) + np.random.normal(0, 0.5, 100)
# Fit a LOESS model
model = loess(x, y)
model.fit()
# Get smoothed predictions and statistics
pred = model.predict(x).values
print(f"First 5 original y values: {y[:5]}")
print(f"First 5 smoothed y values: {pred[:5]}")