Regression with Neural Networks

Regression from Numeric Data

Train a predictor that predicts the median value of properties in a neighborhood of Boston, given some features of the neighborhood.

First, obtain the training and validation data:

train=ExampleData[{"MachineLearning","BostonHomes"},"TrainingData"];
test=ExampleData[{"MachineLearning","BostonHomes"},"TestData"];

First[train]

Define a net that returns a scalar:

net=NetChain[{LinearLayer[15],BatchNormalizationLayer[],ElementwiseLayer[Ramp],LinearLayer[10],BatchNormalizationLayer[],ElementwiseLayer[Ramp],LinearLayer[1]},"Input"->13,"Output"-> "Scalar" ]

Train the net and determine the lowest validation loss:

results=NetTrain[net,train,All,ValidationSet->test]
{trainedNet,valLosses}=results[{"TrainedNet","ValidationLossList"}];
Min[valLosses]

Make a prediction:

trainedNet[{0.02731,0,7.07,0,0.469,6.421,78.9,4.9671,2,242,17.8,396.9,9.14}]

Train a predictor using (RefLink[Predict, paclet:ref/Predict]) instead, and obtain the mean squared loss on the test set:

p=Predict[train, PerformanceGoal->"Quality"]
pm=PredictorMeasurements[p,test,"MeanSquare"]