예제 #1
0
        private static void MakePredictionsOnTestFileAndCalculateError(MovieScorePredictor predictor, UserCache testingSetCache)
        {
            // Get the list of users to make predictions on
            IReadOnlyDictionary <int, UserCache.UserRatingsCache> listOfUsersToPredictScoresOn = testingSetCache.GetAllUsersAndMovieRatings();

            Console.WriteLine("Making predictions...");
            // Predict ratings for all the users in parallel
            List <MoviePrediction> predictions = listOfUsersToPredictScoresOn.AsParallel().Select(l =>
            {
                // Make the prediction for this users movies
                var returnValue = predictor.PredictAllScores(l.Key, l.Value.GetMovieRatings(), K);

                // This is simply to update the console on the current progress
                l.Value.Predicted = true;
                int predicted     = listOfUsersToPredictScoresOn.Values.Count(n => n.Predicted);
                Console.Write("\r{0}/{1}", predicted, listOfUsersToPredictScoresOn.Count);

                // Return the prediction
                return(returnValue);
            }).SelectMany(s => s.Values).ToList();

            Console.WriteLine(Environment.NewLine);

            Console.WriteLine("Calculating errors...");
            var rootMeanSquareError = RootMeanSquareError.Calculate(predictions);
            var meanAbsoluteError   = MeanAbsoluteError.Calculate(predictions);

            Console.WriteLine("=========================================");
            Console.WriteLine("Root mean square error: {0}", rootMeanSquareError);
            Console.WriteLine("Mean absolute error: {0}", meanAbsoluteError);
        }
예제 #2
0
 /// <summary>
 /// Add a set of evaluation metrics to the set of observations.
 /// </summary>
 /// <param name="metrics">The observed regression evaluation metric</param>
 void IMetricsStatistics <RegressionMetrics> .Add(RegressionMetrics metrics)
 {
     MeanAbsoluteError.Add(metrics.MeanAbsoluteError);
     MeanSquaredError.Add(metrics.MeanSquaredError);
     RootMeanSquaredError.Add(metrics.RootMeanSquaredError);
     LossFunction.Add(metrics.LossFunction);
     RSquared.Add(metrics.RSquared);
 }
예제 #3
0
        static void Main(string[] args)
        {
            Operations K = new Operations();

            //Load array to the tensor
            NDArray x = new NDArray(3, 3);

            x.Load(2, 4, 6, 1, 3, 5, 2, 3, 5);
            x.Print("Load X Values");

            NDArray y = new NDArray(3, 1);

            y.Load(20, 15, 15);
            y.Print("Load Y Values");

            //Create two layers, one with 6 neurons and another with 1
            FullyConnected fc1 = new FullyConnected(3, 6, "relu");
            FullyConnected fc2 = new FullyConnected(6, 1, "relu");

            //Connect input by passing data from one layer to another
            fc1.Forward(x);
            fc2.Forward(fc1.Output);
            var preds = fc2.Output;

            preds.Print("Predictions");

            //Calculate the mean square error cost between the predicted and expected values
            BaseCost cost       = new MeanSquaredError();
            var      costValues = cost.Forward(preds, y);

            costValues.Print("MSE Cost");

            //Calculate the mean absolute metric value for the predicted vs expected values
            BaseMetric metric       = new MeanAbsoluteError();
            var        metricValues = metric.Calculate(preds, y);

            metricValues.Print("MAE Metric");

            Console.ReadLine();
        }
예제 #4
0
 internal static HandleRef getCPtr(MeanAbsoluteError obj)
 {
     return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr);
 }
예제 #5
0
 internal static HandleRef getCPtr(MeanAbsoluteError obj) {
   return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }