# Machine Learning Prediction for Motion Sensors In Mathematica

Let's assume we have a motion sensor that provides us X and Y data for a target where the measurement error is normally distributed with parameters:

$\mu=0.0$

$\sigma=5.2$

First we will need to train our prediction model with some training data.  We add a square term to give the target a parabolic path.

Now build the five different supported predictor functions:

With minimal parameter input here is Information about the predictors as built with default parameters:

$\begin{array}{cc}"Method"& "Linear regression"\\ "Number of features"& 1\\ "Number of training examples"& 200\\ "L1 regularization coefficient"& 0\\ "L2 regularization coefficient"& 1.\end{array}$

$\begin{array}{cc}"Method"& "Gaussian Process"\\ "Number of features"& 1\\ "Number of training examples"& 200\\ \mathrm{AssumeDeterministic}& \mathrm{False}\\ "Numerical Covariance Type"& "SquaredExponential"\\ "Nominal Covariance Type"& "HammingDistance"\\ "EstimationMethod"& "MaximumPosterior"\\ "OptimizationMethod"& "FindMinimum"\end{array}$

$\begin{array}{cc}"Method"& "K-nearest neighbors"\\ "Number of features"& 1\\ "Number of training examples"& 200\\ "Number of neighbors"& 10\\ "Distance function"& \mathrm{EuclideanDistance}\end{array}$

$\begin{array}{cc}"Method"& "Neural network"\\ "Number of features"& 1\\ "Number of training examples"& 200\\ "L1 regularization coefficient"& 0\\ "L2 regularization coefficient"& 0.1\\ "Number of hidden layers"& 2\\ "Hidden nodes"& \\ "Hidden layer activation functions"& \\ "CostFunction"& "Cost Function"\end{array}$

$\begin{array}{cc}"Method"& "Random forest"\\ "Number of features"& 1\\ "Number of training examples"& 200\\ "Number of trees"& 50\end{array}$

Now we build a new random sensor track and test it against our trained prediction functions.

Here is our "training track" plotted against the trackData1 we created.

We create a plot function that allows us to pass track data and show the first plot's prediction, confidence interval and raw data using a linear regression predictor:

We decide we'd rather parameterize the prediction method so we steel a cool method found on the Wolfram site.

Finally let's plot them all in one combined chart.

Viola' we get this chart:

The Gaussian Process provides the best fit and tightest confidence interval for our track predictor.

You can download the CDF and/or the Notebook for this work.  Enjoy and let me know if you find something wrong or improve it.

Thanks,

Phil Neumiller