Saturday, December 28, 2019

Regression as Exercises


train=ExampleData[{"MachineLearning",
"BostonHomes"},"TrainingData"];
test=ExampleData[{"MachineLearning",
"BostonHomes"}, "TestData"];
MLP=NetChain[{LinearLayer[13*4],
BatchNormalizationLayer[],ElementwiseLayer[Ramp],
LinearLayer[512],BatchNormalizationLayer[],
ElementwiseLayer[Ramp],LinearLayer[1]},
"Input"->13,"Output"->"Scalar" ]
results=NetTrain[MLP,train,All,
ValidationSet->test,MaxTrainingRounds->500]
{TrainedMLP,ValLosses}=results[{"TrainedNet",
"ValidationLossList"}]; Min[ValLosses]


Predictions= Predict[train,
Method->"GradientBoostedTrees",PerformanceGoal->"Quality"]
testpreds=Predictions[test[[All,1]]];
ListLinePlot[{test[[All,2]],testpreds},ImageSize->600,
PlotLegends->{"Real Data","Predictions"},
PlotLabel->{"Mean Square"->PredictorMeasurements[Predictions,
test,"MeanSquare"]}]

No comments:

Post a Comment