/// <summary>Generate Logistic Regression model based on a set of examples.</summary>
        /// <param name="x">The Matrix to process.</param>
        /// <param name="y">The Vector to process.</param>
        /// <returns>Model.</returns>
        public override IModel Generate(Matrix x, Vector y)
        {
            // create initial theta
            var copy = x.Copy();

            copy = FeatureDimensions.IncreaseDimensions(copy, this.PolynomialFeatures);

            // add intercept term
            copy = copy.Insert(Vector.Ones(copy.Rows), 0, VectorType.Col);

            var theta = Vector.Ones(copy.Cols);

            var run = GradientDescent.Run(
                theta,
                copy,
                y,
                this.MaxIterations,
                this.LearningRate,
                new LogisticCostFunction(),
                this.Lambda,
                new Regularization());

            var model = new LogisticRegressionModel()
            {
                Descriptor         = this.Descriptor, Theta = run.Item2, LogisticFunction = new Logistic(),
                PolynomialFeatures = this.PolynomialFeatures
            };

            return(model);
        }
Пример #2
0
        /// <summary>
        ///     Create a prediction based on the learned Theta values and the supplied test item.
        /// </summary>
        /// <param name="y">Training record</param>
        /// <returns></returns>
        public override double Predict(Vector y)
        {
            var tempy = this.PolynomialFeatures > 0
                            ? FeatureDimensions.IncreaseDimensions(y, this.PolynomialFeatures)
                            : y;

            tempy = tempy.Insert(0, 1.0);
            return(this.LogisticFunction.Compute((tempy * this.Theta).ToDouble()) >= 0.5 ? 1d : 0d);
        }
Пример #3
0
    public static FeatureDimensions dynamic_cast(FeatureBase arg0)
    {
        IntPtr            cPtr = libtischPINVOKE.FeatureDimensions_dynamic_cast(FeatureBase.getCPtr(arg0));
        FeatureDimensions ret  = (cPtr == IntPtr.Zero) ? null : new FeatureDimensions(cPtr, false);

        if (libtischPINVOKE.SWIGPendingException.Pending)
        {
            throw libtischPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
Пример #4
0
 internal static HandleRef getCPtr(FeatureDimensions obj)
 {
     return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr);
 }
 internal static HandleRef getCPtr(FeatureDimensions obj) {
   return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }