コード例 #1
0
        /// <summary>
        ///   Creates a new MultinomialLogisticRegression that is a copy of the current instance.
        /// </summary>
        ///
        public object Clone()
        {
            var mlr = new MultinomialLogisticRegression(Inputs, Categories);

            for (int i = 0; i < coefficients.Length; i++)
            {
                for (int j = 0; j < coefficients[i].Length; j++)
                {
                    mlr.coefficients[i][j]   = coefficients[i][j];
                    mlr.standardErrors[i][j] = standardErrors[i][j];
                }
            }

            return(mlr);
        }
コード例 #2
0
        /// <summary>
        ///   The likelihood ratio test of the overall model, also called the model chi-square test.
        /// </summary>
        ///
        /// <remarks>
        ///   <para>
        ///   The Chi-square test, also called the likelihood ratio test or the log-likelihood test
        ///   is based on the deviance of the model (-2*log-likelihood). The log-likelihood ratio test
        ///   indicates whether there is evidence of the need to move from a simpler model to a more
        ///   complicated one (where the simpler model is nested within the complicated one).</para>
        ///   <para>
        ///   The difference between the log-likelihood ratios for the researcher's model and a
        ///   simpler model is often called the "model chi-square".</para>
        /// </remarks>
        ///
        public ChiSquareTest ChiSquare(double[][] input, double[][] output)
        {
            double[] sums = output.Sum();

            double[] intercept = new double[Categories - 1];
            for (int i = 0; i < intercept.Length; i++)
            {
                intercept[i] = Math.Log(sums[i + 1] / sums[0]);
            }

            var regression = new MultinomialLogisticRegression(Inputs, Categories, intercept);

            double ratio = GetLogLikelihoodRatio(input, output, regression);

            return(new ChiSquareTest(ratio, (Inputs) * (Categories - 1)));
        }
コード例 #3
0
 /// <summary>
 ///   Gets the Log-Likelihood Ratio between two models.
 /// </summary>
 ///
 /// <remarks>
 ///   The Log-Likelihood ratio is defined as 2*(LL - LL0).
 /// </remarks>
 ///
 /// <param name="input">A set of input data.</param>
 /// <param name="output">A set of output data.</param>
 /// <param name="regression">Another Logistic Regression model.</param>
 /// <returns>The Log-Likelihood ratio (a measure of performance
 /// between two models) calculated over the given data sets.</returns>
 ///
 public double GetLogLikelihoodRatio(double[][] input, double[][] output, MultinomialLogisticRegression regression)
 {
     return(2.0 * (this.GetLogLikelihood(input, output) - regression.GetLogLikelihood(input, output)));
 }