Пример #1
0
        /// <summary>
        /// get Mean Absolute Error
        /// return -1 means no MAE
        /// </summary>
        /// <returns>return -1 means no MAE</returns>
        private double _GetMAE(List <AnimeStat> predictions, List <AnimeStat> myScoresList20)
        {
            double absoluteError = 0;
            int    n             = 0;

            foreach (var item in predictions)
            {
                AnimeStat predict = myScoresList20.Find(x => x.AnimeId == item.AnimeId);

                absoluteError = absoluteError + Math.Abs(predict.Score - item.Score);

                n++;
            }
            if (n == 0)
            {
                return(-1);
            }
            else
            {
                return(absoluteError / n);
            }
        }
Пример #2
0
        /// <summary>
        /// get Root Mean Square Error(deviation)
        /// return -1 means no MAE
        /// </summary>
        /// <returns></returns>
        private double _GetRMSE(List <AnimeStat> predictions, List <AnimeStat> myScoresList20)
        {
            double squareError = 0;
            int    n           = 0;

            foreach (var item in predictions)
            {
                AnimeStat predict = myScoresList20.Find(x => x.AnimeId == item.AnimeId);
                squareError = squareError + Math.Pow((predict.Score - item.Score), 2);
                n++;
            }

            double rmse = Math.Sqrt(squareError / (n - 1));

            if (n <= 1 || double.IsNaN(rmse))
            {
                return(-1);
            }
            else
            {
                return(rmse);
            }
        }