scores
Pandas API#
While scores
is primarily designed for use with xarray
Datasets/DataArrays
, some metrics can work out of the box with pandas
while others can work with some wrapping code to convert the two types between each other.
Therefore, to make it more clear what can be used with pandas
, scores
shows a pandas
api point including only those methods which work with pandas
. This API also defines type hints for Pandas rather than xarray.
This notebook will be expanded to cover some more details in future, such as how to convert more complex examples to and from xarray should that be wanted. The API itself is also in an early stage, and so only has a small number of scores currently. This will be expanded based on community feedback or as additional use cases are encountered.
[1]:
import pandas as pd
import scores
from scores import sample_data
Retrieve some sample data with simple values. Fcst and Obs here are pandas.Series objects.
[2]:
fcst = sample_data.simple_forecast_pandas()
obs = sample_data.simple_observations_pandas()
[3]:
fcst
[3]:
0 10
1 10
2 11
3 13
4 14
5 17
6 15
7 14
dtype: int64
Available metrics:
[26]:
# Uncomment this to see help documentation on the module
help(scores.pandas)
[4]:
scores.pandas.continuous.mse(fcst, obs)
[4]:
5.0
[5]:
# Many times, data will be held in a data frame. These can be simply passed to `scores` as follows:
df = pd.DataFrame({"fcst": fcst, "obs": obs})
df.head()
[5]:
fcst | obs | |
---|---|---|
0 | 10 | 11 |
1 | 10 | 11 |
2 | 11 | 12 |
3 | 13 | 14 |
4 | 14 | 11 |
[6]:
scores.pandas.continuous.mse(df.fcst, df.obs)
[6]:
5.0
[ ]: