13
13
import sys
14
14
import warnings
15
15
16
- from deprecated .sphinx import versionchanged
17
-
18
16
from . import utils
19
17
from .core import RestObj , get , get_link , request_link
20
18
from .services import model_management as mm
@@ -130,23 +128,28 @@ def register_model(model, name, project, repository=None, input=None,
130
128
if create_project :
131
129
project = mr .create_project (project , repository )
132
130
133
- model = mr .import_model_from_zip (name , project , zipfile , version = version )
131
+ model = mr .import_model_from_zip (name , project , zipfile ,
132
+ version = version )
134
133
return model
135
134
136
135
# If the model is an scikit-learn model, generate the model dictionary
137
136
# from it and pickle the model for storage
138
- elif all (hasattr (model , attr ) for attr in ['_estimator_type' , 'get_params' ]):
137
+ elif all (hasattr (model , attr ) for attr
138
+ in ['_estimator_type' , 'get_params' ]):
139
139
# Pickle the model so we can store it
140
140
model_pkl = pickle .dumps (model )
141
- files .append ({'name' : 'model.pkl' , 'file' : model_pkl , 'role' : 'Python Pickle' })
141
+ files .append ({'name' : 'model.pkl' ,
142
+ 'file' : model_pkl ,
143
+ 'role' : 'Python Pickle' })
142
144
143
145
# Extract model properties
144
146
model = _sklearn_to_dict (model )
145
147
model ['name' ] = name
146
148
147
149
# Generate PyMAS wrapper
148
150
try :
149
- mas_module = from_pickle (model_pkl , 'predict' , input_types = input , array_input = True )
151
+ mas_module = from_pickle (model_pkl , 'predict' ,
152
+ input_types = input , array_input = True )
150
153
assert isinstance (mas_module , PyMAS )
151
154
152
155
# Include score code files from ESP and MAS
@@ -161,10 +164,9 @@ def register_model(model, name, project, repository=None, input=None,
161
164
for var in mas_module .variables
162
165
if not var .out ]
163
166
164
- model ['outputVariables' ] = [var .as_model_metadata ()
165
- for var in mas_module .variables
166
- if var .out
167
- and var .name not in ('rc' , 'msg' )]
167
+ model ['outputVariables' ] = \
168
+ [var .as_model_metadata () for var in mas_module .variables
169
+ if var .out and var .name not in ('rc' , 'msg' )]
168
170
except ValueError :
169
171
# PyMAS creation failed, most likely because input data wasn't
170
172
# provided
@@ -175,8 +177,14 @@ def register_model(model, name, project, repository=None, input=None,
175
177
assert isinstance (model , dict )
176
178
177
179
if create_project :
178
- vars = model .get ('inputVariables' , []) + model .get ('outputVariables' , [])
179
- target_level = 'Interval' if model .get ('function' ) == 'Regression' else None
180
+ vars = model .get ('inputVariables' , [])
181
+ vars += model .get ('outputVariables' , [])
182
+
183
+ if model .get ('function' ) == 'Regression' :
184
+ target_level = 'Interval'
185
+ else :
186
+ target_level = None
187
+
180
188
project = mr .create_project (project , repository ,
181
189
variables = vars ,
182
190
targetLevel = target_level )
@@ -202,15 +210,17 @@ def publish_model(model, destination, code=None, max_retries=60,
202
210
Parameters
203
211
----------
204
212
model : str or dict
205
- The name or id of the model, or a dictionary representation of the model.
213
+ The name or id of the model, or a dictionary representation of
214
+ the model.
206
215
destination : str
207
216
code : optional
208
217
max_retries : int, optional
209
218
replace : bool, optional
210
219
Whether to overwrite the model if it already exists in
211
220
the `destination`
212
221
kwargs : optional
213
- additional arguments will be passed to the underlying publish functions.
222
+ additional arguments will be passed to the underlying publish
223
+ functions.
214
224
215
225
Returns
216
226
-------
@@ -300,4 +310,3 @@ def submit_request():
300
310
from sasctl .services import microanalytic_score as mas
301
311
return mas .define_steps (module )
302
312
return module
303
-
0 commit comments