Mir simple linear

jmh530 john.michael.hall at gmail.com
Mon Mar 30 17:47:19 UTC 2020


On Monday, 30 March 2020 at 17:21:57 UTC, Vino wrote:
> Hi All,
>
>   Can anyone  guide me what is the problem  with below code as 
> it throws  error.
>
> import std.stdio, mir.math.common: approxEqual;
> static immutable x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
> static immutable y = [1, 3, 2, 5, 7, 8, 8, 9, 10, 12];
> auto params = x.simpleLinearRegression(y);
> writeln(params);

This should be in the Learn forum.

As far as I can tell, the problem is that x and y are both type 
immutable(int[]), which it cannot handle. I tried just turning 
them into slices, but that wasn't sufficient, I had to ensure 
they were double as well (float would also work). Note that the 
example in the document uses a y variable that is a floating 
point type.

/+dub.sdl:
dependency "mir-algorithm" version="~>3.7.25"
+/
import std.stdio : writeln;
import mir.math.stat : simpleLinearRegression;
import mir.ndslice : sliced;

void main() {
     auto x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].sliced!double;
     auto y = [1, 3, 2, 5, 7, 8, 8, 9, 10, 12].sliced!double;
     auto params = x.simpleLinearRegression(y);
     writeln(params);
}


More information about the Digitalmars-d-announce mailing list