File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -167,6 +167,28 @@ def use_feature(self, feature_name):
167167 """
168168 self .get_feature_preprocessing (feature_name )["role" ] = "INPUT"
169169
170+ def use_sample_weighting (self , feature_name ):
171+ """
172+ Uses a feature as sample weight
173+ :param str feature_name: Name of the feature to use
174+ """
175+ self .remove_sample_weighting ()
176+ if not feature_name in self .mltask_settings ["preprocessing" ]["per_feature" ]:
177+ raise ValueError ("Feature %s doesn't exist in this ML task, can't use as weight" % feature_name )
178+ self .mltask_settings ['weight' ]['weightMethod' ] = 'SAMPLE_WEIGHT'
179+ self .mltask_settings ['weight' ]['sampleWeightVariable' ] = feature_name
180+ self .mltask_settings ['preprocessing' ]['per_feature' ][feature_name ]['role' ] = 'WEIGHT'
181+
182+
183+ def remove_sample_weighting (self ):
184+ """
185+ Remove sample weighting. If a feature was used as weight, it's set back to being an input feature
186+ """
187+ self .mltask_settings ['weight' ]['weightMethod' ] = 'NO_WEIGHTING'
188+ for feature_name in self .mltask_settings ['preprocessing' ]['per_feature' ]:
189+ if self .mltask_settings ['preprocessing' ]['per_feature' ][feature_name ]['role' ] == 'WEIGHT' :
190+ self .mltask_settings ['preprocessing' ]['per_feature' ][feature_name ]['role' ] = 'INPUT'
191+
170192 def get_algorithm_settings (self , algorithm_name ):
171193 """
172194 Gets the training settings for a particular algorithm. This returns a reference to the
You can’t perform that action at this time.
0 commit comments