Linear Regression on a String This challenge is a little tricky, but rather simple, given a string s:

meta.codegolf.stackexchange.com


Use the position of the character in the string as an x coordinate and the ascii value as a y coordinate. For the above string, the resultant set of coordinates would be:

0, 109
1, 101
2, 116
3, 97
4, 46
5, 99
6, 111
7, 100
8, 101
9, 103
10,111
11,108
12,102
13,46
14,115
15,116
16,97
17,99
18,107
19,101
20,120
21,99
22,104
23,97
24,110
25,103
26,101
27,46
28,99
29,111
30,109




Next, you must calculate both the slope and the y-intercept of the set you've garnered using Linear Regression, here's the set above plotted:



Which results in a best fit line of (0-indexed):

y = 0.014516129032258x + 99.266129032258


Here's the 1-indexed best-fit line:

y = 0.014516129032258x + 99.251612903226




So your program would return:

f("meta.codegolf.stackexchange.com") = [0.014516129032258, 99.266129032258]


Or (Any other sensible format):

f("meta.codegolf.stackexchange.com") = "0.014516129032258x + 99.266129032258"


Or (Any other sensible format):

f("meta.codegolf.stackexchange.com") = "0.014516129032258\n99.266129032258"


Or (Any other sensible format):

f("meta.codegolf.stackexchange.com") = "0.014516129032258 99.266129032258"


Just explain why it is returning in that format if it isn't obvious.



Some clarifying rules:

- Strings are 0-indexed or 1 indexed both are acceptable.
- Output may be on new lines, as a tuple, as an array or any other format.
- Precision of the output is arbitrary but should be enough to verify validity (min 5).


This is code-golf lowest byte-count wins.
Octave, 29 26 24 20 bytes
@(s)s/[!!s;1:nnz(s)]

Try it Online!
We have the model
y= intercept *x^0 + slope * x
 = intercept * 1  + slope * x

Here y is the  ASCII value of string s
To find parameters intercept and slope we can form the following equation:
s = [intercept slope] * [1 X]

so
[intercept slope] = s/[1 x]

!!s converts a string to a vector of ones with the same length as the string.
The vector of ones is used for estimation of the intercept.
1:nnz(s) is range of values from 1 to number of elements of the string used as x.
Previous answer
@(s)ols(s'+0,[!!s;1:nnz(s)]')

For test paste the following code into Octave Online
(@(s)ols(s'+0,[!!s;1:nnz(s)]'))('meta.codegolf.stackexchange.com')

A function that accepts a string as input and applies ordinary least squares estimation of model y = x*b + e
The first argument of ols is y that for it we transpose the string s and add with number 0 to get its ASCII code.