Creates a Python Evaluator,
that executes a Python function provided by the user on a DataFrame connected to its input port. Returns the result metric of the execution as a MetricValue.
The Python function that will be executed must:
be named evaluate
,
take exactly one argument of type DataFrame
,
return a float
.
This operation has an is larger better
that indicates whether the returned metric is better to be maximized or minimized.
It is especially useful in Grid Search operation that searches for the best Estimator using a given metric.
from math import sqrt
from operator import add
def evaluate(dataframe):
# Example Root-Mean-Square Error implementation
n = dataframe.count()
row_to_sq_error = lambda row: (row['label'] - row['prediction'])**2
sum_sq_error = dataframe.map(row_to_sq_error).reduce(add)
rmse = sqrt(sum_sq_error / n)
return rmse
Since: Seahorse 1.2.0
This operation does not take any input.
Port | Type Qualifier | Description |
---|---|---|
0 | Evaluator | An Evaluator that can be used in an Evaluate operation. |
Name | Type | Description |
---|---|---|
metric name |
String |
Name of the metric. |
python evaluator code |
Code Snippet |
The Python code to be executed. It has to contain a Python function complying to signature presented in the operation's description. |
is larger better |
Boolean |
Indicates whether the returned metric is better to be maximized or minimized. |