I have this simple code to do a regression on a list of points very close to a parabole. It is purely anecdotal that I happen to know the exact underlying trend, the idea is just to have simple/nice synthetic data. The eventual goal is to do regressions with data whose underlying trend is not known.
Table[x -> {x, x^2 + RandomReal[{-0.9, 0.9}]}, {x, -5., 5., 0.5}];
net = NetChain[{20, Tanh, 2}];
trained = NetTrain[net, data, BatchSize -> 20]
Show[ListPlot[{Flatten[Table[trained@{x}, {x, -4., 4., 0.25}], 1],
data[[All, 2]]}],
Plot[x^2, {x, -4., 4.}, PlotStyle -> Darker[Green]]]
Is there a more compact / advisable way to do something equivalent using ports? I ask this because that seems the way to go to include weights (https://reference.wolframcloud.com/language/tutorial/NeuralNetworksExampleWeighting.html.en)
data = Table[{x, x^2 + RandomReal[{-0.9, 0.9}]}, {x, -5., 5., 0.5}]; lmf = LinearModelFit[data, {x, x^2}, x]
. That will give you the ability to look at goodness-of-fit statistics. $\endgroup$FindFormula
function when you want to find a general fit that describes the data rather than explaining the data. $\endgroup$