fillna
Builtin index · Statistics & ML
fillna(x, value)
Input: x, value · Output: no output
What it is
Replaces every NaN (the missing-value marker) in a vector or matrix by value, leaving every other entry, inf included, untouched. For a matrix value is a single number or a vector with one number per column. A Signal keeps its Fs. For time series use fill_missing, which interpolates instead. Errors: a vector x with a vector value, a per-column value of the wrong length, complex input.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
fillna(x, value) | x vectorErrors: a vector x with a vector value, a per-column value of the wrong length, complex input.value vector or matrixReplaces every NaN (the missing-value marker) in a vector or matrix by value, leaving every other entry, inf included, untouched. | not documented yet | A Signal keeps its Fs. For time series use fill_missing, which interpolates instead. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
Xna = [1, 10; nan, 12; 3, nan; 5, 14; 7, 16; nan, 18]
yna = [0, 0, 0, 1, 1, 1]
Xf = impute(Xna, "median")
print(Xf)
m = logistic_model(Xf, yna)
print("train accuracy: {round(m.score(Xf, yna), 3)}")
print(fillna([1, nan, 3], 0))
output
[1, 10; 4, 12; 3, 14; 5, 14; 7, 16; 4, 18] train accuracy: 0.667 [1, 0, 3]
from statistics-ml