コード例 #1
0
        /// <summary>
        /// Computes the best-fit linear logistic regression from the data.
        /// </summary>
        /// <returns>The fit result.</returns>
        /// <remarks>
        /// <para>Linear logistic regression is a way to fit binary outcome data to a linear model.</para>
        /// <para>The method assumes that binary outcomes are encoded as 0 and 1. If any y-values other than
        /// 0 and 1 are encountered, it throws an <see cref="InvalidOperationException"/>.</para>
        /// <para>The fit result is two-dimensional. The first parameter is a, the second b.</para>
        /// </remarks>
        /// <exception cref="InsufficientDataException">There are fewer than three data points.</exception>
        /// <exception cref="InvalidOperationException">There is a y-value other than 0 or 1.</exception>
        public LinearLogisticRegressionResult LinearLogisticRegression()
        {
            List <bool> y = yData.Select(v => { if (v == 0.0)
                                                {
                                                    return(false);
                                                }
                                                else if (v == 1.0)
                                                {
                                                    return(true);
                                                }
                                                else
                                                {
                                                    throw new InvalidOperationException();
                                                } }).ToList();

            return(Bivariate.LinearLogisticRegression(y, xData));
        }