Data Transformation Examples
Data Transformation Examples#
All examples are tested.
For fitting a curve to some data, the following operations can be combined:
lambdaoperation to define the model function, see
curve_fitoperation, which is an alias for
scipy.optimize.curve_fit; see scipy documentation
select: data_to_fit: path/to/elephant_ts # 1D data with `time` dimension transform: # Define the model function as a lambda - lambda: "lambda x, a0, a1, a2, a3, a4, a5: a5*x**5 + a4*x**4 + a3*x**3 + a2*x**2 + a1*x**1 + a0" tag: elephant_f # Extract the independent variable (here: the `time` coordinates) - .coords: [!dag_tag data_to_fit, time] tag: times # Do the fit; result will be that of `scipy.optimize.curve_fit` - curve_fit: - !dag_tag elephant_f - !dag_tag times - !dag_tag data_to_fit tag: fit_results
The polynomial above of course doesn’t quite achieve fitting an elephant to the data, as John von Neumann wanted to show. However, see this blog post on how this can actually be achieved.