Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
metric_args = validation.get('metric_args', dict())
if metric:
scorer = get_scorer(metric, metric_args)
else:
scorer = dataset.score
metric = dataset.metric
scores = list()
splits = dataset.get_splits(n_splits)
if n_splits == 1:
splits = [splits]
for split, (X_train, X_test, y_train, y_test) in enumerate(splits):
LOGGER.info('Scoring split %s', split + 1)
context = get_context(dataset, validation.get('context', dict()))
pipeline = MLPipeline.from_dict(pipeline_metadata)
pipeline.fit(X_train, y_train, **context)
predictions = pipeline.predict(X_test, **context)
score = scorer(y_test, predictions)
LOGGER.info('Split %s %s: %s', split + 1, metric, score)
scores.append(score)
return np.mean(scores), np.std(scores)