def _local_fit(row): """ Fit locally a model with a combination of this estimator's param, with overriding parameters provided by the input. :param row: a list or tuple containing index and override_param_map. Index is an int representing the index of parameter map and override_param_map is a dict whose key is a string representing an MLllib Param Name. These are meant to override the base estimator's params. :return: tuple of index, override_param_map and serialized Keras HDF5 file bytes """ index, override_param_map = row # Update params params = baseParamsBc.value params.update(override_param_map) # Create Keras model model = kmutil.bytes_to_model(modelBytesBc.value) model.compile(optimizer=params['kerasOptimizer'], loss=params['kerasLoss']) # Retrieve features and labels and fit Keras model features = localFeaturesBc.value labels = None if localLabelsBc is None else localLabelsBc.value _fit_params = params['kerasFitParams'] model.fit(x=features, y=labels, **_fit_params) return index, override_param_map, kmutil.model_to_bytes(model)
def _local_fit(override_param_map): """ Fit locally a model with a combination of this estimator's param, with overriding parameters provided by the input. :param override_param_map: dict, key type is MLllib Param They are meant to override the base estimator's params. :return: serialized Keras HDF5 file bytes """ # Update params params = baseParamDictBc.value override_param_dict = dict([ (param.name, val) for param, val in override_param_map.items() ]) params.update(override_param_dict) # Create Keras model model = kmutil.bytes_to_model(modelBytesBc.value) model.compile(optimizer=params['kerasOptimizer'], loss=params['kerasLoss']) # Retrieve features and labels and fit Keras model features = localFeaturesBc.value labels = None if localLabelsBc is None else localLabelsBc.value _fit_params = params['kerasFitParams'] model.fit(x=features, y=labels, **_fit_params) return kmutil.model_to_bytes(model)