Guide · Open source
How to use pykan: install, build a KAN and plot it
Updated · written with AI from the project's own documentation and checked against our catalogue data
pykan is the official code repository for the Kolmogorov-Arnold Network (KAN) papers. KANs place learnable activation functions on the edges between nodes, instead of fixed activation functions on the nodes as in standard MLPs. This guide shows you how to install pykan, build a small KAN, and use its plotting and pruning tools to inspect what the model learned.
Quick start
- 1Check Python and pip. Confirm you have Python 3.9.7 or higher and pip installed.
- 2Install pykan. Run pip install pykan, or install from GitHub with the git+https command in the README.
- 3Open the quickstart. Work through hellokan.ipynb from the repository to see a working example.
- 4Build a small KAN. Start with a small shape such as width=[5,1,1], grid=3, k=3 and train on small data.
- 5Call model.speed() for custom loops. If you write your own training loop and skip the symbolic branch, call model.speed() before training.
- 6Plot and prune. Use model.plot() to inspect the network, then model.prune() to remove neurons that are clearly useless.
What is pykan and what does it do?
pykan implements Kolmogorov-Arnold Networks, which the README describes as promising alternatives to Multi-Layer Perceptrons (MLPs). MLPs are based on the universal approximation theorem, while KANs are based on the Kolmogorov-Arnold representation theorem. The README says this design makes KANs sometimes much better than MLPs in both accuracy and interpretability.
Install pykan from PyPI or GitHub
The README lists Python 3.9.7 or higher and pip as prerequisites. You can install pykan from PyPI or directly from the GitHub repository.
- Install from PyPI with the package name pykan.
- Install from GitHub to get the repository version.
- For development, clone the repo and install it in editable mode from the project folder.
pip install pykan
pip install git+https://github.com/KindXiaoming/pykan.gitCheck the requirements before you install
The README includes a requirements list with pinned versions of packages such as torch, numpy, matplotlib, sympy and scikit_learn. You can install them from a requirements.txt file after activating your virtual environment. The README also offers a Conda option that creates an environment with Python 3.9.7.
- Python 3.9.7 or higher and pip.
- Packages listed in the README requirements, including torch, numpy, matplotlib, sympy, scikit_learn, pandas, seaborn, pyyaml and tqdm.
pip install -r requirements.txtBuild and train your first KAN
The README suggests starting with a simple setup: a small KAN shape, a small grid size, small data, and no regularization. For a task with 5 inputs and 1 output, it suggests trying KAN(width=[5,1,1], grid=3, k=3). If that fails, increase width first, then depth. For a first run, the README points to the hellokan.ipynb notebook, and more examples are in the tutorials folder.
- Start with a small width, grid and data size.
- If it underfits, increase width first, then depth.
- Use the hellokan.ipynb notebook as a quickstart.
KAN(width=[5,1,1], grid=3, k=3)Speed up training with model.speed()
The README's efficiency note applies if you write your own training loop instead of using model.fit(), and you never use the symbolic branch. In that case, call model.speed() before training. Otherwise the symbolic branch stays on, and the README says it is very slow because its symbolic computations are not parallelized.
model.speed()Inspect, sparsify and prune the model
To make a KAN easier to interpret, the README suggests sparsifying training with a regularization weight such as lamb, and increasing it gradually. After training, plot the model with model.plot(). If some neurons are clearly useless, call model.prune() to get a pruned model, which you can train further or use for symbolic regression.
- Sparsify with model.train(lamb=0.01) and increase lamb gradually.
- Inspect the network with model.plot().
- Remove unneeded neurons with model.prune().
model.train(lamb=0.01)
pruned_model = model.prune()Watch for overfitting and tune carefully
The README notes that many intuitions from MLPs may not transfer to KANs. It says grid matters more than width for overfitting: if there is a large gap between train and test loss, first try decreasing grid, then width. For accuracy, it suggests trying grid extension, and it links an example in the documentation.
- Compare train and test losses to check for underfitting or overfitting.
- If the gap is large, reduce grid before width.
- Once you get a good result, try more data for a final run.
What people use it for
- Researchers comparing KANs with MLPs on small, science-oriented problems.
- Inspecting a learned model with model.plot() to see how inputs map to outputs.
- Students learning how KANs differ from standard neural networks.
- Following the KAN 2.0 paper and its scientific-discovery workflow.
- Running the tutorials on a single CPU, as the README describes.
Frequently asked questions
How do I install pykan?
Run pip install pykan to install from PyPI, or pip install git+https://github.com/KindXiaoming/pykan.git to install from GitHub. The README lists Python 3.9.7 or higher and pip as prerequisites.
What Python version does pykan need?
The README says Python 3.9.7 or higher. It also lists pinned package versions in its requirements, including torch 2.2.2 and numpy 1.24.4.
Is pykan free to use?
pykan is released under the MIT licence, as shown on its repository page. Check the LICENSE file in the repository for the full terms.
Is pykan better than an MLP?
The README says KANs are sometimes much better than MLPs in accuracy and interpretability, but it also says results vary. It recommends trying simple setups and comparing against your own baseline.
Why is pykan slow when I train it?
If you write your own training loop and never use the symbolic branch, the README says the symbolic branch is on by default and is very slow. Call model.speed() before training to turn it off.
What are alternatives to pykan?
The README names efficient-kan and FourierKAN as implementations that may be more efficient. It also mentions GraphKAN for graph-related work.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
pykan suits researchers, students and scientists who want to try KANs on small, science-oriented problems and inspect the learned model with plotting and pruning. If you need large-scale machine learning training or heavily optimized code, the README itself points you to efficient-kan or FourierKAN instead.
Install options & downloads