Skip to content

Commit b648391

Browse files
Add Requirement #13878 - Support Coefficient parameter
1 parent bfca8a0 commit b648391

File tree

4 files changed

+76
-5
lines changed

4 files changed

+76
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
3.0.2 (unreleased)
22
------------------
33

4-
- Nothing changed yet.
4+
- Add Requirement #13878 - Support Coefficient parameter
5+
6+
- Fix Bug #13864 - Fix botocore upload incomplete model, and use boto3 instead.
57

68

79
3.0.1 (2020-04-27)

afs/models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def upload_model(
148148
tags={},
149149
extra_evaluation={},
150150
feature_importance=None,
151+
coefficient=None,
151152
model_repository_name=None,
152153
model_name=None,
153154
blob_mode=True,
@@ -225,8 +226,12 @@ def upload_model(
225226
data = dict(
226227
tags=json.dumps(tags),
227228
evaluation_result=json.dumps(evaluation_result),
228-
feature_importance=json.dumps(feature_importance),
229229
)
230+
if feature_importance:
231+
data.update({'feature_importance': json.dumps(feature_importance)})
232+
if coefficient:
233+
data.update({'coefficient': json.dumps(coefficient)})
234+
230235
if self.afs_version >= '3.1.3':
231236
data.update(
232237
{

docs/Examples.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ feature_importance = [
3636
{'feature': 'sepal_width', 'importance': 0.0033974420712357825}
3737
]
3838
39+
coefficient = [
40+
{'feature': 'B-0070-0068-1-FN66F_strength', 'coefficient': -4.730741400252476},
41+
{'feature': 'B-0070-0068-1-FN66F_vendor', 'coefficient': -0.9335123601234512},
42+
{'feature': 'B-0070-0068-1-FN66F_tensile','coefficient': 0.16411707246054036},
43+
{'feature': 'B-0070-0068-1-FN66F_lot','coefficient': -0.08745686004816221},
44+
{'feature': 'Machine','coefficient': 0.015048547152059243},
45+
{'feature': 'Lot','coefficient': -0.010971975766858174},
46+
{'feature': 'RPM','coefficient': 0.0003730247816832932},
47+
{'feature': 'record_purpose','coefficient': 0.0}
48+
]
49+
50+
3951
# Model object
4052
afs_models = models()
4153
@@ -45,15 +57,17 @@ afs_models = models()
4557
# 3. (optional) extra_evaluation is for other evaluations for the model, you can put them to this parameter.
4658
# 4. (optional) tags is the label for the model, like the time of data or the type of the algorithm.
4759
# 5. (optional) feature_importance is the record how the features important in the model.
60+
# 6. (optional) coefficient indicates the direction of the relationship between a predictor variable and the response variable.
4861
afs_models.upload_model(
4962
model_path='model.h5',
5063
model_repository_name='model.h5',
5164
accuracy=0.4,
5265
loss=0.3,
5366
extra_evaluation=extra_evaluation,
5467
tags=tags,
55-
feature_importance=feature_importance
56-
)
68+
feature_importance=feature_importance,
69+
coefficient=coefficient,
70+
)
5771
5872
# Get the latest model info
5973
model_info = afs_models.get_latest_model_info(model_repository_name='model.h5')
@@ -94,7 +108,16 @@ print(model_info)
94108
'feature': 'sepal_width',
95109
'importance': 0.0033974421
96110
}],
97-
'coefficient': [],
111+
'coefficient': [
112+
{'feature': 'B-0070-0068-1-FN66F_strength', 'coefficient': -4.730741400252476},
113+
{'feature': 'B-0070-0068-1-FN66F_vendor', 'coefficient': -0.9335123601234512},
114+
{'feature': 'B-0070-0068-1-FN66F_tensile','coefficient': 0.16411707246054036},
115+
{'feature': 'B-0070-0068-1-FN66F_lot','coefficient': -0.08745686004816221},
116+
{'feature': 'Machine','coefficient': 0.015048547152059243},
117+
{'feature': 'Lot','coefficient': -0.010971975766858174},
118+
{'feature': 'RPM','coefficient': 0.0003730247816832932},
119+
{'feature': 'record_purpose','coefficient': 0.0}
120+
],
98121
'size': 11,
99122
'created_at': '2020-04-06T10:23:56.228000+00:00'
100123
}

tests/v2/test_models.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,44 @@ def test_create_model_with_datasetid_target(test_env, afs_models, clean_mr, dele
187187
assert "dataset_id" in resp
188188
assert "afs_target" in resp
189189
print(resp)
190+
191+
def test_create_model_with_ft_and_cofficient(test_env, afs_models, clean_mr, delete_mr_and_model, model_file, model_repository_name):
192+
193+
feature_importance = [
194+
{'feature': 'petal_length', 'importance': 0.9473576807512394},
195+
{'feature': 'petal_width', 'importance': 0.038191635936882906},
196+
{'feature': 'sepal_length', 'importance': 0.011053241240641932},
197+
{'feature': 'sepal_width', 'importance': 0.0033974420712357825}
198+
]
199+
200+
coefficient = [
201+
{'feature': 'B-0070-0068-1-FN66F_strength', 'coefficient': -4.730741400252476},
202+
{'feature': 'B-0070-0068-1-FN66F_vendor', 'coefficient': -0.9335123601234512},
203+
{'feature': 'B-0070-0068-1-FN66F_tensile','coefficient': 0.16411707246054036},
204+
{'feature': 'B-0070-0068-1-FN66F_lot','coefficient': -0.08745686004816221},
205+
{'feature': 'Machine','coefficient': 0.015048547152059243},
206+
{'feature': 'Lot','coefficient': -0.010971975766858174},
207+
{'feature': 'RPM','coefficient': 0.0003730247816832932},
208+
{'feature': 'record_purpose','coefficient': 0.0}
209+
]
210+
211+
resp = afs_models.upload_model(
212+
model_path="unit_test_model",
213+
accuracy=1.0,
214+
loss=1.0,
215+
tags={"tag_key": "tag_value"},
216+
extra_evaluation={"extra_loss": 1.23},
217+
feature_importance=feature_importance,
218+
coefficient=coefficient,
219+
model_repository_name=model_repository_name,
220+
model_name="test_model",
221+
)
222+
assert isinstance(resp, dict)
223+
assert "uuid" in resp
224+
assert "name" in resp
225+
assert "created_at" in resp
226+
assert "tags" in resp
227+
assert "evaluation_result" in resp
228+
assert "feature_importance" in resp
229+
assert "coefficient" in resp
230+
print(resp)

0 commit comments

Comments
 (0)