{"id":5981,"library":"kafe2","title":"Karlsruhe Fit Environment 2 (kafe2)","description":"kafe2 (Karlsruhe Fit Environment 2) is an open-source Python package (current version 2.11.0) for likelihood-based parameter estimation and elementary data analysis. Primarily used for fitting models to measured data and visualizing results, it provides a user-friendly interface for state-of-the-art statistical methods, relying on established numerical and optimization libraries like NumPy and SciPy. The library aims to offer an easy-to-use and performance-optimized pipeline for data analysis, including parameter confidence intervals and publication-quality plots. It typically sees a few releases per year.","status":"active","version":"2.11.0","language":"en","source_language":"en","source_url":"https://github.com/PhiLFitters/kafe2","tags":["fitting","data-analysis","physics","statistics","maximum-likelihood","least-squares","plotting"],"install":[{"cmd":"pip install kafe2","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core for numerical operations.","package":"numpy","optional":false},{"reason":"For numerical differentiation, replaced scipy.misc.derivative.","package":"numdifftools","optional":false},{"reason":"Core for scientific computing, used for optimization.","package":"scipy","optional":false},{"reason":"For plotting and visualization of fit results.","package":"matplotlib","optional":false},{"reason":"For presenting tabular data, likely in reports.","package":"tabulate","optional":false},{"reason":"For handling YAML configuration files, particularly for the kafe2go CLI.","package":"pyyaml","optional":false},{"reason":"Optional but recommended minimizer backend for numerical optimization, alternative to SciPy's minimizers.","package":"iminuit","optional":true}],"imports":[{"note":"For simplified functional interface (e.g., kafe2.xy_fit, kafe2.plot).","symbol":"kafe2","correct":"import kafe2"},{"note":"For the object-oriented interface, import specific classes as needed.","symbol":"XYFit, Plot, XYContainer, ContoursProfiler","correct":"from kafe2 import XYFit, Plot, XYContainer, ContoursProfiler"}],"quickstart":{"code":"import kafe2\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n# 1. Define your data\nx_data = np.array([1.0, 2.0, 3.0, 4.0])\ny_data = np.array([2.3, 4.2, 7.5, 9.4])\n\n# 2. Perform a fit using the simplified functional interface\n# A 'line' model is used by default if not specified explicitly.\nfit_object = kafe2.xy_fit(\n    \"line\",\n    x_data,\n    y_data,\n    x_error=0.1, \n    y_error=[0.40, 0.45, 0.40, 0.25] # Point-wise y errors\n)\n\n# 3. Plot the results\nplot_object = kafe2.plot(fit_object, x_label=\"$t$ [s]\", y_label=\"$h$ [m]\")\nplt.show()","lang":"python","description":"This quickstart demonstrates a simple linear fit to x-y data with errors, using kafe2's simplified functional interface. It defines data, performs the fit, and then visualizes the results."},"warnings":[{"fix":"Update calls to wrapper functions to place the model function (or model name string) as the first argument, followed by data arguments. E.g., `kafe2.xy_fit(model_func, x_data, y_data)` instead of `kafe2.xy_fit(x_data, y_data, model_func)`.","message":"Argument order for all wrapper functions (e.g., `xy_fit`, `hist_fit`) changed in v2.8.0. The model function is now accepted as the first argument, followed by the data.","severity":"breaking","affected_versions":">=2.8.0"},{"fix":"Ensure your Python environment meets the current requirements. For v2.11.0, Python >=3.9 and <=3.13 are officially supported.","message":"Python version support has changed across minor releases. Python 3.6 was dropped in v2.8.1, and Python 3.8 was dropped in v2.11.0. Python 3.13 was added in v2.11.0.","severity":"breaking","affected_versions":">=2.8.1, >=2.11.0"},{"fix":"Install a C++ compiler (e.g., Build Tools for Visual Studio on Windows, build-essential on Debian/Ubuntu, or Xcode Command Line Tools on macOS) before installing `iminuit` or `kafe2` with `iminuit` dependencies.","message":"The optional `iminuit` minimizer, if used, requires a C++ compiler to be available on your system during installation. Installation may fail or default to SciPy's minimizers if not present.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review custom model function implementations, especially if you were manipulating their internal representation. Standard Python function definitions should work as expected.","message":"As of v2.11.0, the model function code consistently uses function signatures instead of bytecode. While this enables overriding `__signature__`, custom model functions that relied on specific bytecode introspection might behave differently.","severity":"gotcha","affected_versions":">=2.11.0"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z","problems":[]}