You'd need to make the range references consistent, so if data is in rows 13 to 263 I think the formula should be like this:
=AVERAGE(IF(SUBTOTAL(2,OFFSET(G13,ROW(G13:G263)-ROW(G13),0)),IF(I13:I263=F5,G13:G263)))
That's an "array formula" which needs to be entered in a specific way. Put the formula in the cell and then press F2 to slect formula, hold down CTR and SHIFT keys and press ENTER so that curly braces like { and } appear around the formula in the formula bar.
OFFSET splits the range into individual cells which can then be examined by SUBTOTAL, that's used to only include visible rows after filtering.
What's in F5, that seems to be empty in your screenshot?