public List<Dish> CalculatePredictedRateForUnratedDishes(List<Rating> rates, List<Dish> unratedDishes)
        {
            List<Dish> recommendeDishes = new List<Dish>();
            double[][] inputs = new double[rates.Count][];
            double[][] outputs = new double[rates.Count][];
            for (int i = 0; i < rates.Count; i++)
            {
                inputs[i] = rates[i].DishParameters;
                outputs[i] = new double[] {rates[i].Rate};
            }

            MultivariateLinearRegression regression = new MultivariateLinearRegression(6, 1);
            double errorRegression = regression.Regress(inputs, outputs);

            foreach (var unratedDish in unratedDishes)
            {
                unratedDish.PredictedRate = regression.Compute(unratedDish.DishParameters)[0];
            }

            recommendeDishes.AddRange(unratedDishes.OrderByDescending(dish => dish.PredictedRate).ToList().Take(3));

            return recommendeDishes;
        }
Exemple #2
0
        private void btnRegress_Click(object sender, EventArgs e)
        {
            if (pls == null || dgvRegressionInput.DataSource == null)
            {
                MessageBox.Show("Please compute the analysis first.");
                return;
            }

            int components = (int)numComponentsRegression.Value;
            regression = pls.CreateRegression(components);

            DataTable table = dgvRegressionInput.DataSource as DataTable;
            DataTable inputTable = table.DefaultView.ToTable(false, inputColumnNames);
            DataTable outputTable = table.DefaultView.ToTable(false, outputColumnNames);


            double[][] sourceInput = Matrix.ToArray(inputTable as DataTable);
            double[][] sourceOutput = Matrix.ToArray(outputTable as DataTable);

            
            double[,] result = Matrix.ToMatrix(regression.Compute(sourceInput));

            double[] rSquared = regression.CoefficientOfDetermination(sourceInput, sourceOutput, cbAdjusted.Checked);

            dgvRegressionOutput.DataSource = new ArrayDataView(result, outputColumnNames);
            dgvRSquared.DataSource = new ArrayDataView(rSquared, outputColumnNames);
        }