BeHappy
BeHappy is a small Python package that prints the source code of eight classic machine learning and statistics experiments with a single function call:
from BeHappy import code
code()
Calling code() prints the code of these eight experiments, in order, under
the headings Exp 1: to Exp 8::
| Exp | What it covers |
|---|---|
| 1 | NumPy arrays, linear algebra, clip / select / where, SciPy statistics and optimisation, statsmodels OLS, K-Means clustering |
| 2 | Simple linear regression on Boston Housing (RM → price) with scikit-learn and statsmodels |
| 3 | Multiple linear regression on Boston Housing (OpenML) with scikit-learn and statsmodels |
| 4 | Polynomial regression (degrees 1-3) on LSTAT, with a plot |
| 5 | Binary and multinomial logistic regression on Iris (scikit-learn and statsmodels) |
| 6 | Dow Jones Index: predicting next week's close price with linear regression, with a plot |
| 7 | One-vs-rest classification with linear regression on Iris |
| 8 | One-vs-rest classification with linear regression on KDD Cup 99 (10% sample) |
code() only prints the code. It does not run the experiments, download
anything or create any files. Nothing is printed when you import the package.
You can copy any printed experiment into a notebook cell or a .py file and
run it. The libraries it needs (numpy, pandas, scipy, scikit-learn,
statsmodels, matplotlib and requests) are installed together with BeHappy.
Experiments 2, 3, 4, 6 and 8 download public datasets when you run them, so
they need an internet connection.
Installation
pip install behappy
The project is called behappy on PyPI, and you import it as BeHappy.
pip treats the name case-insensitively, so pip install BeHappy works too.
To install from a local copy of the source:
pip install .
Usage
Python (script or terminal)
from BeHappy import code
code()
Save that as run.py and run python run.py. The code is printed in the terminal.
To save it to a file instead, run python run.py > experiments.txt.
Jupyter Notebook
In a cell:
%pip install behappy
Then, in a new cell:
from BeHappy import code
code()
The code is printed below the cell. If VS Code shows "Output is truncated", click "View as a scrollable element" (or "open in a text editor") to see all of it.
Google Colab
!pip install behappy
from BeHappy import code
code()
Colab may ask you to restart the runtime after installing (for example if numpy was upgraded). If it does, restart and run the second cell again.
Requirements
Python 3.9 or newer. These dependencies are installed automatically: numpy, pandas, scipy, scikit-learn, statsmodels, matplotlib and requests.
Development
pip install -e ".[dev]"
pytest
License
MIT. See LICENSE.
Metadata
Release files for behappy 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| behappy-0.1.1.tar.gz | 12.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| behappy-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.4 kB
Release files / behappy-0.1.1.tar.gz
| Download URL | behappy-0.1.1.tar.gz |
|---|---|
| Size | 12.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eefb2dab32679641eba8f48b2f1d754fc890047b4129bb3afa4b24e486c8b20a
|
|
BLAKE2b-256 checksum How to use checksums |
7934ba6682c2fe8c09866307cbc6d85bebb27fc6028d097bb4a1a5c0857b58d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.7
|
Release files / behappy-0.1.1-py3-none-any.whl
| Download URL | behappy-0.1.1-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b725729ff5bf3adb00d372dde17c2a0c5f67f46edc12f7cdffe04b040348b023
|
|
BLAKE2b-256 checksum How to use checksums |
dc2dbef1c67ec22e3a70b8d9451ec9a9ea6c1ae0e6a0dd247039cdaa43864c29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.7
|
Security for behappy 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.