betterfit


Namebetterfit JSON
Version 0.0.2a3 PyPI version JSON
download
home_pagehttps://github.com/leftgoes/betterfit
SummaryRegression of data with error propagation
upload_time2024-11-27 03:33:23
maintainerNone
docs_urlNone
authorHa Jong Kim
requires_python>=3.12
licenseMIT
keywords regression data
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Betterfit
## Installation
`pip install betterfit`

## Getting Started
Refer to [getting_started.py](tests/getting_started.py):
```python
# getting_started.py
import matplotlib.pyplot as plt
import sympy as smp
from uncertainties import ufloat

from betterfit import Dataset, LinearFit

# create immutable datasets
resistance_data = Dataset.fromiter(symbol='R',
                                   values=[2000, 1800, 1600, 1400, 1200, 1000, 900],
                                   errors=10)
length_data = Dataset.fromiter(symbol=smp.Symbol('l'),
                               values=[160, 172, 192, 223, 254, 298, 327],
                               errors=[1.5, 2.4, 2, 2.3, 2.1, 3, 5])
length_data = length_data.multiply(1e-3)

# define quantities as sympy symbols
R, l, d = smp.symbols('R l d')

# define an expression depending on these symbols
phi = smp.atan(l / d)

# perform linear fit
linearfit = LinearFit()
linearfit.add_constant(symbol=d,
                       value=ufloat(0.535, 0.01))
linearfit.add_datasets(resistance_data, length_data)
slope, yintercept = linearfit.fit(x_expr=1 / phi,
                                  y_expr=R)

# linearfit.fit return sympy symbols representing the slope and yintercept
# the values can be accessed through linearfit[slope] and linearfit[yintercept]
print(f'slope: {linearfit[slope]:.3g}')
print(f'yintercept: {linearfit[yintercept]:.3g}')

# similarily, values of expressions can be accessed through linearfit[expr]
print(f'phi: {linearfit[phi]}')

# plot setup
fig, ax = plt.subplots()
ax.set_title('Example Linear Fit with Weighted Least Squares')
ax.set_xlabel(r'$\frac{1}{\phi}$ [$s$]')
ax.set_ylabel(r'$R$ [$\Omega$]')

# plot fit
linearfit.plot_on(ax,
                  x=1 / phi,
                  y=R,
                  fmt='o',
                  label='data')
linearfit.plot_fit_on(ax)

ax.legend()

plt.show()
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/leftgoes/betterfit",
    "name": "betterfit",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "regression, data",
    "author": "Ha Jong Kim",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/a8/2f/f382daca2d37e86c78672cc66310c1dfaa29752a9dd36a3914d461ac0b71/betterfit-0.0.2a3.tar.gz",
    "platform": null,
    "description": "# Betterfit\n## Installation\n`pip install betterfit`\n\n## Getting Started\nRefer to [getting_started.py](tests/getting_started.py):\n```python\n# getting_started.py\nimport matplotlib.pyplot as plt\nimport sympy as smp\nfrom uncertainties import ufloat\n\nfrom betterfit import Dataset, LinearFit\n\n# create immutable datasets\nresistance_data = Dataset.fromiter(symbol='R',\n                                   values=[2000, 1800, 1600, 1400, 1200, 1000, 900],\n                                   errors=10)\nlength_data = Dataset.fromiter(symbol=smp.Symbol('l'),\n                               values=[160, 172, 192, 223, 254, 298, 327],\n                               errors=[1.5, 2.4, 2, 2.3, 2.1, 3, 5])\nlength_data = length_data.multiply(1e-3)\n\n# define quantities as sympy symbols\nR, l, d = smp.symbols('R l d')\n\n# define an expression depending on these symbols\nphi = smp.atan(l / d)\n\n# perform linear fit\nlinearfit = LinearFit()\nlinearfit.add_constant(symbol=d,\n                       value=ufloat(0.535, 0.01))\nlinearfit.add_datasets(resistance_data, length_data)\nslope, yintercept = linearfit.fit(x_expr=1 / phi,\n                                  y_expr=R)\n\n# linearfit.fit return sympy symbols representing the slope and yintercept\n# the values can be accessed through linearfit[slope] and linearfit[yintercept]\nprint(f'slope: {linearfit[slope]:.3g}')\nprint(f'yintercept: {linearfit[yintercept]:.3g}')\n\n# similarily, values of expressions can be accessed through linearfit[expr]\nprint(f'phi: {linearfit[phi]}')\n\n# plot setup\nfig, ax = plt.subplots()\nax.set_title('Example Linear Fit with Weighted Least Squares')\nax.set_xlabel(r'$\\frac{1}{\\phi}$ [$s$]')\nax.set_ylabel(r'$R$ [$\\Omega$]')\n\n# plot fit\nlinearfit.plot_on(ax,\n                  x=1 / phi,\n                  y=R,\n                  fmt='o',\n                  label='data')\nlinearfit.plot_fit_on(ax)\n\nax.legend()\n\nplt.show()\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Regression of data with error propagation",
    "version": "0.0.2a3",
    "project_urls": {
        "Homepage": "https://github.com/leftgoes/betterfit",
        "Repository": "https://github.com/leftgoes/betterfit"
    },
    "split_keywords": [
        "regression",
        " data"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8b5e7eba40013ae729f464efc3fdc7096a7b8c8d400bffefe7e772a415b23366",
                "md5": "5ee48a2f36da5b0a6d5cc7a5e20d1d4c",
                "sha256": "bd42d7ec10f039811f8c0552004097836917b516af4e0087b2571a89c3bfd6ae"
            },
            "downloads": -1,
            "filename": "betterfit-0.0.2a3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5ee48a2f36da5b0a6d5cc7a5e20d1d4c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 6703,
            "upload_time": "2024-11-27T03:33:21",
            "upload_time_iso_8601": "2024-11-27T03:33:21.717777Z",
            "url": "https://files.pythonhosted.org/packages/8b/5e/7eba40013ae729f464efc3fdc7096a7b8c8d400bffefe7e772a415b23366/betterfit-0.0.2a3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a82ff382daca2d37e86c78672cc66310c1dfaa29752a9dd36a3914d461ac0b71",
                "md5": "a90a613fc98d5a9043b057d15debdc2c",
                "sha256": "46adc75ba94aeac0fe5dd34ec9b1d713e81dd49e1bffaee93efbddd62a99c888"
            },
            "downloads": -1,
            "filename": "betterfit-0.0.2a3.tar.gz",
            "has_sig": false,
            "md5_digest": "a90a613fc98d5a9043b057d15debdc2c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 5029,
            "upload_time": "2024-11-27T03:33:23",
            "upload_time_iso_8601": "2024-11-27T03:33:23.474890Z",
            "url": "https://files.pythonhosted.org/packages/a8/2f/f382daca2d37e86c78672cc66310c1dfaa29752a9dd36a3914d461ac0b71/betterfit-0.0.2a3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-27 03:33:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "leftgoes",
    "github_project": "betterfit",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "betterfit"
}
        
Elapsed time: 0.35807s