sinapsis-data-analysis 0.1.10__py3-none-any.whl → 0.1.12__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.
@@ -24,3 +24,4 @@ excluded_neighbors_models = [
24
24
  "LocalOutlierFactor",
25
25
  ]
26
26
  excluded_tree_models = ["plot_tree", "export_text", "export_graphviz", "BaseDecisionTree"]
27
+ excluded_svm_models = ["l1_min_c"]
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ import os
2
3
  from abc import abstractmethod
3
4
  from typing import Any
4
5
 
@@ -6,6 +7,7 @@ import numpy as np
6
7
  from sinapsis_core.data_containers.data_packet import DataContainer
7
8
  from sinapsis_core.template_base.base_models import TemplateAttributes
8
9
  from sinapsis_core.template_base.template import Template
10
+ from sinapsis_core.utils.env_var_keys import SINAPSIS_CACHE_DIR
9
11
 
10
12
 
11
13
  class MLBaseInference(Template):
@@ -24,11 +26,12 @@ class MLBaseInference(Template):
24
26
  """
25
27
 
26
28
  model_path: str
29
+ root_dir : str = SINAPSIS_CACHE_DIR
27
30
  generic_field_key: str
28
31
 
29
32
  def __init__(self, attributes: TemplateAttributes) -> None:
30
33
  super().__init__(attributes)
31
- self.model = self.load_model(self.attributes.model_path)
34
+
32
35
 
33
36
  def get_data(self, container: DataContainer) -> Any:
34
37
  """Get the data from the data container
@@ -111,7 +114,8 @@ class MLBaseInference(Template):
111
114
  if not self.data_is_valid(data):
112
115
  self.logger.warning("Invalid or missing data")
113
116
  return container
114
-
117
+ full_path = os.path.join(self.attributes.root_dir, self.attributes.model_path)
118
+ self.model = self.load_model(full_path)
115
119
  data = self.preprocess_data(data)
116
120
  predictions = self.predict(data)
117
121
 
@@ -34,7 +34,7 @@ class MLBaseAttributes(TemplateAttributes):
34
34
  model_save_path (str): Path where the trained model will be saved.
35
35
  """
36
36
 
37
- generic_field_key: str
37
+ generic_field_key: str | None = None
38
38
  root_dir : str = WORKING_DIR
39
39
  model_save_path: str
40
40
 
@@ -220,13 +220,13 @@ class MLBaseTraining(BaseDynamicWrapperTemplate):
220
220
  full_path = os.path.join(self.attributes.root_dir, self.attributes.model_save_path)
221
221
  try:
222
222
  os.makedirs(os.path.dirname(full_path), exist_ok=True)
223
- self._save_model_implementation()
223
+ self._save_model_implementation(full_path)
224
224
  self.logger.info(f"Model saved at {self.attributes.model_save_path}")
225
225
  except (MemoryError, TypeError) as e:
226
226
  self.logger.error(f"Error saving model: {e}")
227
227
 
228
228
  @abstractmethod
229
- def _save_model_implementation(self) -> None:
229
+ def _save_model_implementation(self, full_path: str) -> None:
230
230
  """Save the trained model using an implementation-specific method.
231
231
 
232
232
  This abstract method should be implemented by subclasses to define
@@ -5,11 +5,12 @@ from sinapsis_core.template_base.base_models import UIPropertiesMetadata
5
5
  from sinapsis_core.template_base.dynamic_template import WrapperEntryConfig
6
6
  from sinapsis_core.template_base.dynamic_template_factory import make_dynamic_template
7
7
  from sinapsis_core.utils.env_var_keys import SINAPSIS_BUILD_DOCS
8
- from sklearn import linear_model, neighbors, neural_network, tree
8
+ from sklearn import linear_model, neighbors, neural_network, svm, tree
9
9
 
10
10
  from sinapsis_data_analysis.helpers.excluded_models import (
11
11
  excluded_linear_models,
12
12
  excluded_neighbors_models,
13
+ excluded_svm_models,
13
14
  excluded_tree_models,
14
15
  )
15
16
  from sinapsis_data_analysis.helpers.tags import Tags
@@ -53,12 +54,12 @@ class SKLearnLinearModelsTrain(MLBaseTraining):
53
54
  category="SKLearn", tags=[Tags.DATA_ANALYSIS, Tags.LINEAR_REGRESSION, Tags.MODELS, Tags.SKLEARN, Tags.TRAINING]
54
55
  )
55
56
 
56
- def _save_model_implementation(self) -> None:
57
+ def _save_model_implementation(self, full_path:str) -> None:
57
58
  """
58
59
  Implements the abstract method from the base class to
59
60
  save the model to the path specified in attributes.
60
61
  """
61
- joblib.dump(self.trained_model, self.attributes.model_save_path)
62
+ joblib.dump(self.trained_model, full_path)
62
63
 
63
64
 
64
65
  class SKLearnNeighborsModelsTrain(SKLearnLinearModelsTrain):
@@ -177,6 +178,41 @@ class SKLearnTreeModelsTrain(SKLearnLinearModelsTrain):
177
178
  )
178
179
 
179
180
 
181
+ class SKLearnSVMModelsTrain(SKLearnLinearModelsTrain):
182
+ """
183
+ This template dynamically wraps sklearn's svm module,
184
+ providing access to models like SVC, SVR, LinearSVC,
185
+ LinearSVR, NuSVC, NuSVR, and OneClassSVM.
186
+
187
+ Usage example:
188
+
189
+ agent:
190
+ name: my_test_agent
191
+ templates:
192
+ - template_name: InputTemplate
193
+ class_name: InputTemplate
194
+ attributes: {}
195
+ - template_name: SVCWrapper
196
+ class_name: SVCWrapper
197
+ template_input: DataLoaderTemplate
198
+ attributes:
199
+ generic_field_key: 'data_loader_key'
200
+ model_save_path: 'artifacts/svc_model.joblib'
201
+ svc_init:
202
+ C: 1.0
203
+ kernel: rbf
204
+ random_state: 42
205
+
206
+ """
207
+
208
+ WrapperEntry = WrapperEntryConfig(
209
+ wrapped_object=svm,
210
+ signature_from_doc_string=True,
211
+ exclude_module_atts=excluded_svm_models,
212
+ force_init_as_method=False,
213
+ )
214
+
215
+
180
216
  def __getattr__(name: str) -> Template:
181
217
  """
182
218
  Only create a template if it's imported, this avoids creating all the base models for all templates
@@ -190,6 +226,8 @@ def __getattr__(name: str) -> Template:
190
226
  return make_dynamic_template(name, SKLearnNNModelsTrain)
191
227
  if name in SKLearnTreeModelsTrain.WrapperEntry.module_att_names:
192
228
  return make_dynamic_template(name, SKLearnTreeModelsTrain)
229
+ if name in SKLearnSVMModelsTrain.WrapperEntry.module_att_names:
230
+ return make_dynamic_template(name, SKLearnSVMModelsTrain)
193
231
  raise AttributeError(f"template `{name}` not found in {__name__}")
194
232
 
195
233
 
@@ -198,6 +236,7 @@ __all__ = (
198
236
  + SKLearnNeighborsModelsTrain.WrapperEntry.module_att_names
199
237
  + SKLearnNNModelsTrain.WrapperEntry.module_att_names
200
238
  + SKLearnTreeModelsTrain.WrapperEntry.module_att_names
239
+ + SKLearnSVMModelsTrain.WrapperEntry.module_att_names
201
240
  )
202
241
 
203
242
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sinapsis-data-analysis
3
- Version: 0.1.10
3
+ Version: 0.1.12
4
4
  Summary: Templates to work with models for classification, regression and clustering with xgboost and sklearn.
5
5
  Author-email: SinapsisAI <dev@sinapsis.tech>
6
6
  Project-URL: Homepage, https://sinapsis.tech
@@ -68,6 +68,7 @@ The following model types are supported:
68
68
  - **Linear Models**: LinearRegression, Ridge, Lasso, ElasticNet, LogisticRegression, etc.
69
69
  - **Neighbors Models**: KNeighborsClassifier, KNeighborsRegressor, RadiusNeighborsClassifier, etc.
70
70
  - **Neural Network Models**: MLPClassifier, MLPRegressor, BernoulliRBM
71
+ - **SVM Models**: SVC, SVR, LinearSVC, LinearSVR, NuSVC, NuSVR, OneClassSVM, etc.
71
72
  - **Tree Models**: DecisionTreeClassifier, DecisionTreeRegressor, ExtraTreeClassifier, etc.
72
73
 
73
74
  Each template uses the same base attributes:
@@ -1,18 +1,18 @@
1
1
  sinapsis_data_analysis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  sinapsis_data_analysis/helpers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- sinapsis_data_analysis/helpers/excluded_models.py,sha256=gVrTRBdktM3eoBxd7kX22xHlQQS3jPklCdxhisPwsc8,651
3
+ sinapsis_data_analysis/helpers/excluded_models.py,sha256=_95yGsYEiDYXfV5gBlJ1L2XGR1_MebvBS9mGYNy8X2A,686
4
4
  sinapsis_data_analysis/helpers/model_metrics.py,sha256=mR-ZLD8PrGgOh1PrYG8TOjFhJz6l2EDRtn6jtMMyI7A,729
5
5
  sinapsis_data_analysis/helpers/tags.py,sha256=ICJNmbNAtwn5BfMvGHh6eLuq5Ro3hCIbwd-Y63qOmC0,372
6
6
  sinapsis_data_analysis/templates/__init__.py,sha256=z1-E6V4f6MqoGY0_cPwSurDpXDdMOAEOvSS4ogrl1DM,840
7
- sinapsis_data_analysis/templates/ml_base_inference.py,sha256=CMAebWYKAyNWWdJFEc4zAjFH5z5RlEbsunvYhlunYno,3467
8
- sinapsis_data_analysis/templates/ml_base_training.py,sha256=3-YfNie6kyWHmpn9Dn2okfpOoGQsjY1iH-a3hwxt5aw,9325
7
+ sinapsis_data_analysis/templates/ml_base_inference.py,sha256=3QfMH8w4yNCnEFZeJOOO3HZAC75UjJL2P6R4aN06f9g,3655
8
+ sinapsis_data_analysis/templates/ml_base_training.py,sha256=m2yDuR9C7lfN1jT31fTQsn3c4fN0Gtx5jd8MtaemUqw,9364
9
9
  sinapsis_data_analysis/templates/sklearn_inference.py,sha256=rf-HsWYE4_g9KM_BZbP3f2jKyKz_MLj9-eZ1CAGHqp8,931
10
10
  sinapsis_data_analysis/templates/sklearn_manifold.py,sha256=whYTvwDnVacSh4N2XBXVgn8O1dG-KnQsx6htm5DFEbQ,5519
11
- sinapsis_data_analysis/templates/sklearn_train.py,sha256=WIF7DIslVIRHCmDAXfVUZkiVtLRPRbg6Snq0Di7Ln3w,6757
11
+ sinapsis_data_analysis/templates/sklearn_train.py,sha256=4b4w2IxoF4ZdYqB1zM9PmMqb7TN8hVvoOtpkPoQTiUc,7870
12
12
  sinapsis_data_analysis/templates/xgboost_inference.py,sha256=rFk44jHFCr-EuqDg74TInjlHDCstvA0V422gQmgbd0I,1028
13
13
  sinapsis_data_analysis/templates/xgboost_train.py,sha256=VQSztloGAW4Xcx8MZCoRKdqa5jn4NL857jHTeMRuMwA,2513
14
- sinapsis_data_analysis-0.1.10.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
15
- sinapsis_data_analysis-0.1.10.dist-info/METADATA,sha256=4LiJ3H5ka3Ocimbxt4F52ohKG2yjgbMVoyOoSzSlcbM,6297
16
- sinapsis_data_analysis-0.1.10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
- sinapsis_data_analysis-0.1.10.dist-info/top_level.txt,sha256=Mc5OyqBINgXFLrAyVBmjg25MQd6Lbg7z-rwotzEeygQ,23
18
- sinapsis_data_analysis-0.1.10.dist-info/RECORD,,
14
+ sinapsis_data_analysis-0.1.12.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
15
+ sinapsis_data_analysis-0.1.12.dist-info/METADATA,sha256=k0XwPqShVMV8NhFa4fAMK4-gObfpENHXzd_i2xHonIY,6379
16
+ sinapsis_data_analysis-0.1.12.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
17
+ sinapsis_data_analysis-0.1.12.dist-info/top_level.txt,sha256=Mc5OyqBINgXFLrAyVBmjg25MQd6Lbg7z-rwotzEeygQ,23
18
+ sinapsis_data_analysis-0.1.12.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5