Skip to content

Commit 3ba9af2

Browse files
rename + add pypi workflow
1 parent 41beb4c commit 3ba9af2

File tree

14 files changed

+358
-198
lines changed

14 files changed

+358
-198
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Publish Python 🐍 distribution 📦 to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
build:
12+
name: Build distribution 📦
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
persist-credentials: false
18+
fetch-depth: 0
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.x"
23+
- name: Install pypa/build
24+
run: >-
25+
python3 -m
26+
pip install
27+
build
28+
--user
29+
- name: Build a binary wheel and a source tarball
30+
run: python3 -m build
31+
- name: Store the distribution packages
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: python-package-distributions
35+
path: dist/
36+
publish-to-pypi:
37+
name: >-
38+
Publish Python 🐍 distribution 📦 to PyPI
39+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
40+
needs:
41+
- build
42+
runs-on: ubuntu-latest
43+
environment:
44+
name: pypi
45+
url: https://pypi.org/p/mcd-regression
46+
permissions:
47+
id-token: write # IMPORTANT: mandatory for trusted publishing
48+
steps:
49+
- name: Download all the dists
50+
uses: actions/download-artifact@v4
51+
with:
52+
name: python-package-distributions
53+
path: dist/
54+
- name: Publish distribution 📦 to PyPI
55+
uses: pypa/gh-action-pypi-publish@release/v1
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Publish Python 🐍 distribution 📦 to TestPyPI
2+
3+
on: push
4+
5+
permissions:
6+
contents: read
7+
8+
jobs:
9+
build:
10+
name: Build distribution 📦
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
persist-credentials: false
16+
fetch-depth: 0
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.x"
21+
- name: Install pypa/build
22+
run: >-
23+
python3 -m
24+
pip install
25+
build
26+
--user
27+
- name: Build a binary wheel and a source tarball
28+
run: python3 -m build
29+
- name: Store the distribution packages
30+
uses: actions/upload-artifact@v4
31+
with:
32+
name: python-package-distributions
33+
path: dist/
34+
publish-to-testpypi:
35+
name: Publish Python 🐍 distribution 📦 to TestPyPI
36+
needs:
37+
- build
38+
runs-on: ubuntu-latest
39+
40+
environment:
41+
name: testpypi
42+
url: https://test.pypi.org/p/mcd-regression
43+
44+
permissions:
45+
id-token: write # IMPORTANT: mandatory for trusted publishing
46+
47+
steps:
48+
- name: Download all the dists
49+
uses: actions/download-artifact@v4
50+
with:
51+
name: python-package-distributions
52+
path: dist/
53+
- name: Publish distribution 📦 to TestPyPI
54+
uses: pypa/gh-action-pypi-publish@release/v1
55+
with:
56+
repository-url: https://test.pypi.org/legacy/

README.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
# robust_linear_regression
1+
# mcd_regression
22

33
Python implementation of robust linear regression in the multiple regression and multivariate regression cases using the minimum covariance determinant (MCD).
44

5-
Usage ([examples/example.ipynb](examples/example.ipynb)):
5+
Usage ([https://github.com/stevenstetzler/mcd_regression/tree/main/docs/examples/example.ipynb](docs/examples/example.ipynb)):
66
```python
7-
>>> from robust_linear_regression import RobustLinearRegression
8-
>>> rlr = RobustLinearRegression()
7+
>>> from mcd_regression import MCDRegression
8+
>>> mcdr = MCDRegression()
99
>>> x = data[:, 0, None] # n x d_x, must be 2D
1010
>>> y = data[:, 1:] # n x d_y, must be 2D
11-
>>> rlr.fit(x, y)
12-
>>> residuals = y - rlr.predict(x)
13-
>>> slope = rlr.beta
14-
>>> intercept = rlr.alpha
11+
>>> mcdr.fit(x, y)
12+
>>> residuals = y - mcdr.predict(x)
13+
>>> slope = mcdr.beta
14+
>>> intercept = mcdr.alpha
1515
```
1616

1717
Installation:
18+
- Available via PyPI as `mcd-regression`
19+
```bash
20+
$ python -m pip install mcd-regression
21+
```
22+
1823
- Development
1924
```bash
20-
$ git clone https://github.com/stevenstetzler/robust_linear_regression.git
21-
$ python -m pip install -e robust_linear_regression
25+
$ git clone https://github.com/stevenstetzler/mcd_regression.git
26+
$ python -m pip install -e mcd_regression
2227
```
2328

2429
References:
File renamed without changes.

docs/examples/example.ipynb

Lines changed: 90 additions & 0 deletions
Large diffs are not rendered by default.

examples/example.py renamed to docs/examples/example.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
from robust_linear_regression import RobustLinearRegression
1+
from mcd_regression import MCDRegression
22
import numpy as np
3-
import pathlib
43
import os
54
import matplotlib.pyplot as plt
65

76
def main():
87
data = np.loadtxt(os.path.join(os.path.dirname(__file__), "data.txt"))
9-
rlr = RobustLinearRegression()
8+
mcdr = MCDRegression()
109
x = data[:, 0, None]
1110
y = data[:, 1:]
12-
rlr.fit(x, y)
11+
mcdr.fit(x, y)
1312
line_x = np.array([[-0.02], [0.20]])
14-
line_y = rlr.predict(line_x)
13+
line_y = mcdr.predict(line_x)
1514
fig, axd = plt.subplot_mosaic([['y1', 'd'], ['y2', 'd']], dpi=150)
1615
plt.sca(axd["y1"])
17-
plt.scatter(x[~rlr.outliers, 0], y[~rlr.outliers, 0], s=2, label="inliers")
18-
plt.scatter(x[rlr.outliers, 0], y[rlr.outliers, 0], s=2, label="outliers")
16+
plt.scatter(x[~mcdr.outliers, 0], y[~mcdr.outliers, 0], s=2, label="inliers")
17+
plt.scatter(x[mcdr.outliers, 0], y[mcdr.outliers, 0], s=2, label="outliers")
1918
plt.plot(line_x, line_y[:, 0], color="k", zorder=-1, label="line")
2019
plt.legend()
2120
plt.xlabel("x")
2221
plt.ylabel("y_1")
2322
plt.sca(axd["y2"])
24-
plt.scatter(x[~rlr.outliers, 0], y[~rlr.outliers, 1], s=2, label="inliers")
25-
plt.scatter(x[rlr.outliers, 0], y[rlr.outliers, 1], s=2, label="outliers")
23+
plt.scatter(x[~mcdr.outliers, 0], y[~mcdr.outliers, 1], s=2, label="inliers")
24+
plt.scatter(x[mcdr.outliers, 0], y[mcdr.outliers, 1], s=2, label="outliers")
2625
plt.plot(line_x, line_y[:, 1], color="k", zorder=-1, label="line")
2726
plt.xlabel("x")
2827
plt.ylabel("y_2")
2928
plt.legend()
3029
plt.sca(axd["d"])
31-
plt.scatter(rlr.d_x, rlr.d_r, s=2)
32-
plt.axvline(rlr.d_x_threshold, color="k")
33-
plt.axhline(rlr.d_r_threshold, color="k")
30+
plt.scatter(mcdr.d_x[~mcdr.outliers], mcdr.d_r[~mcdr.outliers], s=2)
31+
plt.scatter(mcdr.d_x[mcdr.outliers], mcdr.d_r[mcdr.outliers], s=2)
32+
plt.axvline(mcdr.outlier_x_threshold, color="k", ls='--')
33+
plt.axhline(mcdr.outlier_r_threshold, color="k", ls='--')
3434
plt.xlabel("d(x)")
3535
plt.ylabel("d(r)")
3636
fig.align_ylabels()

examples/example.ipynb

Lines changed: 0 additions & 92 deletions
This file was deleted.

pyproject.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[build-system]
2+
requires = ["setuptools>=80", "setuptools-scm>=8"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "mcd-regression"
7+
license = {file = "LICENSE"}
8+
readme = "README.md"
9+
authors = [
10+
{ name = "Steven Stetzler", email = "[email protected]" }
11+
]
12+
classifiers = [
13+
"Development Status :: 4 - Beta",
14+
"License :: OSI Approved :: MIT License",
15+
"Intended Audience :: Developers",
16+
"Intended Audience :: Science/Research",
17+
"Operating System :: OS Independent",
18+
"Programming Language :: Python",
19+
]
20+
dynamic = ["version"]
21+
requires-python = ">=3.9"
22+
dependencies = [
23+
"numpy",
24+
"scipy",
25+
"scikit-learn",
26+
]
27+
description = "Robust linear regression in the multiple regression and multivariate regression cases using the minimum covariance determinant (MCD)."
28+
29+
[project.urls]
30+
"Source Code" = "https://github.com/stevenstetzler/mcd_regression"
31+
32+
[tool.setuptools_scm]
33+
write_to = "src/mcd_regression/_version.py"
34+
version_scheme = "guess-next-dev"
35+
local_scheme = "no-local-version"
36+
37+
[project.optional-dependencies]
38+
dev = [
39+
"matplotlib" # Used for examples
40+
]

requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

robust_linear_regression/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)