# How to code F1 score?

How to code F1 score?

I find that precision and recall can't be coded by coding AFL Do you know what the TP, FP, and FN values are?

If you can determine those, you should be able to calculate everything.

1 Like

Yes. I know. But I don’t know how to use AFL to code TP, FP, and FN.

Could you show me an example, so that I could set it as an optimization target?

So how would you manually calculate TP, FP, and FN from the OHLC values?

There must be a formula for them. When you have that, we might be able to help.

I have no idea what the F1 score is, but if it can be a mathematical formula from the OHLC values, it can be done in AFL.

1 Like

@snoopy.pa30 these are the symbols frequently used in ML formulas that calculate some common performance metrics.

Unfortunately, @ChriX did not provide any example of his "machine learning" code to classify something available in AmiBroker, so it is not possible to elaborate an answer further.

In any case, he can refer to this old thread where @aron provided some guidance and code samples to apply some ML techniques in AFL.

1 Like

Never say "can't be coded"!

`MxCumVector` is either a row or column vector depending on whether you calculate the sum of either each row or of each column of a `r x c` matrix.

`MxDiag` extracts the diagonal part of a matrix.

`MxMean` calculates mean of rows or the mean of columns of a matrix (in this case the one of column(s)).

F1 Score is at the bottom. 