lecrapaud 0.1.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 +1 -0
- lecrapaud/api.py +271 -0
- lecrapaud/config.py +25 -0
- lecrapaud/db/__init__.py +1 -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/alembic/versions/2025_06_17_1652-c45f5e49fa2c_make_fields_nullable.py +89 -0
- lecrapaud/db/models/__init__.py +11 -0
- lecrapaud/db/models/base.py +181 -0
- lecrapaud/db/models/dataset.py +129 -0
- lecrapaud/db/models/feature.py +45 -0
- lecrapaud/db/models/feature_selection.py +125 -0
- lecrapaud/db/models/feature_selection_rank.py +79 -0
- lecrapaud/db/models/model.py +40 -0
- lecrapaud/db/models/model_selection.py +63 -0
- lecrapaud/db/models/model_training.py +62 -0
- lecrapaud/db/models/score.py +65 -0
- lecrapaud/db/models/target.py +67 -0
- lecrapaud/db/session.py +45 -0
- lecrapaud/directory_management.py +28 -0
- lecrapaud/experiment.py +64 -0
- lecrapaud/feature_engineering.py +846 -0
- lecrapaud/feature_selection.py +1167 -0
- lecrapaud/integrations/openai_integration.py +225 -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 +1671 -0
- lecrapaud/predictions.py +292 -0
- lecrapaud/preprocessing.py +984 -0
- lecrapaud/search_space.py +848 -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 +239 -0
- lecrapaud/utils.py +246 -0
- lecrapaud-0.1.0.dist-info/LICENSE +201 -0
- lecrapaud-0.1.0.dist-info/METADATA +105 -0
- lecrapaud-0.1.0.dist-info/RECORD +63 -0
- lecrapaud-0.1.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,129 @@
|
|
|
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 lecrapaud.db.session import get_db
|
|
21
|
+
from lecrapaud.db.models.base import Base
|
|
22
|
+
|
|
23
|
+
# jointures
|
|
24
|
+
dataset_target_association = Table(
|
|
25
|
+
"dataset_target_association",
|
|
26
|
+
Base.metadata,
|
|
27
|
+
Column(
|
|
28
|
+
"dataset_id",
|
|
29
|
+
BigInteger,
|
|
30
|
+
ForeignKey("datasets.id", ondelete="CASCADE"),
|
|
31
|
+
primary_key=True,
|
|
32
|
+
),
|
|
33
|
+
Column(
|
|
34
|
+
"target_id",
|
|
35
|
+
BigInteger,
|
|
36
|
+
ForeignKey("targets.id", ondelete="CASCADE"),
|
|
37
|
+
primary_key=True,
|
|
38
|
+
),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class Dataset(Base):
|
|
43
|
+
__tablename__ = "datasets"
|
|
44
|
+
|
|
45
|
+
id = Column(BigInteger, primary_key=True, index=True, autoincrement=True)
|
|
46
|
+
created_at = Column(
|
|
47
|
+
TIMESTAMP(timezone=True), server_default=func.now(), nullable=False
|
|
48
|
+
)
|
|
49
|
+
updated_at = Column(
|
|
50
|
+
TIMESTAMP(timezone=True),
|
|
51
|
+
server_default=func.now(),
|
|
52
|
+
onupdate=func.now(),
|
|
53
|
+
nullable=False,
|
|
54
|
+
)
|
|
55
|
+
name = Column(String(50), nullable=False)
|
|
56
|
+
path = Column(String(255)) # we do not have this at creation time
|
|
57
|
+
type = Column(String(50), nullable=False)
|
|
58
|
+
size = Column(Integer, nullable=False)
|
|
59
|
+
train_size = Column(Integer)
|
|
60
|
+
val_size = Column(Integer)
|
|
61
|
+
test_size = Column(Integer)
|
|
62
|
+
corr_threshold = Column(Float, nullable=False)
|
|
63
|
+
max_features = Column(Integer, nullable=False)
|
|
64
|
+
percentile = Column(Float, nullable=False)
|
|
65
|
+
number_of_groups = Column(Integer)
|
|
66
|
+
list_of_groups = Column(JSON)
|
|
67
|
+
start_date = Column(DateTime)
|
|
68
|
+
end_date = Column(DateTime)
|
|
69
|
+
train_start_date = Column(DateTime)
|
|
70
|
+
train_end_date = Column(DateTime)
|
|
71
|
+
val_start_date = Column(DateTime)
|
|
72
|
+
val_end_date = Column(DateTime)
|
|
73
|
+
test_start_date = Column(DateTime)
|
|
74
|
+
test_end_date = Column(DateTime)
|
|
75
|
+
|
|
76
|
+
feature_selections = relationship(
|
|
77
|
+
"FeatureSelection",
|
|
78
|
+
back_populates="dataset",
|
|
79
|
+
cascade="all, delete-orphan",
|
|
80
|
+
lazy="selectin",
|
|
81
|
+
)
|
|
82
|
+
model_selections = relationship(
|
|
83
|
+
"ModelSelection",
|
|
84
|
+
back_populates="dataset",
|
|
85
|
+
cascade="all, delete-orphan",
|
|
86
|
+
lazy="selectin",
|
|
87
|
+
)
|
|
88
|
+
targets = relationship(
|
|
89
|
+
"Target",
|
|
90
|
+
secondary=dataset_target_association,
|
|
91
|
+
back_populates="datasets",
|
|
92
|
+
lazy="selectin",
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
__table_args__ = (
|
|
96
|
+
UniqueConstraint(
|
|
97
|
+
"name",
|
|
98
|
+
name="uq_datasets_composite",
|
|
99
|
+
),
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
def get_features(self, target_number: int):
|
|
103
|
+
feature_selections = self.feature_selections
|
|
104
|
+
target_id = [t for t in self.targets if t.name == f"TARGET_{target_number}"][
|
|
105
|
+
0
|
|
106
|
+
].id
|
|
107
|
+
feature_selection = [
|
|
108
|
+
fs for fs in feature_selections if fs.target_id == target_id
|
|
109
|
+
][0]
|
|
110
|
+
feature = [f.name for f in feature_selection.features]
|
|
111
|
+
return feature
|
|
112
|
+
|
|
113
|
+
def get_all_features(self, date_column: str = None, group_column: str = None):
|
|
114
|
+
target_idx = [target.id for target in self.targets]
|
|
115
|
+
all_features = []
|
|
116
|
+
if date_column:
|
|
117
|
+
all_features.append(date_column)
|
|
118
|
+
if group_column:
|
|
119
|
+
all_features.append(group_column)
|
|
120
|
+
all_features += list(
|
|
121
|
+
chain.from_iterable(
|
|
122
|
+
[f.name for f in fs.features]
|
|
123
|
+
for fs in self.feature_selections
|
|
124
|
+
if fs.target_id in target_idx
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
all_features = list(dict.fromkeys(all_features))
|
|
128
|
+
|
|
129
|
+
return all_features
|
|
@@ -0,0 +1,45 @@
|
|
|
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 lecrapaud.db.session import get_db
|
|
20
|
+
from lecrapaud.db.models.base import Base
|
|
21
|
+
from lecrapaud.db.models.feature_selection import feature_selection_association
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Feature(Base):
|
|
25
|
+
__tablename__ = "features"
|
|
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
|
+
name = Column(String(50), nullable=False, unique=True)
|
|
38
|
+
type = Column(String(50))
|
|
39
|
+
|
|
40
|
+
feature_selections = relationship(
|
|
41
|
+
"FeatureSelection",
|
|
42
|
+
secondary=feature_selection_association,
|
|
43
|
+
back_populates="features",
|
|
44
|
+
lazy="selectin",
|
|
45
|
+
)
|
|
@@ -0,0 +1,125 @@
|
|
|
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 lecrapaud.db.session import get_db
|
|
28
|
+
from lecrapaud.db.models.base import Base, with_db
|
|
29
|
+
|
|
30
|
+
# jointures
|
|
31
|
+
feature_selection_association = Table(
|
|
32
|
+
"feature_selection_association",
|
|
33
|
+
Base.metadata,
|
|
34
|
+
Column(
|
|
35
|
+
"feature_selection_id",
|
|
36
|
+
BigInteger,
|
|
37
|
+
ForeignKey("feature_selections.id", ondelete="CASCADE"),
|
|
38
|
+
primary_key=True,
|
|
39
|
+
),
|
|
40
|
+
Column(
|
|
41
|
+
"feature_id",
|
|
42
|
+
BigInteger,
|
|
43
|
+
ForeignKey("features.id", ondelete="CASCADE"),
|
|
44
|
+
primary_key=True,
|
|
45
|
+
),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class FeatureSelection(Base):
|
|
50
|
+
__tablename__ = "feature_selections"
|
|
51
|
+
|
|
52
|
+
id = Column(BigInteger, primary_key=True, index=True, autoincrement=True)
|
|
53
|
+
created_at = Column(
|
|
54
|
+
TIMESTAMP(timezone=True), server_default=func.now(), nullable=False
|
|
55
|
+
)
|
|
56
|
+
updated_at = Column(
|
|
57
|
+
TIMESTAMP(timezone=True),
|
|
58
|
+
server_default=func.now(),
|
|
59
|
+
onupdate=func.now(),
|
|
60
|
+
nullable=False,
|
|
61
|
+
)
|
|
62
|
+
training_time = Column(Integer)
|
|
63
|
+
best_features_path = Column(String(255))
|
|
64
|
+
dataset_id = Column(
|
|
65
|
+
BigInteger, ForeignKey("datasets.id", ondelete="CASCADE"), nullable=False
|
|
66
|
+
)
|
|
67
|
+
target_id = Column(
|
|
68
|
+
BigInteger, ForeignKey("targets.id", ondelete="CASCADE"), nullable=False
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
dataset = relationship(
|
|
72
|
+
"Dataset", back_populates="feature_selections", lazy="selectin"
|
|
73
|
+
)
|
|
74
|
+
target = relationship(
|
|
75
|
+
"Target", back_populates="feature_selections", lazy="selectin"
|
|
76
|
+
)
|
|
77
|
+
feature_selection_ranks = relationship(
|
|
78
|
+
"FeatureSelectionRank",
|
|
79
|
+
back_populates="feature_selection",
|
|
80
|
+
cascade="all, delete-orphan",
|
|
81
|
+
lazy="selectin",
|
|
82
|
+
)
|
|
83
|
+
features = relationship(
|
|
84
|
+
"Feature",
|
|
85
|
+
secondary=feature_selection_association,
|
|
86
|
+
back_populates="feature_selections",
|
|
87
|
+
lazy="selectin",
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
__table_args__ = (
|
|
91
|
+
UniqueConstraint(
|
|
92
|
+
"dataset_id", "target_id", name="uq_feature_selection_composite"
|
|
93
|
+
),
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
@with_db
|
|
97
|
+
def add_features(self, features: list, db=None):
|
|
98
|
+
self = db.merge(self)
|
|
99
|
+
for feature in features:
|
|
100
|
+
feature = db.merge(feature)
|
|
101
|
+
if feature not in self.features:
|
|
102
|
+
self.features.append(feature)
|
|
103
|
+
# db.flush()
|
|
104
|
+
# db.refresh(self)
|
|
105
|
+
return self
|
|
106
|
+
|
|
107
|
+
@with_db
|
|
108
|
+
def __lshift__(self, feature_or_list, db=None):
|
|
109
|
+
items = (
|
|
110
|
+
feature_or_list
|
|
111
|
+
if isinstance(feature_or_list, Iterable)
|
|
112
|
+
and not isinstance(feature_or_list, (str, bytes))
|
|
113
|
+
else [feature_or_list]
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
self = db.merge(self)
|
|
117
|
+
for feature in items:
|
|
118
|
+
feature = db.merge(feature)
|
|
119
|
+
if feature not in self.features:
|
|
120
|
+
self.features.append(feature)
|
|
121
|
+
|
|
122
|
+
db.flush()
|
|
123
|
+
db.refresh(self)
|
|
124
|
+
print(self.features)
|
|
125
|
+
return self
|
|
@@ -0,0 +1,79 @@
|
|
|
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 lecrapaud.db.session import get_db
|
|
22
|
+
from lecrapaud.db.models.base import Base, with_db
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class FeatureSelectionRank(Base):
|
|
26
|
+
__tablename__ = "feature_selection_ranks"
|
|
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
|
+
score = Column(Float)
|
|
39
|
+
pvalue = Column(Float)
|
|
40
|
+
support = Column(Integer)
|
|
41
|
+
rank = Column(Integer)
|
|
42
|
+
method = Column(String(50))
|
|
43
|
+
training_time = Column(Integer)
|
|
44
|
+
feature_id = Column(BigInteger, ForeignKey("features.id", ondelete="CASCADE"))
|
|
45
|
+
feature_selection_id = Column(
|
|
46
|
+
BigInteger, ForeignKey("feature_selections.id", ondelete="CASCADE")
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
feature = relationship("Feature", lazy="selectin")
|
|
50
|
+
feature_selection = relationship(
|
|
51
|
+
"FeatureSelection", back_populates="feature_selection_ranks", lazy="selectin"
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
__table_args__ = (
|
|
55
|
+
UniqueConstraint(
|
|
56
|
+
"feature_id",
|
|
57
|
+
"feature_selection_id",
|
|
58
|
+
"method",
|
|
59
|
+
name="uq_feature_selection_rank_composite",
|
|
60
|
+
),
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
@classmethod
|
|
64
|
+
@with_db
|
|
65
|
+
def bulk_upsert(cls, rows, db=None):
|
|
66
|
+
stmt = insert(cls).values(rows)
|
|
67
|
+
|
|
68
|
+
update_fields = {
|
|
69
|
+
key: stmt.inserted[key]
|
|
70
|
+
for key in rows[0]
|
|
71
|
+
if key not in ("feature_selection_id", "feature_id", "method")
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
stmt = stmt.on_duplicate_key_update(**update_fields)
|
|
75
|
+
|
|
76
|
+
db.execute(stmt)
|
|
77
|
+
db.commit()
|
|
78
|
+
|
|
79
|
+
return len(rows)
|
|
@@ -0,0 +1,40 @@
|
|
|
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 lecrapaud.db.session import get_db
|
|
21
|
+
from lecrapaud.db.models.base import Base
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Model(Base):
|
|
25
|
+
__tablename__ = "models"
|
|
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
|
+
name = Column(String(50), nullable=False)
|
|
38
|
+
type = Column(String(50), nullable=False)
|
|
39
|
+
|
|
40
|
+
__table_args__ = (UniqueConstraint("name", "type", name="uq_model_composite"),)
|
|
@@ -0,0 +1,63 @@
|
|
|
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 lecrapaud.db.session import get_db
|
|
21
|
+
from lecrapaud.db.models.base import Base
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ModelSelection(Base):
|
|
25
|
+
__tablename__ = "model_selections"
|
|
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
|
+
best_model_params = Column(JSON)
|
|
38
|
+
best_model_path = Column(String(255))
|
|
39
|
+
best_model_id = Column(BigInteger, ForeignKey("models.id", ondelete="CASCADE"))
|
|
40
|
+
target_id = Column(
|
|
41
|
+
BigInteger, ForeignKey("targets.id", ondelete="CASCADE"), nullable=False
|
|
42
|
+
)
|
|
43
|
+
dataset_id = Column(
|
|
44
|
+
BigInteger, ForeignKey("datasets.id", ondelete="CASCADE"), nullable=False
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
best_model = relationship("Model", lazy="selectin")
|
|
48
|
+
model_trainings = relationship(
|
|
49
|
+
"ModelTraining",
|
|
50
|
+
back_populates="model_selection",
|
|
51
|
+
cascade="all, delete-orphan",
|
|
52
|
+
lazy="selectin",
|
|
53
|
+
)
|
|
54
|
+
dataset = relationship(
|
|
55
|
+
"Dataset", back_populates="model_selections", lazy="selectin"
|
|
56
|
+
)
|
|
57
|
+
target = relationship("Target", back_populates="model_selections", lazy="selectin")
|
|
58
|
+
|
|
59
|
+
__table_args__ = (
|
|
60
|
+
UniqueConstraint(
|
|
61
|
+
"target_id", "dataset_id", name="uq_model_selection_composite"
|
|
62
|
+
),
|
|
63
|
+
)
|
|
@@ -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
|
+
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 lecrapaud.db.session import get_db
|
|
21
|
+
from lecrapaud.db.models.base import Base
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ModelTraining(Base):
|
|
25
|
+
__tablename__ = "model_trainings"
|
|
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
|
+
best_params = Column(JSON)
|
|
38
|
+
model_path = Column(String(255))
|
|
39
|
+
training_time = Column(Integer)
|
|
40
|
+
model_id = Column(BigInteger, ForeignKey("models.id"), nullable=False)
|
|
41
|
+
model_selection_id = Column(
|
|
42
|
+
BigInteger,
|
|
43
|
+
ForeignKey("model_selections.id", ondelete="CASCADE"),
|
|
44
|
+
nullable=False,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
model = relationship("Model", lazy="selectin")
|
|
48
|
+
model_selection = relationship(
|
|
49
|
+
"ModelSelection", back_populates="model_trainings", lazy="selectin"
|
|
50
|
+
)
|
|
51
|
+
score = relationship(
|
|
52
|
+
"Score",
|
|
53
|
+
back_populates="model_trainings",
|
|
54
|
+
cascade="all, delete-orphan",
|
|
55
|
+
lazy="selectin",
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
__table_args__ = (
|
|
59
|
+
UniqueConstraint(
|
|
60
|
+
"model_id", "model_selection_id", name="uq_model_training_composite"
|
|
61
|
+
),
|
|
62
|
+
)
|
|
@@ -0,0 +1,65 @@
|
|
|
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 lecrapaud.db.session import get_db
|
|
20
|
+
from lecrapaud.db.models.base import Base
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Score(Base):
|
|
24
|
+
__tablename__ = "scores"
|
|
25
|
+
|
|
26
|
+
id = Column(BigInteger, primary_key=True, index=True, autoincrement=True)
|
|
27
|
+
created_at = Column(
|
|
28
|
+
TIMESTAMP(timezone=True), server_default=func.now(), nullable=False
|
|
29
|
+
)
|
|
30
|
+
updated_at = Column(
|
|
31
|
+
TIMESTAMP(timezone=True),
|
|
32
|
+
server_default=func.now(),
|
|
33
|
+
onupdate=func.now(),
|
|
34
|
+
nullable=False,
|
|
35
|
+
)
|
|
36
|
+
type = Column(
|
|
37
|
+
String(50), nullable=False
|
|
38
|
+
) # either hyperopts or validation or crossval
|
|
39
|
+
training_time = Column(Integer)
|
|
40
|
+
eval_data_std = Column(Float)
|
|
41
|
+
rmse = Column(Float)
|
|
42
|
+
rmse_std_ratio = Column(Float)
|
|
43
|
+
mae = Column(Float)
|
|
44
|
+
mape = Column(Float)
|
|
45
|
+
mam = Column(Float)
|
|
46
|
+
mad = Column(Float)
|
|
47
|
+
mae_mam_ratio = Column(Float)
|
|
48
|
+
mae_mad_ratio = Column(Float)
|
|
49
|
+
r2 = Column(Float)
|
|
50
|
+
logloss = Column(Float)
|
|
51
|
+
accuracy = Column(Float)
|
|
52
|
+
precision = Column(Float)
|
|
53
|
+
recall = Column(Float)
|
|
54
|
+
f1 = Column(Float)
|
|
55
|
+
roc_auc = Column(Float)
|
|
56
|
+
threshold = Column(Float)
|
|
57
|
+
precision_at_threshold = Column(Float)
|
|
58
|
+
recall_at_threshold = Column(Float)
|
|
59
|
+
model_training_id = Column(
|
|
60
|
+
BigInteger, ForeignKey("model_trainings.id", ondelete="CASCADE"), nullable=False
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
model_trainings = relationship(
|
|
64
|
+
"ModelTraining", back_populates="score", lazy="selectin"
|
|
65
|
+
)
|
|
@@ -0,0 +1,67 @@
|
|
|
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 lecrapaud.db.session import get_db
|
|
21
|
+
from lecrapaud.db.models.base import Base
|
|
22
|
+
from lecrapaud.db.models.dataset import dataset_target_association
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Target(Base):
|
|
26
|
+
__tablename__ = "targets"
|
|
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
|
+
description = Column(String(255))
|
|
41
|
+
|
|
42
|
+
datasets = relationship(
|
|
43
|
+
"Dataset",
|
|
44
|
+
secondary=dataset_target_association,
|
|
45
|
+
back_populates="targets",
|
|
46
|
+
lazy="selectin",
|
|
47
|
+
)
|
|
48
|
+
feature_selections = relationship(
|
|
49
|
+
"FeatureSelection",
|
|
50
|
+
back_populates="target",
|
|
51
|
+
cascade="all, delete-orphan",
|
|
52
|
+
lazy="selectin",
|
|
53
|
+
)
|
|
54
|
+
model_selections = relationship(
|
|
55
|
+
"ModelSelection",
|
|
56
|
+
back_populates="target",
|
|
57
|
+
cascade="all, delete-orphan",
|
|
58
|
+
lazy="selectin",
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
__table_args__ = (
|
|
62
|
+
UniqueConstraint(
|
|
63
|
+
"name",
|
|
64
|
+
"type",
|
|
65
|
+
name="uq_target_composite",
|
|
66
|
+
),
|
|
67
|
+
)
|