Xarray¶
Setup¶
In [ ]:
Copied!
pip install ydf xarray -U
pip install ydf xarray -U
In [1]:
Copied!
import ydf
import xarray as xr
import ydf
import xarray as xr
In [2]:
Copied!
dataset = xr.Dataset({
"feature_1": ("example", [0.1, 0.2, 0.3, 0.4]),
"feature_2": ("example", ["X", "X", "Y", "Y"]),
"feature_3": (("example", "pixel"), [[1, 2], [3, 4], [5, 6], [7, 8]]),
"label": ("example", ["A", "B", "A", "B"]),
})
dataset = xr.Dataset({
"feature_1": ("example", [0.1, 0.2, 0.3, 0.4]),
"feature_2": ("example", ["X", "X", "Y", "Y"]),
"feature_3": (("example", "pixel"), [[1, 2], [3, 4], [5, 6], [7, 8]]),
"label": ("example", ["A", "B", "A", "B"]),
})
This dataset contains 4 examples. feature1
is a single-dimensional numerical feature. feature_2
is a categorical feature. feature_3
is a multi-dimensional feature. Finally, label
is the label.
We can then train a model on this (very simple) dataset.
In [4]:
Copied!
model = ydf.RandomForestLearner(label="label").train(dataset)
model = ydf.RandomForestLearner(label="label").train(dataset)
Train model on 4 examples Model trained in 0:00:00.006497
We can make predictions with the model.
In [5]:
Copied!
model.predict(dataset)
model.predict(dataset)
Out[5]:
array([0.2999998, 0.2999998, 0.2999998, 0.2999998], dtype=float32)