wizata-dsapi 1.3.20__py3-none-any.whl → 1.3.23__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.
@@ -2,7 +2,7 @@
2
2
  from .plot import Plot
3
3
  from .datapoint import DataPoint
4
4
  from .datastore import DataStore
5
- from .mlmodel import MLModel
5
+ from .mlmodel import ModelInfo, ModelList
6
6
  from .request import Request
7
7
  from .execution import Execution, ExecutionStatus
8
8
  from .experiment import Experiment
@@ -76,12 +76,6 @@ _registry = {
76
76
  "cloud_dsapi": ['lists', 'get_by_id', 'create', 'update', 'delete', 'search'],
77
77
  "cloud_context": ['get_by_id', 'create', 'update', 'delete', 'search']
78
78
  },
79
- "mlmodels":
80
- {
81
- "class": MLModel,
82
- "cloud_dsapi": ['lists', 'get_by_id', 'get_by_key', 'delete'],
83
- "cloud_context": []
84
- },
85
79
  "pipelines":
86
80
  {
87
81
  "class": Pipeline,
@@ -3,7 +3,6 @@ import uuid
3
3
  import pandas
4
4
  import time
5
5
 
6
- from .mlmodel import MLModel
7
6
  from .script import Script
8
7
  from .plot import Plot
9
8
  from .wizard_function import WizardStep, WizardFunction
@@ -15,20 +14,6 @@ class DSAPIEncoder(json.JSONEncoder):
15
14
  def default(self, obj):
16
15
  if isinstance(obj, uuid.UUID):
17
16
  return str(obj)
18
- if isinstance(obj, MLModel):
19
- json_obj = {
20
- "id": str(obj.model_id),
21
- "status": str(obj.status),
22
- "generatedById": str(obj.generatedById),
23
- "input_columns": list(obj.input_columns),
24
- "output_columns": list(obj.output_columns),
25
- "has_anomalies": str(obj.has_anomalies),
26
- "labels_count": str(obj.label_counts),
27
- "has_target_feat": str(obj.has_target_feat),
28
- "needExactColumnNames": str(obj.needExactColumnNames),
29
- "needExactColumnNumbers": str(obj.needExactColumnNumbers)
30
- }
31
- return json_obj
32
17
  if isinstance(obj, Script):
33
18
  json_obj = {
34
19
  "id": str(obj.script_id),
wizata_dsapi/mlmodel.py CHANGED
@@ -12,25 +12,40 @@ def get_bool(obj, name: str):
12
12
  class ModelInfo:
13
13
  """
14
14
  define a pointer to a machine learning model.
15
+
16
+ :ivar model_type str: mlflow model flavour
15
17
  """
16
18
 
17
19
  def __init__(self,
18
20
  key: str,
19
21
  twin_hardware_id: str = None,
20
- property_name: str = None,
22
+ property_value: str = None,
21
23
  alias: str = None,
24
+ model_type: str = None,
22
25
  file_format: str = 'pkl',
23
- source: str = 'wizata'
26
+ source: str = 'wizata',
27
+ property_name: str = None
24
28
  ):
29
+ # information identifying a model
25
30
  self.key = key
26
31
  self.twin_hardware_id = twin_hardware_id
27
- self.property_name = property_name
32
+ self.property_value = property_value
28
33
  self.alias = alias
29
34
  self.file_format = file_format
30
35
  self.source = source
36
+ self.model_type = model_type
37
+
38
+ # files attached to model when loaded
31
39
  self.trained_model = None
32
40
  self.scaler = None
33
41
 
42
+ # temporary properties during model generation not generally stored
43
+ self.property_name = property_name
44
+ self.input_columns = None
45
+ self.has_target_feat = False
46
+ self.label_counts = 0
47
+
48
+
34
49
  def identifier(self, include_alias: bool = False) -> str:
35
50
  """
36
51
  returns the complete string identifier for this model.
@@ -44,8 +59,8 @@ class ModelInfo:
44
59
  if self.twin_hardware_id is not None:
45
60
  identifier += f".{self.twin_hardware_id}"
46
61
 
47
- if self.property_name is not None:
48
- identifier += f".{self.property_name}"
62
+ if self.property_value is not None:
63
+ identifier += f".{self.property_value}"
49
64
 
50
65
  if include_alias and self.alias is not None:
51
66
  identifier += f"@{self.alias}"
@@ -64,14 +79,18 @@ class ModelInfo:
64
79
  }
65
80
  if self.twin_hardware_id is not None:
66
81
  obj["twin_hardware_id"] = str(self.twin_hardware_id)
67
- if self.property_name is not None:
68
- obj["property_name"] = self.property_name
82
+ if self.property_value is not None:
83
+ obj["property_value"] = self.property_value
69
84
  if self.alias is not None:
70
85
  obj["alias"] = self.alias
86
+ if self.model_type is not None:
87
+ obj["model_type"] = self.model_type
71
88
  if self.file_format is not None:
72
89
  obj["file_format"] = self.file_format
73
90
  if self.source is not None:
74
91
  obj["source"] = self.source
92
+ if self.property_name is not None:
93
+ obj["property_name"] = self.property_name
75
94
  return obj
76
95
 
77
96
  def from_json(self, obj):
@@ -82,14 +101,18 @@ class ModelInfo:
82
101
  self.key = obj["key"]
83
102
  if "twin_hardware_id" in obj.keys():
84
103
  self.twin_hardware_id = obj["twin_hardware_id"]
85
- if "property_name" in obj.keys():
86
- self.property_name = obj["property_name"]
104
+ if "property_value" in obj.keys():
105
+ self.property_name = obj["property_value"]
87
106
  if "alias" in obj.keys():
88
107
  self.alias = obj["alias"]
108
+ if "model_type" in obj.keys():
109
+ self.model_type = obj["model_type"]
89
110
  if "file_format" in obj.keys():
90
111
  self.key = obj["file_format"]
91
112
  if "source" in obj.keys():
92
113
  self.source = obj["source"]
114
+ if "property_name" in obj.keys():
115
+ self.property_name = obj["property_name"]
93
116
 
94
117
 
95
118
  class ModelList:
@@ -186,19 +209,28 @@ class MLModelConfig(ApiDto):
186
209
  self.model_type = model_type
187
210
  self.model_alias = model_alias
188
211
 
189
- def create_model_info(self, hardware_id: str = None) -> ModelInfo:
212
+ def create_model_info(self,
213
+ hardware_id: str = None,
214
+ property_value: str = None) -> ModelInfo:
190
215
  """
191
216
  create model info corresponding to the configuration.
192
217
  :param hardware_id: provide a hardware id for this model if by_twin.
218
+ :param property_value: provide a value for this model if by_property.
193
219
  :return:
194
220
  """
221
+ if self.by_twin and hardware_id is None:
222
+ raise ValueError('hardware_id is required if by_twin to create a model info')
223
+ if self.by_property and property_value is None:
224
+ raise ValueError('property_value is required if by_property to create a model info')
195
225
  model_info = ModelInfo(
196
226
  key=self.model_key,
197
227
  twin_hardware_id=hardware_id,
198
- property_name=self.property_name,
228
+ property_value=property_value,
199
229
  source=self.source,
200
230
  alias=self.model_alias,
201
- file_format=self.model_format
231
+ file_format=self.model_format,
232
+ model_type=self.model_type,
233
+ property_name=self.property_name
202
234
  )
203
235
  return model_info
204
236
 
@@ -1,28 +1,28 @@
1
1
  import pandas
2
- from .mlmodel import MLModel
2
+ from .mlmodel import ModelInfo
3
3
 
4
4
 
5
- def predict(df: pandas.DataFrame, ml_model: MLModel, mapping_table=None):
5
+ def predict(df: pandas.DataFrame, model_info: ModelInfo, mapping_table=None):
6
6
  """
7
7
  Execute a Machine Learning models locally.
8
8
  :param df: dataframe to use as input.
9
- :param ml_model: trained machine learning model.
9
+ :param model_info: model information handler.
10
10
  :param mapping_table: Optional mapping table.
11
11
  :return: output dataframe with predicted values.
12
12
  """
13
- if ml_model is None or ml_model.trained_model is None or ml_model.input_columns is None:
13
+ if model_info is None or model_info.trained_model is None or model_info.input_columns is None:
14
14
  raise ValueError("Please download your model from DS API before using it.")
15
15
  old_index = df.index
16
16
  df.index = pandas.to_datetime(df.index)
17
17
  df_result = pandas.DataFrame(index=df.index)
18
- features = ml_model.input_columns
19
- if ml_model.has_target_feat is True:
20
- df_result['result'] = ml_model.trained_model.detect(df[features]).astype(float)
18
+ features = model_info.input_columns
19
+ if model_info.has_target_feat is True:
20
+ df_result['result'] = model_info.trained_model.detect(df[features]).astype(float)
21
21
  else:
22
- df_result['result'] = ml_model.trained_model.predict(df[features]).astype(float)
23
- if ml_model.label_counts != 0:
24
- df_result[__generate_label_columns(ml_model.label_counts)] = \
25
- ml_model.trained_model.predict_proba(df[features]).astype(float)
22
+ df_result['result'] = model_info.trained_model.predict(df[features]).astype(float)
23
+ if model_info.label_counts != 0:
24
+ df_result[__generate_label_columns(model_info.label_counts)] = \
25
+ model_info.trained_model.predict_proba(df[features]).astype(float)
26
26
  df_result = df_result.set_index(old_index)
27
27
  return df_result
28
28
 
@@ -3,7 +3,7 @@ import json
3
3
  from .api_dto import ApiDto
4
4
  from .pipeline import Pipeline
5
5
  from .script import Script
6
- from .mlmodel import MLModel
6
+ from .mlmodel import ModelInfo
7
7
  from datetime import datetime
8
8
 
9
9
  import pytz
wizata_dsapi/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "1.3.20"
1
+ __version__ = "1.3.23"
@@ -23,7 +23,7 @@ from .api_dto import ApiDto, VarType
23
23
  from .business_label import BusinessLabel
24
24
  from .plot import Plot
25
25
  from .request import Request
26
- from .mlmodel import MLModel
26
+ from .mlmodel import ModelInfo, ModelList
27
27
  from .experiment import Experiment
28
28
  from .script import Script
29
29
  from .execution import Execution, ExecutionStatus
@@ -590,15 +590,6 @@ class WizataDSAPIClient(ApiInterface):
590
590
  return obj.script_id
591
591
  else:
592
592
  raise self.__raise_error(response)
593
- if isinstance(obj, MLModel):
594
- response = requests.put(self.__url() + "mlmodels/",
595
- headers=self.__header(),
596
- data=pickle.dumps(obj))
597
- if response.status_code == 200:
598
- obj.model_id = uuid.UUID(response.json()['id'])
599
- return obj.model_id
600
- else:
601
- raise self.__raise_error(response)
602
593
  if isinstance(obj, Template):
603
594
  return self.upsert_template(obj.key, obj.name)
604
595
  if isinstance(obj, Pipeline):
@@ -847,13 +838,6 @@ class WizataDSAPIClient(ApiInterface):
847
838
  execution.script = self.get(script_name=script)
848
839
  elif isinstance(script, Script):
849
840
  execution.script = script
850
- if ml_model is not None:
851
- if isinstance(ml_model, uuid.UUID) or (isinstance(ml_model, str) and is_valid_uuid(ml_model)):
852
- execution.ml_model = MLModel(ml_model)
853
- elif isinstance(ml_model, str):
854
- execution.ml_model = self.get(model_key=ml_model)
855
- elif isinstance(ml_model, MLModel):
856
- execution.ml_model = ml_model
857
841
  if image is not None:
858
842
  execution.pipeline_image_id = image
859
843
  if isAnomalyDetection:
@@ -899,9 +883,6 @@ class WizataDSAPIClient(ApiInterface):
899
883
  if "plots" in obj.keys():
900
884
  for plot in obj["plots"]:
901
885
  result_execution.plots.append(self.get(Plot(plot_id=plot["id"])))
902
- if "models" in obj.keys():
903
- for mlmodel in obj["models"]:
904
- result_execution.models.append(self.get(MLModel(model_id=mlmodel["id"])))
905
886
  if "resultDataframe" in obj.keys() and obj["resultDataframe"]["id"] is not None:
906
887
  result_execution.output_ds_dataframe = self.get(DSDataFrame(df_id=obj["resultDataframe"]["id"]))
907
888
 
@@ -1104,7 +1085,7 @@ class WizataDSAPIClient(ApiInterface):
1104
1085
  scaler=None,
1105
1086
  has_anomalies: bool = False,
1106
1087
  has_target_feat: bool = False,
1107
- experiment_key = None) -> tuple[MLModel, pandas.DataFrame]:
1088
+ experiment_key = None) -> tuple[ModelInfo, pandas.DataFrame]:
1108
1089
  """
1109
1090
  Register a Machine Learning model to Wizata.
1110
1091
  Model is tested by the API against a sample dataframe.
@@ -1124,15 +1105,13 @@ class WizataDSAPIClient(ApiInterface):
1124
1105
  elif df is None:
1125
1106
  raise ValueError('A sample dataframe must be provided')
1126
1107
 
1127
- # Create a ML Model object
1128
- ml_model = MLModel()
1108
+ ml_model = ModelInfo(key=model_key)
1129
1109
  ml_model.trained_model = train_model
1130
1110
  if scaler is not None:
1131
1111
  ml_model.scaler = scaler
1132
1112
  ml_model.has_anomalies = has_anomalies
1133
1113
  ml_model.has_target_feat = has_target_feat
1134
1114
  ml_model.input_columns = df.columns
1135
- ml_model.key = model_key
1136
1115
 
1137
1116
  if experiment_key is not None:
1138
1117
  ml_model.experimentId = self.get(experiment_key=experiment_key).experiment_id
@@ -1141,7 +1120,8 @@ class WizataDSAPIClient(ApiInterface):
1141
1120
  result_df = predict(df, ml_model)
1142
1121
  if result_df is not None:
1143
1122
  ml_model.status = "valid"
1144
- self.upsert(ml_model)
1123
+ #TODO: proper method to upload and download from registry to modify this one
1124
+ ## self.upsert(ml_model)
1145
1125
  return ml_model, result_df
1146
1126
  else:
1147
1127
  raise RuntimeError('no dataframe was generated by your model while testing predict capabilities')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wizata_dsapi
3
- Version: 1.3.20
3
+ Version: 1.3.23
4
4
  Summary: Wizata Data Science Toolkit
5
5
  Author: Wizata S.A.
6
6
  Author-email: info@wizata.com
@@ -1,5 +1,5 @@
1
1
  wizata_dsapi/__init__.py,sha256=MPTx3eqYPaHzIBrnrx27xW2xCliPLHjCYn7ar5FYefY,2040
2
- wizata_dsapi/api_config.py,sha256=pyGPyoCrfOFl-C6DlDRdQbQWDG2Y_oB4gvzjh2wYb8w,5300
2
+ wizata_dsapi/api_config.py,sha256=6Pnnv62X_QrTUXaa1MtFZeQaqMUJC-9Y5BW7B4gef10,5139
3
3
  wizata_dsapi/api_dto.py,sha256=-NdaTRvw5jW5xFGpIhY8U0-SdvzW2t6QD26y0UPApU0,2238
4
4
  wizata_dsapi/api_interface.py,sha256=DURk-0ey16T8sV5e2Y2G_YybPEusJvZuY0oD5L7AnXo,10903
5
5
  wizata_dsapi/bucket.py,sha256=Zz9olv-pymikAutGitSuGWrAPiawOTW86JDDHG4ugTc,1150
@@ -9,19 +9,19 @@ wizata_dsapi/dataframe_toolkit.py,sha256=7D8JrhsFSGXeO3mRAd2e2cLmdjbXRjk04IuaMG8
9
9
  wizata_dsapi/datapoint.py,sha256=UUatqzWMwC4ucM6HdeQDWtLS4fGqEsDABCNVmxoP5Hg,14635
10
10
  wizata_dsapi/datastore.py,sha256=BSHZmCSJ679boBA1eCkaWGJCy1CUeipKKGt2jDHzdVo,2663
11
11
  wizata_dsapi/ds_dataframe.py,sha256=Sk2JRUuTRJzko3HosJnbK34STpgSJUlqxLq8w_E5VM4,2089
12
- wizata_dsapi/dsapi_json_encoder.py,sha256=EhY1NA3-UQJ3HFYYbe7bvXb8NuhOvHVMJvXyGvX_T3k,2772
12
+ wizata_dsapi/dsapi_json_encoder.py,sha256=_NJE2IncJCS-juOxV_IQWHq8WpaanKe2aWpGNZNUzyk,2062
13
13
  wizata_dsapi/evaluation.py,sha256=kB61SD66uRBBbKqiES7XZERn77bwhacbyufneSD4s8c,2222
14
14
  wizata_dsapi/execution.py,sha256=JuU8qZDcUZxtCvQwwvM_luwHi18GQ2jbBSxAjc2cSlM,14148
15
15
  wizata_dsapi/experiment.py,sha256=QYQ1CJ-MTWsXq08xYbm5sAp95dRxbPOmGDgaAOoBMDQ,4631
16
16
  wizata_dsapi/group_system.py,sha256=6rUKe0_J3YWACysyBlzuw_TEpKNXgLOMxhpWsNxOzwY,1708
17
17
  wizata_dsapi/ilogger.py,sha256=iYnID-Z-qrYhie26C43404aIuU4_tHSKXbDeQIdo82Q,807
18
18
  wizata_dsapi/insight.py,sha256=ABFZ04DqYxxzqAEfU1tzlTZqqrigM-zN-8Lbetko3g0,6468
19
- wizata_dsapi/mlmodel.py,sha256=vtrMjhvnjZS-PFM9hWAzXA3c862B-qR2qEJS4UtJgo0,14289
20
- wizata_dsapi/model_toolkit.py,sha256=a76ckSuetSKDjEkOl7o49g9oaItdw9iOaPt0JcstmhU,1551
19
+ wizata_dsapi/mlmodel.py,sha256=rsUmkRniFQktXZAiBejdAJQIgnChvi-J_KJJjmifrSI,15681
20
+ wizata_dsapi/model_toolkit.py,sha256=UNyw5CFSgZeXydQFsiDIRTjoMeqIsdyIIuiwumLW5bA,1574
21
21
  wizata_dsapi/paged_query_result.py,sha256=0Iyt2Kd4tvrfthhT-tk9EmSERsbJTaPNON2euHcBn6k,1150
22
22
  wizata_dsapi/pipeline.py,sha256=WDJeOxPZJiYW1qwTNZUm3jom2epIxqrSoiUwcrTF9EE,31300
23
23
  wizata_dsapi/pipeline_deployment.py,sha256=grekBaxUK0EhL9w7lDB8vNuW_wzLnHVm9Mq8Lkbkguk,1722
24
- wizata_dsapi/pipeline_image.py,sha256=M3FOr45dJIAEvsmXPpMD8JZ09k5-YpW9PRYEWJqptcI,5272
24
+ wizata_dsapi/pipeline_image.py,sha256=FUxaDDAOZHG8MA2xpZDoG7m1xbtiRSB8YuLFObUSd8c,5274
25
25
  wizata_dsapi/plot.py,sha256=SPGKFWWYNcRvHcqvvnPIIIBKsd5UwhdsxLW7b2dG2rs,2360
26
26
  wizata_dsapi/request.py,sha256=W4E1BHacQdJiBLPI96yVeHz41rbfFuGrbuw1U60L_DM,27560
27
27
  wizata_dsapi/script.py,sha256=DeEciwVpuCYZetgJCoivw_bYe8ma52WuTaTQ_VkLEcg,12930
@@ -31,10 +31,10 @@ wizata_dsapi/template.py,sha256=wtCRKKk3PchH4RrNgNYlEF_9C6bzZwKIeLyEvgv6Fdo,1370
31
31
  wizata_dsapi/trigger.py,sha256=w3BZYP-L3SUwvaT0oCTanh_Ewn57peZvlt7vxzHv9J8,5129
32
32
  wizata_dsapi/twin.py,sha256=S0DUzQf1smZXZTdXpXZPtkZYCfKIhw53EecCnsl9i4Q,11017
33
33
  wizata_dsapi/twinregistration.py,sha256=Mi6-YuwroiEXc0c1hgrOaphh4hNVoHupxOnXedVtJtE,13377
34
- wizata_dsapi/version.py,sha256=xkU7aW7cKvizjP0w8nXhUrp9VWxt6sXDqExnl-nGWGw,23
34
+ wizata_dsapi/version.py,sha256=EGztvYCGaOWq_edANXRtYB9YDbL4jWFHJI9a0CTSz5Y,23
35
35
  wizata_dsapi/wizard_function.py,sha256=RbM7W7Gf-6Rhp_1dU9DBYkHaciknGAGvuAndhAS_vyo,942
36
36
  wizata_dsapi/wizard_request.py,sha256=v6BaqKLKvTWmUSo0_gda9FabAQz5x_-GOH1Av50GzFo,3762
37
- wizata_dsapi/wizata_dsapi_client.py,sha256=kos_8j47CBXiy6y6b_H2yDUe3aWh76diEmWjCisYKkY,78662
37
+ wizata_dsapi/wizata_dsapi_client.py,sha256=h8iSz7IGbP-Zq9rbqMdq-hTrt16laD1JeaRWPzaLaoo,77695
38
38
  wizata_dsapi/words.py,sha256=tV8CqzCqODZCV7PgBxBF5exBxeF_ya9t5DiUy-cg6Sg,1535
39
39
  wizata_dsapi/models/__init__.py,sha256=O5PHqw8lKILw4apO-MfDxPz73wK0vADD9y3xjuzX7Tw,104
40
40
  wizata_dsapi/models/common.py,sha256=1dTqE80-mFJnUwEdNlJdhJzfZ2N5Kp8Nb3LQ8uwPtLc,3808
@@ -42,8 +42,8 @@ wizata_dsapi/plots/__init__.py,sha256=qgnSFqrjOPur-807M8uh5awIfjM1ZHXUXcAqHc-r2l
42
42
  wizata_dsapi/plots/common.py,sha256=jdPsJqLHBwSKc6dX83BSGPqSRxzIVNHSYO5yI_8sjGk,6568
43
43
  wizata_dsapi/scripts/__init__.py,sha256=hAxiETSQf0qOHde1si1tEAJU48seqEgHrchCzS2-LvQ,80
44
44
  wizata_dsapi/scripts/common.py,sha256=efwq-Rd0lvYljIs3gSFz9izogBD7asOU2cTK-IvHTkM,4244
45
- wizata_dsapi-1.3.20.dist-info/licenses/LICENSE.txt,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
46
- wizata_dsapi-1.3.20.dist-info/METADATA,sha256=AlxEUFMhHXabL0a22dsV8VSxOStL2KwigOTGdIIcKr0,5651
47
- wizata_dsapi-1.3.20.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
48
- wizata_dsapi-1.3.20.dist-info/top_level.txt,sha256=-OeTJbEnh5DuWyTOHtvw0Dw3LRg3G27TNS6W4ZtfwPs,13
49
- wizata_dsapi-1.3.20.dist-info/RECORD,,
45
+ wizata_dsapi-1.3.23.dist-info/licenses/LICENSE.txt,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
46
+ wizata_dsapi-1.3.23.dist-info/METADATA,sha256=s72ozfS_1A5XMtwD2-aeYcGdsPAwaluPyME2GP7s7P8,5651
47
+ wizata_dsapi-1.3.23.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
48
+ wizata_dsapi-1.3.23.dist-info/top_level.txt,sha256=-OeTJbEnh5DuWyTOHtvw0Dw3LRg3G27TNS6W4ZtfwPs,13
49
+ wizata_dsapi-1.3.23.dist-info/RECORD,,