lecrapaud 0.4.0__py3-none-any.whl
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.
Potentially problematic release.
This version of lecrapaud might be problematic. Click here for more details.
- lecrapaud/__init__.py +0 -0
- lecrapaud/config.py +16 -0
- lecrapaud/db/__init__.py +0 -0
- lecrapaud/db/alembic/README +1 -0
- lecrapaud/db/alembic/env.py +78 -0
- lecrapaud/db/alembic/script.py.mako +26 -0
- lecrapaud/db/alembic/versions/2025_04_06_1738-7390745388e4_initial_setup.py +295 -0
- lecrapaud/db/alembic/versions/2025_04_06_1755-40cd8d3e798e_unique_constraint_for_data.py +30 -0
- lecrapaud/db/alembic/versions/2025_05_23_1724-2360941fa0bd_longer_string.py +52 -0
- lecrapaud/db/alembic/versions/2025_05_27_1159-b96396dcfaff_add_env_to_trading_tables.py +34 -0
- lecrapaud/db/alembic/versions/2025_05_27_1337-40cbfc215f7c_fix_nb_character_on_portfolio.py +39 -0
- lecrapaud/db/alembic/versions/2025_05_27_1526-3de994115317_to_datetime.py +36 -0
- lecrapaud/db/alembic/versions/2025_05_27_2003-25c227c684f8_add_fees_to_transactions.py +30 -0
- lecrapaud/db/alembic/versions/2025_05_27_2047-6b6f2d38e9bc_double_instead_of_float.py +132 -0
- lecrapaud/db/alembic/versions/2025_05_31_1111-c175e4a36d68_generalise_stock_to_group.py +36 -0
- lecrapaud/db/alembic/versions/2025_05_31_1256-5681095bfc27_create_investment_run_and_portfolio_.py +62 -0
- lecrapaud/db/alembic/versions/2025_05_31_1806-339927587383_add_investment_run_id.py +107 -0
- lecrapaud/db/alembic/versions/2025_05_31_1834-52b809a34371_make_nullablee.py +38 -0
- lecrapaud/db/alembic/versions/2025_05_31_1849-3b8550297e8e_change_date_to_datetime.py +44 -0
- lecrapaud/db/alembic/versions/2025_05_31_1852-e6b8c95d8243_add_date_to_portfolio_history.py +30 -0
- lecrapaud/db/alembic/versions/2025_06_10_1136-db8cdd83563a_addnewsandoptiontodata.py +32 -0
- lecrapaud/db/crud.py +179 -0
- lecrapaud/db/models/__init__.py +11 -0
- lecrapaud/db/models/base.py +6 -0
- lecrapaud/db/models/dataset.py +124 -0
- lecrapaud/db/models/feature.py +46 -0
- lecrapaud/db/models/feature_selection.py +126 -0
- lecrapaud/db/models/feature_selection_rank.py +80 -0
- lecrapaud/db/models/model.py +41 -0
- lecrapaud/db/models/model_selection.py +56 -0
- lecrapaud/db/models/model_training.py +54 -0
- lecrapaud/db/models/score.py +62 -0
- lecrapaud/db/models/target.py +59 -0
- lecrapaud/db/services.py +0 -0
- lecrapaud/db/setup.py +58 -0
- lecrapaud/directory_management.py +28 -0
- lecrapaud/feature_engineering.py +1119 -0
- lecrapaud/feature_selection.py +1229 -0
- lecrapaud/jobs/__init__.py +13 -0
- lecrapaud/jobs/config.py +17 -0
- lecrapaud/jobs/scheduler.py +36 -0
- lecrapaud/jobs/tasks.py +57 -0
- lecrapaud/model_selection.py +1571 -0
- lecrapaud/predictions.py +292 -0
- lecrapaud/search_space.py +844 -0
- lecrapaud/services/__init__.py +0 -0
- lecrapaud/services/embedding_categorical.py +71 -0
- lecrapaud/services/indicators.py +309 -0
- lecrapaud/speed_tests/experiments.py +139 -0
- lecrapaud/speed_tests/test-gpu-bilstm.ipynb +261 -0
- lecrapaud/speed_tests/test-gpu-resnet.ipynb +166 -0
- lecrapaud/speed_tests/test-gpu-transformers.ipynb +254 -0
- lecrapaud/speed_tests/tests.ipynb +145 -0
- lecrapaud/speed_tests/trash.py +37 -0
- lecrapaud/training.py +151 -0
- lecrapaud/utils.py +246 -0
- lecrapaud-0.4.0.dist-info/LICENSE +201 -0
- lecrapaud-0.4.0.dist-info/METADATA +103 -0
- lecrapaud-0.4.0.dist-info/RECORD +60 -0
- lecrapaud-0.4.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
from sqlalchemy import (
|
|
2
|
+
Column,
|
|
3
|
+
Integer,
|
|
4
|
+
String,
|
|
5
|
+
DateTime,
|
|
6
|
+
Date,
|
|
7
|
+
Float,
|
|
8
|
+
JSON,
|
|
9
|
+
Table,
|
|
10
|
+
ForeignKey,
|
|
11
|
+
BigInteger,
|
|
12
|
+
Index,
|
|
13
|
+
TIMESTAMP,
|
|
14
|
+
UniqueConstraint,
|
|
15
|
+
)
|
|
16
|
+
from sqlalchemy import desc, asc, cast, text, func
|
|
17
|
+
from sqlalchemy.orm import relationship, Mapped, mapped_column, DeclarativeBase
|
|
18
|
+
from itertools import chain
|
|
19
|
+
|
|
20
|
+
from src.db.setup import get_db
|
|
21
|
+
from src.db.models.base import Base
|
|
22
|
+
from src.db.crud import CRUDMixin, with_db
|
|
23
|
+
|
|
24
|
+
# jointures
|
|
25
|
+
dataset_target_association = Table(
|
|
26
|
+
"dataset_target_association",
|
|
27
|
+
Base.metadata,
|
|
28
|
+
Column(
|
|
29
|
+
"dataset_id",
|
|
30
|
+
BigInteger,
|
|
31
|
+
ForeignKey("datasets.id", ondelete="CASCADE"),
|
|
32
|
+
primary_key=True,
|
|
33
|
+
),
|
|
34
|
+
Column(
|
|
35
|
+
"target_id",
|
|
36
|
+
BigInteger,
|
|
37
|
+
ForeignKey("targets.id", ondelete="CASCADE"),
|
|
38
|
+
primary_key=True,
|
|
39
|
+
),
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class Dataset(Base, CRUDMixin):
|
|
44
|
+
__tablename__ = "datasets"
|
|
45
|
+
|
|
46
|
+
id = Column(BigInteger, primary_key=True, index=True, autoincrement=True)
|
|
47
|
+
created_at = Column(
|
|
48
|
+
TIMESTAMP(timezone=True), server_default=func.now(), nullable=False
|
|
49
|
+
)
|
|
50
|
+
updated_at = Column(
|
|
51
|
+
TIMESTAMP(timezone=True),
|
|
52
|
+
server_default=func.now(),
|
|
53
|
+
onupdate=func.now(),
|
|
54
|
+
nullable=False,
|
|
55
|
+
)
|
|
56
|
+
name = Column(String(50), nullable=False)
|
|
57
|
+
path = Column(String(255)) # we do not have this at creation time
|
|
58
|
+
type = Column(String(50), nullable=False)
|
|
59
|
+
size = Column(Integer, nullable=False)
|
|
60
|
+
train_size = Column(Integer, nullable=False)
|
|
61
|
+
val_size = Column(Integer)
|
|
62
|
+
test_size = Column(Integer, nullable=False)
|
|
63
|
+
number_of_groups = Column(Integer, nullable=False)
|
|
64
|
+
list_of_groups = Column(JSON, nullable=False)
|
|
65
|
+
corr_threshold = Column(Float, nullable=False)
|
|
66
|
+
max_features = Column(Integer, nullable=False)
|
|
67
|
+
percentile = Column(Float, nullable=False)
|
|
68
|
+
start_date = Column(DateTime, nullable=False)
|
|
69
|
+
end_date = Column(DateTime, nullable=False)
|
|
70
|
+
train_start_date = Column(DateTime, nullable=False)
|
|
71
|
+
train_end_date = Column(DateTime, nullable=False)
|
|
72
|
+
val_start_date = Column(DateTime)
|
|
73
|
+
val_end_date = Column(DateTime)
|
|
74
|
+
test_start_date = Column(DateTime, nullable=False)
|
|
75
|
+
test_end_date = Column(DateTime, nullable=False)
|
|
76
|
+
|
|
77
|
+
feature_selections = relationship(
|
|
78
|
+
"FeatureSelection",
|
|
79
|
+
back_populates="dataset",
|
|
80
|
+
cascade="all, delete-orphan",
|
|
81
|
+
lazy="selectin",
|
|
82
|
+
)
|
|
83
|
+
model_selections = relationship(
|
|
84
|
+
"ModelSelection",
|
|
85
|
+
back_populates="dataset",
|
|
86
|
+
cascade="all, delete-orphan",
|
|
87
|
+
lazy="selectin",
|
|
88
|
+
)
|
|
89
|
+
targets = relationship(
|
|
90
|
+
"Target",
|
|
91
|
+
secondary=dataset_target_association,
|
|
92
|
+
back_populates="datasets",
|
|
93
|
+
lazy="selectin",
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
__table_args__ = (
|
|
97
|
+
UniqueConstraint(
|
|
98
|
+
"name",
|
|
99
|
+
name="uq_datasets_composite",
|
|
100
|
+
),
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
def get_features(self, target_number: int):
|
|
104
|
+
feature_selections = self.feature_selections
|
|
105
|
+
target_id = [t for t in self.targets if t.name == f"TARGET_{target_number}"][
|
|
106
|
+
0
|
|
107
|
+
].id
|
|
108
|
+
feature_selection = [
|
|
109
|
+
fs for fs in feature_selections if fs.target_id == target_id
|
|
110
|
+
][0]
|
|
111
|
+
feature = [f.name for f in feature_selection.features]
|
|
112
|
+
return feature
|
|
113
|
+
|
|
114
|
+
def get_all_features(self):
|
|
115
|
+
target_idx = [target.id for target in self.targets]
|
|
116
|
+
all_features = chain.from_iterable(
|
|
117
|
+
[f.name for f in fs.features]
|
|
118
|
+
for fs in self.feature_selections
|
|
119
|
+
if fs.target_id in target_idx
|
|
120
|
+
)
|
|
121
|
+
all_features = ["DATE", "STOCK"] + list(all_features)
|
|
122
|
+
all_features = list(dict.fromkeys(all_features))
|
|
123
|
+
|
|
124
|
+
return all_features
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from sqlalchemy import (
|
|
2
|
+
Column,
|
|
3
|
+
Integer,
|
|
4
|
+
String,
|
|
5
|
+
DateTime,
|
|
6
|
+
Date,
|
|
7
|
+
Float,
|
|
8
|
+
JSON,
|
|
9
|
+
Table,
|
|
10
|
+
ForeignKey,
|
|
11
|
+
BigInteger,
|
|
12
|
+
Index,
|
|
13
|
+
TIMESTAMP,
|
|
14
|
+
)
|
|
15
|
+
from sqlalchemy import desc, asc, cast, text, func
|
|
16
|
+
|
|
17
|
+
from sqlalchemy.orm import relationship, Mapped, mapped_column, DeclarativeBase
|
|
18
|
+
|
|
19
|
+
from src.db.setup import get_db
|
|
20
|
+
from src.db.models.base import Base
|
|
21
|
+
from src.db.models.feature_selection import feature_selection_association
|
|
22
|
+
from src.db.crud import CRUDMixin
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Feature(Base, CRUDMixin):
|
|
26
|
+
__tablename__ = "features"
|
|
27
|
+
|
|
28
|
+
id = Column(BigInteger, primary_key=True, index=True, autoincrement=True)
|
|
29
|
+
created_at = Column(
|
|
30
|
+
TIMESTAMP(timezone=True), server_default=func.now(), nullable=False
|
|
31
|
+
)
|
|
32
|
+
updated_at = Column(
|
|
33
|
+
TIMESTAMP(timezone=True),
|
|
34
|
+
server_default=func.now(),
|
|
35
|
+
onupdate=func.now(),
|
|
36
|
+
nullable=False,
|
|
37
|
+
)
|
|
38
|
+
name = Column(String(50), nullable=False, unique=True)
|
|
39
|
+
type = Column(String(50))
|
|
40
|
+
|
|
41
|
+
feature_selections = relationship(
|
|
42
|
+
"FeatureSelection",
|
|
43
|
+
secondary=feature_selection_association,
|
|
44
|
+
back_populates="features",
|
|
45
|
+
lazy="selectin"
|
|
46
|
+
)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
from sqlalchemy import (
|
|
2
|
+
Column,
|
|
3
|
+
Integer,
|
|
4
|
+
String,
|
|
5
|
+
DateTime,
|
|
6
|
+
Date,
|
|
7
|
+
Float,
|
|
8
|
+
JSON,
|
|
9
|
+
Table,
|
|
10
|
+
ForeignKey,
|
|
11
|
+
BigInteger,
|
|
12
|
+
Index,
|
|
13
|
+
TIMESTAMP,
|
|
14
|
+
UniqueConstraint,
|
|
15
|
+
)
|
|
16
|
+
from sqlalchemy import desc, asc, cast, text, func
|
|
17
|
+
|
|
18
|
+
from sqlalchemy.orm import (
|
|
19
|
+
relationship,
|
|
20
|
+
Mapped,
|
|
21
|
+
mapped_column,
|
|
22
|
+
DeclarativeBase,
|
|
23
|
+
object_session,
|
|
24
|
+
)
|
|
25
|
+
from collections.abc import Iterable
|
|
26
|
+
|
|
27
|
+
from src.db.setup import get_db
|
|
28
|
+
from src.db.models.base import Base
|
|
29
|
+
from src.db.crud import CRUDMixin, with_db
|
|
30
|
+
|
|
31
|
+
# jointures
|
|
32
|
+
feature_selection_association = Table(
|
|
33
|
+
"feature_selection_association",
|
|
34
|
+
Base.metadata,
|
|
35
|
+
Column(
|
|
36
|
+
"feature_selection_id",
|
|
37
|
+
BigInteger,
|
|
38
|
+
ForeignKey("feature_selections.id", ondelete="CASCADE"),
|
|
39
|
+
primary_key=True,
|
|
40
|
+
),
|
|
41
|
+
Column(
|
|
42
|
+
"feature_id",
|
|
43
|
+
BigInteger,
|
|
44
|
+
ForeignKey("features.id", ondelete="CASCADE"),
|
|
45
|
+
primary_key=True,
|
|
46
|
+
),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class FeatureSelection(Base, CRUDMixin):
|
|
51
|
+
__tablename__ = "feature_selections"
|
|
52
|
+
|
|
53
|
+
id = Column(BigInteger, primary_key=True, index=True, autoincrement=True)
|
|
54
|
+
created_at = Column(
|
|
55
|
+
TIMESTAMP(timezone=True), server_default=func.now(), nullable=False
|
|
56
|
+
)
|
|
57
|
+
updated_at = Column(
|
|
58
|
+
TIMESTAMP(timezone=True),
|
|
59
|
+
server_default=func.now(),
|
|
60
|
+
onupdate=func.now(),
|
|
61
|
+
nullable=False,
|
|
62
|
+
)
|
|
63
|
+
training_time = Column(Integer)
|
|
64
|
+
best_features_path = Column(String(255))
|
|
65
|
+
dataset_id = Column(
|
|
66
|
+
BigInteger, ForeignKey("datasets.id", ondelete="CASCADE"), nullable=False
|
|
67
|
+
)
|
|
68
|
+
target_id = Column(
|
|
69
|
+
BigInteger, ForeignKey("targets.id", ondelete="CASCADE"), nullable=False
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
dataset = relationship(
|
|
73
|
+
"Dataset", back_populates="feature_selections", lazy="selectin"
|
|
74
|
+
)
|
|
75
|
+
target = relationship(
|
|
76
|
+
"Target", back_populates="feature_selections", lazy="selectin"
|
|
77
|
+
)
|
|
78
|
+
feature_selection_ranks = relationship(
|
|
79
|
+
"FeatureSelectionRank",
|
|
80
|
+
back_populates="feature_selection",
|
|
81
|
+
cascade="all, delete-orphan",
|
|
82
|
+
lazy="selectin",
|
|
83
|
+
)
|
|
84
|
+
features = relationship(
|
|
85
|
+
"Feature",
|
|
86
|
+
secondary=feature_selection_association,
|
|
87
|
+
back_populates="feature_selections",
|
|
88
|
+
lazy="selectin",
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
__table_args__ = (
|
|
92
|
+
UniqueConstraint(
|
|
93
|
+
"dataset_id", "target_id", name="uq_feature_selection_composite"
|
|
94
|
+
),
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
@with_db
|
|
98
|
+
def add_features(self, features: list, db=None):
|
|
99
|
+
self = db.merge(self)
|
|
100
|
+
for feature in features:
|
|
101
|
+
feature = db.merge(feature)
|
|
102
|
+
if feature not in self.features:
|
|
103
|
+
self.features.append(feature)
|
|
104
|
+
# db.flush()
|
|
105
|
+
# db.refresh(self)
|
|
106
|
+
return self
|
|
107
|
+
|
|
108
|
+
@with_db
|
|
109
|
+
def __lshift__(self, feature_or_list, db=None):
|
|
110
|
+
items = (
|
|
111
|
+
feature_or_list
|
|
112
|
+
if isinstance(feature_or_list, Iterable)
|
|
113
|
+
and not isinstance(feature_or_list, (str, bytes))
|
|
114
|
+
else [feature_or_list]
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
self = db.merge(self)
|
|
118
|
+
for feature in items:
|
|
119
|
+
feature = db.merge(feature)
|
|
120
|
+
if feature not in self.features:
|
|
121
|
+
self.features.append(feature)
|
|
122
|
+
|
|
123
|
+
db.flush()
|
|
124
|
+
db.refresh(self)
|
|
125
|
+
print(self.features)
|
|
126
|
+
return self
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from sqlalchemy import (
|
|
2
|
+
Column,
|
|
3
|
+
Integer,
|
|
4
|
+
String,
|
|
5
|
+
DateTime,
|
|
6
|
+
Date,
|
|
7
|
+
Float,
|
|
8
|
+
JSON,
|
|
9
|
+
Table,
|
|
10
|
+
ForeignKey,
|
|
11
|
+
BigInteger,
|
|
12
|
+
Index,
|
|
13
|
+
TIMESTAMP,
|
|
14
|
+
UniqueConstraint,
|
|
15
|
+
)
|
|
16
|
+
from sqlalchemy import desc, asc, cast, text, func
|
|
17
|
+
|
|
18
|
+
from sqlalchemy.orm import relationship, Mapped, mapped_column, DeclarativeBase
|
|
19
|
+
from sqlalchemy.dialects.mysql import insert
|
|
20
|
+
|
|
21
|
+
from src.db.setup import get_db
|
|
22
|
+
from src.db.models.base import Base
|
|
23
|
+
from src.db.crud import CRUDMixin, with_db
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class FeatureSelectionRank(Base, CRUDMixin):
|
|
27
|
+
__tablename__ = "feature_selection_ranks"
|
|
28
|
+
|
|
29
|
+
id = Column(BigInteger, primary_key=True, index=True, autoincrement=True)
|
|
30
|
+
created_at = Column(
|
|
31
|
+
TIMESTAMP(timezone=True), server_default=func.now(), nullable=False
|
|
32
|
+
)
|
|
33
|
+
updated_at = Column(
|
|
34
|
+
TIMESTAMP(timezone=True),
|
|
35
|
+
server_default=func.now(),
|
|
36
|
+
onupdate=func.now(),
|
|
37
|
+
nullable=False,
|
|
38
|
+
)
|
|
39
|
+
score = Column(Float)
|
|
40
|
+
pvalue = Column(Float)
|
|
41
|
+
support = Column(Integer)
|
|
42
|
+
rank = Column(Integer)
|
|
43
|
+
method = Column(String(50))
|
|
44
|
+
training_time = Column(Integer)
|
|
45
|
+
feature_id = Column(BigInteger, ForeignKey("features.id", ondelete="CASCADE"))
|
|
46
|
+
feature_selection_id = Column(
|
|
47
|
+
BigInteger, ForeignKey("feature_selections.id", ondelete="CASCADE")
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
feature = relationship("Feature", lazy="selectin")
|
|
51
|
+
feature_selection = relationship(
|
|
52
|
+
"FeatureSelection", back_populates="feature_selection_ranks", lazy="selectin"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
__table_args__ = (
|
|
56
|
+
UniqueConstraint(
|
|
57
|
+
"feature_id",
|
|
58
|
+
"feature_selection_id",
|
|
59
|
+
"method",
|
|
60
|
+
name="uq_feature_selection_rank_composite",
|
|
61
|
+
),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
@classmethod
|
|
65
|
+
@with_db
|
|
66
|
+
def bulk_upsert(cls, rows, db=None):
|
|
67
|
+
stmt = insert(cls).values(rows)
|
|
68
|
+
|
|
69
|
+
update_fields = {
|
|
70
|
+
key: stmt.inserted[key]
|
|
71
|
+
for key in rows[0]
|
|
72
|
+
if key not in ("feature_selection_id", "feature_id", "method")
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
stmt = stmt.on_duplicate_key_update(**update_fields)
|
|
76
|
+
|
|
77
|
+
db.execute(stmt)
|
|
78
|
+
db.commit()
|
|
79
|
+
|
|
80
|
+
return len(rows)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from sqlalchemy import (
|
|
2
|
+
Column,
|
|
3
|
+
Integer,
|
|
4
|
+
String,
|
|
5
|
+
DateTime,
|
|
6
|
+
Date,
|
|
7
|
+
Float,
|
|
8
|
+
JSON,
|
|
9
|
+
Table,
|
|
10
|
+
ForeignKey,
|
|
11
|
+
BigInteger,
|
|
12
|
+
Index,
|
|
13
|
+
TIMESTAMP,
|
|
14
|
+
UniqueConstraint,
|
|
15
|
+
)
|
|
16
|
+
from sqlalchemy import desc, asc, cast, text, func
|
|
17
|
+
|
|
18
|
+
from sqlalchemy.orm import relationship, Mapped, mapped_column, DeclarativeBase
|
|
19
|
+
|
|
20
|
+
from src.db.setup import get_db
|
|
21
|
+
from src.db.models.base import Base
|
|
22
|
+
from src.db.crud import CRUDMixin
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Model(Base, CRUDMixin):
|
|
26
|
+
__tablename__ = "models"
|
|
27
|
+
|
|
28
|
+
id = Column(BigInteger, primary_key=True, index=True, autoincrement=True)
|
|
29
|
+
created_at = Column(
|
|
30
|
+
TIMESTAMP(timezone=True), server_default=func.now(), nullable=False
|
|
31
|
+
)
|
|
32
|
+
updated_at = Column(
|
|
33
|
+
TIMESTAMP(timezone=True),
|
|
34
|
+
server_default=func.now(),
|
|
35
|
+
onupdate=func.now(),
|
|
36
|
+
nullable=False,
|
|
37
|
+
)
|
|
38
|
+
name = Column(String(50), nullable=False)
|
|
39
|
+
type = Column(String(50), nullable=False)
|
|
40
|
+
|
|
41
|
+
__table_args__ = (UniqueConstraint("name", "type", name="uq_model_composite"),)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from sqlalchemy import (
|
|
2
|
+
Column,
|
|
3
|
+
Integer,
|
|
4
|
+
String,
|
|
5
|
+
DateTime,
|
|
6
|
+
Date,
|
|
7
|
+
Float,
|
|
8
|
+
JSON,
|
|
9
|
+
Table,
|
|
10
|
+
ForeignKey,
|
|
11
|
+
BigInteger,
|
|
12
|
+
Index,
|
|
13
|
+
TIMESTAMP,
|
|
14
|
+
UniqueConstraint,
|
|
15
|
+
)
|
|
16
|
+
from sqlalchemy import desc, asc, cast, text, func
|
|
17
|
+
|
|
18
|
+
from sqlalchemy.orm import relationship, Mapped, mapped_column, DeclarativeBase
|
|
19
|
+
|
|
20
|
+
from src.db.setup import get_db
|
|
21
|
+
from src.db.models.base import Base
|
|
22
|
+
from src.db.crud import CRUDMixin
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ModelSelection(Base, CRUDMixin):
|
|
26
|
+
__tablename__ = "model_selections"
|
|
27
|
+
|
|
28
|
+
id = Column(BigInteger, primary_key=True, index=True, autoincrement=True)
|
|
29
|
+
created_at = Column(
|
|
30
|
+
TIMESTAMP(timezone=True), server_default=func.now(), nullable=False
|
|
31
|
+
)
|
|
32
|
+
updated_at = Column(
|
|
33
|
+
TIMESTAMP(timezone=True),
|
|
34
|
+
server_default=func.now(),
|
|
35
|
+
onupdate=func.now(),
|
|
36
|
+
nullable=False,
|
|
37
|
+
)
|
|
38
|
+
best_model_params = Column(JSON)
|
|
39
|
+
best_model_path = Column(String(255))
|
|
40
|
+
best_model_id = Column(BigInteger, ForeignKey("models.id", ondelete="CASCADE"))
|
|
41
|
+
target_id = Column(BigInteger, ForeignKey("targets.id", ondelete="CASCADE"), nullable=False)
|
|
42
|
+
dataset_id = Column(BigInteger, ForeignKey("datasets.id", ondelete="CASCADE"), nullable=False)
|
|
43
|
+
|
|
44
|
+
best_model = relationship("Model", lazy="selectin")
|
|
45
|
+
model_trainings = relationship("ModelTraining", back_populates="model_selection", cascade="all, delete-orphan", lazy="selectin")
|
|
46
|
+
dataset = relationship(
|
|
47
|
+
"Dataset", back_populates="model_selections", lazy="selectin"
|
|
48
|
+
)
|
|
49
|
+
target = relationship("Target", back_populates="model_selections", lazy="selectin")
|
|
50
|
+
|
|
51
|
+
__table_args__ = (
|
|
52
|
+
UniqueConstraint(
|
|
53
|
+
"target_id", "dataset_id", name="uq_model_selection_composite"
|
|
54
|
+
),
|
|
55
|
+
)
|
|
56
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from sqlalchemy import (
|
|
2
|
+
Column,
|
|
3
|
+
Integer,
|
|
4
|
+
String,
|
|
5
|
+
DateTime,
|
|
6
|
+
Date,
|
|
7
|
+
Float,
|
|
8
|
+
JSON,
|
|
9
|
+
Table,
|
|
10
|
+
ForeignKey,
|
|
11
|
+
BigInteger,
|
|
12
|
+
Index,
|
|
13
|
+
TIMESTAMP,
|
|
14
|
+
UniqueConstraint,
|
|
15
|
+
)
|
|
16
|
+
from sqlalchemy import desc, asc, cast, text, func
|
|
17
|
+
|
|
18
|
+
from sqlalchemy.orm import relationship, Mapped, mapped_column, DeclarativeBase
|
|
19
|
+
|
|
20
|
+
from src.db.setup import get_db
|
|
21
|
+
from src.db.models.base import Base
|
|
22
|
+
from src.db.crud import CRUDMixin
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ModelTraining(Base, CRUDMixin):
|
|
26
|
+
__tablename__ = "model_trainings"
|
|
27
|
+
|
|
28
|
+
id = Column(BigInteger, primary_key=True, index=True, autoincrement=True)
|
|
29
|
+
created_at = Column(
|
|
30
|
+
TIMESTAMP(timezone=True), server_default=func.now(), nullable=False
|
|
31
|
+
)
|
|
32
|
+
updated_at = Column(
|
|
33
|
+
TIMESTAMP(timezone=True),
|
|
34
|
+
server_default=func.now(),
|
|
35
|
+
onupdate=func.now(),
|
|
36
|
+
nullable=False,
|
|
37
|
+
)
|
|
38
|
+
best_params = Column(JSON)
|
|
39
|
+
model_path = Column(String(255))
|
|
40
|
+
training_time = Column(Integer)
|
|
41
|
+
model_id = Column(BigInteger, ForeignKey("models.id"), nullable=False)
|
|
42
|
+
model_selection_id = Column(
|
|
43
|
+
BigInteger, ForeignKey("model_selections.id", ondelete="CASCADE"), nullable=False
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
model = relationship("Model", lazy="selectin")
|
|
47
|
+
model_selection = relationship("ModelSelection", back_populates="model_trainings", lazy="selectin")
|
|
48
|
+
score = relationship("Score", back_populates="model_trainings", cascade="all, delete-orphan", lazy="selectin")
|
|
49
|
+
|
|
50
|
+
__table_args__ = (
|
|
51
|
+
UniqueConstraint(
|
|
52
|
+
"model_id", "model_selection_id", name="uq_model_training_composite"
|
|
53
|
+
),
|
|
54
|
+
)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from sqlalchemy import (
|
|
2
|
+
Column,
|
|
3
|
+
Integer,
|
|
4
|
+
String,
|
|
5
|
+
DateTime,
|
|
6
|
+
Date,
|
|
7
|
+
Float,
|
|
8
|
+
JSON,
|
|
9
|
+
Table,
|
|
10
|
+
ForeignKey,
|
|
11
|
+
BigInteger,
|
|
12
|
+
Index,
|
|
13
|
+
TIMESTAMP,
|
|
14
|
+
)
|
|
15
|
+
from sqlalchemy import desc, asc, cast, text, func
|
|
16
|
+
|
|
17
|
+
from sqlalchemy.orm import relationship, Mapped, mapped_column, DeclarativeBase
|
|
18
|
+
|
|
19
|
+
from src.db.setup import get_db
|
|
20
|
+
from src.db.models.base import Base
|
|
21
|
+
from src.db.crud import CRUDMixin
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Score(Base, CRUDMixin):
|
|
25
|
+
__tablename__ = "scores"
|
|
26
|
+
|
|
27
|
+
id = Column(BigInteger, primary_key=True, index=True, autoincrement=True)
|
|
28
|
+
created_at = Column(
|
|
29
|
+
TIMESTAMP(timezone=True), server_default=func.now(), nullable=False
|
|
30
|
+
)
|
|
31
|
+
updated_at = Column(
|
|
32
|
+
TIMESTAMP(timezone=True),
|
|
33
|
+
server_default=func.now(),
|
|
34
|
+
onupdate=func.now(),
|
|
35
|
+
nullable=False,
|
|
36
|
+
)
|
|
37
|
+
type = Column(
|
|
38
|
+
String(50), nullable=False
|
|
39
|
+
) # either hyperopts or validation or crossval
|
|
40
|
+
training_time = Column(Integer)
|
|
41
|
+
eval_data_std = Column(Float)
|
|
42
|
+
rmse = Column(Float)
|
|
43
|
+
rmse_std_ratio = Column(Float)
|
|
44
|
+
mae = Column(Float)
|
|
45
|
+
mape = Column(Float)
|
|
46
|
+
mam = Column(Float)
|
|
47
|
+
mad = Column(Float)
|
|
48
|
+
mae_mam_ratio = Column(Float)
|
|
49
|
+
mae_mad_ratio = Column(Float)
|
|
50
|
+
r2 = Column(Float)
|
|
51
|
+
logloss = Column(Float)
|
|
52
|
+
accuracy = Column(Float)
|
|
53
|
+
precision = Column(Float)
|
|
54
|
+
recall = Column(Float)
|
|
55
|
+
f1 = Column(Float)
|
|
56
|
+
roc_auc = Column(Float)
|
|
57
|
+
threshold = Column(Float)
|
|
58
|
+
precision_at_threshold = Column(Float)
|
|
59
|
+
recall_at_threshold = Column(Float)
|
|
60
|
+
model_training_id = Column(BigInteger, ForeignKey("model_trainings.id", ondelete="CASCADE"), nullable=False)
|
|
61
|
+
|
|
62
|
+
model_trainings = relationship("ModelTraining", back_populates="score", lazy="selectin")
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from sqlalchemy import (
|
|
2
|
+
Column,
|
|
3
|
+
Integer,
|
|
4
|
+
String,
|
|
5
|
+
DateTime,
|
|
6
|
+
Date,
|
|
7
|
+
Float,
|
|
8
|
+
JSON,
|
|
9
|
+
Table,
|
|
10
|
+
ForeignKey,
|
|
11
|
+
BigInteger,
|
|
12
|
+
Index,
|
|
13
|
+
TIMESTAMP,
|
|
14
|
+
UniqueConstraint,
|
|
15
|
+
)
|
|
16
|
+
from sqlalchemy import desc, asc, cast, text, func
|
|
17
|
+
|
|
18
|
+
from sqlalchemy.orm import relationship, Mapped, mapped_column, DeclarativeBase
|
|
19
|
+
|
|
20
|
+
from src.db.setup import get_db
|
|
21
|
+
from src.db.models.base import Base
|
|
22
|
+
from src.db.crud import CRUDMixin
|
|
23
|
+
from src.db.models.dataset import dataset_target_association
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Target(Base, CRUDMixin):
|
|
27
|
+
__tablename__ = "targets"
|
|
28
|
+
|
|
29
|
+
id = Column(BigInteger, primary_key=True, index=True, autoincrement=True)
|
|
30
|
+
created_at = Column(
|
|
31
|
+
TIMESTAMP(timezone=True), server_default=func.now(), nullable=False
|
|
32
|
+
)
|
|
33
|
+
updated_at = Column(
|
|
34
|
+
TIMESTAMP(timezone=True),
|
|
35
|
+
server_default=func.now(),
|
|
36
|
+
onupdate=func.now(),
|
|
37
|
+
nullable=False,
|
|
38
|
+
)
|
|
39
|
+
name = Column(String(50), nullable=False)
|
|
40
|
+
type = Column(String(50), nullable=False)
|
|
41
|
+
description = Column(String(255))
|
|
42
|
+
|
|
43
|
+
datasets = relationship(
|
|
44
|
+
"Dataset", secondary=dataset_target_association, back_populates="targets", lazy="selectin"
|
|
45
|
+
)
|
|
46
|
+
feature_selections = relationship(
|
|
47
|
+
"FeatureSelection", back_populates="target", cascade="all, delete-orphan", lazy="selectin"
|
|
48
|
+
)
|
|
49
|
+
model_selections = relationship(
|
|
50
|
+
"ModelSelection", back_populates="target", cascade="all, delete-orphan", lazy="selectin"
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
__table_args__ = (
|
|
54
|
+
UniqueConstraint(
|
|
55
|
+
"name",
|
|
56
|
+
"type",
|
|
57
|
+
name="uq_target_composite",
|
|
58
|
+
),
|
|
59
|
+
)
|
lecrapaud/db/services.py
ADDED
|
File without changes
|