factrainer-base 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,173 @@
1
+ notebooks/
2
+
3
+ # pytest-profiling
4
+ prof/
5
+
6
+ # Byte-compiled / optimized / DLL files
7
+ __pycache__/
8
+ *.py[cod]
9
+ *$py.class
10
+
11
+ # C extensions
12
+ *.so
13
+
14
+ # Distribution / packaging
15
+ .Python
16
+ build/
17
+ develop-eggs/
18
+ dist/
19
+ downloads/
20
+ eggs/
21
+ .eggs/
22
+ lib/
23
+ lib64/
24
+ parts/
25
+ sdist/
26
+ var/
27
+ wheels/
28
+ share/python-wheels/
29
+ *.egg-info/
30
+ .installed.cfg
31
+ *.egg
32
+ MANIFEST
33
+
34
+ # PyInstaller
35
+ # Usually these files are written by a python script from a template
36
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
37
+ *.manifest
38
+ *.spec
39
+
40
+ # Installer logs
41
+ pip-log.txt
42
+ pip-delete-this-directory.txt
43
+
44
+ # Unit test / coverage reports
45
+ htmlcov/
46
+ .tox/
47
+ .nox/
48
+ .coverage
49
+ .coverage.*
50
+ .cache
51
+ nosetests.xml
52
+ coverage.xml
53
+ *.cover
54
+ *.py,cover
55
+ .hypothesis/
56
+ .pytest_cache/
57
+ cover/
58
+
59
+ # Translations
60
+ *.mo
61
+ *.pot
62
+
63
+ # Django stuff:
64
+ *.log
65
+ local_settings.py
66
+ db.sqlite3
67
+ db.sqlite3-journal
68
+
69
+ # Flask stuff:
70
+ instance/
71
+ .webassets-cache
72
+
73
+ # Scrapy stuff:
74
+ .scrapy
75
+
76
+ # Sphinx documentation
77
+ docs/_build/
78
+
79
+ # PyBuilder
80
+ .pybuilder/
81
+ target/
82
+
83
+ # Jupyter Notebook
84
+ .ipynb_checkpoints
85
+
86
+ # IPython
87
+ profile_default/
88
+ ipython_config.py
89
+
90
+ # pyenv
91
+ # For a library or package, you might want to ignore these files since the code is
92
+ # intended to run in multiple environments; otherwise, check them in:
93
+ # .python-version
94
+
95
+ # pipenv
96
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
97
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
98
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
99
+ # install all needed dependencies.
100
+ #Pipfile.lock
101
+
102
+ # UV
103
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
104
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
105
+ # commonly ignored for libraries.
106
+ #uv.lock
107
+
108
+ # poetry
109
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
110
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
111
+ # commonly ignored for libraries.
112
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
113
+ #poetry.lock
114
+
115
+ # pdm
116
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
117
+ #pdm.lock
118
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
119
+ # in version control.
120
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
121
+ .pdm.toml
122
+ .pdm-python
123
+ .pdm-build/
124
+
125
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
126
+ __pypackages__/
127
+
128
+ # Celery stuff
129
+ celerybeat-schedule
130
+ celerybeat.pid
131
+
132
+ # SageMath parsed files
133
+ *.sage.py
134
+
135
+ # Environments
136
+ .env
137
+ .venv
138
+ env/
139
+ venv/
140
+ ENV/
141
+ env.bak/
142
+ venv.bak/
143
+
144
+ # Spyder project settings
145
+ .spyderproject
146
+ .spyproject
147
+
148
+ # Rope project settings
149
+ .ropeproject
150
+
151
+ # mkdocs documentation
152
+ /site
153
+
154
+ # mypy
155
+ .mypy_cache/
156
+ .dmypy.json
157
+ dmypy.json
158
+
159
+ # Pyre type checker
160
+ .pyre/
161
+
162
+ # pytype static type analyzer
163
+ .pytype/
164
+
165
+ # Cython debug symbols
166
+ cython_debug/
167
+
168
+ # PyCharm
169
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
170
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
171
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
172
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
173
+ #.idea/
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.4
2
+ Name: factrainer-base
3
+ Version: 0.1.0
4
+ Summary: Add your description here
5
+ Author-email: ritsuki1227 <ritsuki1227@gmail.com>
6
+ Requires-Python: >=3.12
7
+ Requires-Dist: pydantic>=2.11.2
8
+ Requires-Dist: scikit-learn>=1.6.1
File without changes
@@ -0,0 +1,18 @@
1
+ [project]
2
+ name = "factrainer-base"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ authors = [{ name = "ritsuki1227", email = "ritsuki1227@gmail.com" }]
7
+ requires-python = ">=3.12"
8
+ dependencies = [
9
+ "pydantic>=2.11.2",
10
+ "scikit-learn>=1.6.1",
11
+ ]
12
+
13
+ [build-system]
14
+ requires = ["hatchling"]
15
+ build-backend = "hatchling.build"
16
+
17
+ [tool.hatch.build.targets.wheel]
18
+ packages = ["src/factrainer"]
File without changes
@@ -0,0 +1,52 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import Self
3
+
4
+ from pydantic import BaseModel, ConfigDict
5
+
6
+ from .dataset import BaseDataset, Prediction
7
+ from .raw_model import RawModel
8
+
9
+
10
+ class BaseTrainConfig(BaseModel):
11
+ model_config = ConfigDict(arbitrary_types_allowed=True)
12
+
13
+
14
+ class BasePredictConfig(BaseModel):
15
+ model_config = ConfigDict(arbitrary_types_allowed=True)
16
+
17
+
18
+ class BaseLearner[T: BaseDataset, U: RawModel, V: BaseTrainConfig](ABC):
19
+ @abstractmethod
20
+ def train(self, train_dataset: T, val_dataset: T | None, config: V) -> U:
21
+ raise NotImplementedError
22
+
23
+
24
+ class BasePredictor[T: BaseDataset, U: RawModel, W: BasePredictConfig](ABC):
25
+ @abstractmethod
26
+ def predict(self, dataset: T, raw_model: U, config: W | None) -> Prediction:
27
+ raise NotImplementedError
28
+
29
+
30
+ class BaseMlModelConfig[
31
+ T: BaseDataset,
32
+ U: RawModel,
33
+ V: BaseTrainConfig,
34
+ W: BasePredictConfig,
35
+ ](BaseModel):
36
+ learner: BaseLearner[T, U, V]
37
+ predictor: BasePredictor[T, U, W]
38
+ train_config: V
39
+ pred_config: W | None = None
40
+ model_config = ConfigDict(arbitrary_types_allowed=True)
41
+
42
+
43
+ class MlModelConfig[
44
+ T: BaseDataset,
45
+ U: RawModel,
46
+ V: BaseTrainConfig,
47
+ W: BasePredictConfig,
48
+ ](BaseMlModelConfig[T, U, V, W], ABC):
49
+ @classmethod
50
+ @abstractmethod
51
+ def create(cls, train_config: V, pred_config: W | None = None) -> Self:
52
+ raise NotImplementedError
@@ -0,0 +1,43 @@
1
+ from abc import ABC, abstractmethod
2
+ from collections.abc import Sequence
3
+ from typing import Any, Generator, Self
4
+
5
+ import numpy as np
6
+ import numpy.typing as npt
7
+ from pydantic import BaseModel, ConfigDict
8
+ from sklearn.model_selection._split import _BaseKFold
9
+
10
+ # type Prediction = npt.NDArray[Any] | scipy.sparse.spmatrix | list[scipy.sparse.spmatrix]
11
+ type Prediction = npt.NDArray[np.number[Any]]
12
+ type RowIndex = list[int]
13
+ type RowIndices = Sequence[RowIndex]
14
+ type Rows = int | slice | RowIndex
15
+ type RowsAndColumns = Rows | tuple[Rows, ...]
16
+
17
+
18
+ class BaseDataset(BaseModel):
19
+ model_config = ConfigDict(arbitrary_types_allowed=True)
20
+
21
+
22
+ class IndexableDataset(BaseDataset):
23
+ @abstractmethod
24
+ def __getitem__(self, index: RowsAndColumns) -> Self:
25
+ raise NotImplementedError
26
+
27
+ @abstractmethod
28
+ def get_index(
29
+ self, k_fold: _BaseKFold
30
+ ) -> Generator[tuple[RowIndex, RowIndex], None, None]:
31
+ raise NotImplementedError
32
+
33
+
34
+ class BaseDatasetEqualityChecker[T](ABC):
35
+ @abstractmethod
36
+ def check(self, left: T, right: T) -> bool:
37
+ raise NotImplementedError
38
+
39
+
40
+ class BaseDatasetSlicer[T](ABC):
41
+ @abstractmethod
42
+ def slice(self, data: T, index: RowIndex) -> T:
43
+ raise NotImplementedError
File without changes
@@ -0,0 +1,5 @@
1
+ from pydantic import BaseModel, ConfigDict
2
+
3
+
4
+ class RawModel(BaseModel):
5
+ model_config = ConfigDict(arbitrary_types_allowed=True)