public static StdDev ( Matrix source, VectorType t = VectorType.Col ) : |
||
source | Matrix | |
t | VectorType | Use column or row (default: Col) |
Résultat |
/// <summary>Generate Linear 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 Vector theta = Vector.Ones(x.Cols + 1); Matrix copy = x.Copy(); // normalise features for (int i = 0; i < copy.Cols; i++) { var j = FeatureNormalizer.FeatureScale(copy[i, VectorType.Col]); for (int k = 0; k < copy.Rows; k++) { copy[k, i] = j[k]; } } // add intercept term copy = copy.Insert(Vector.Ones(copy.Rows), 0, VectorType.Col); // run gradient descent var run = GradientDescent.Run(theta, copy, y, MaxIterations, LearningRate, new LinearCostFunction(), Lambda, new Regularization()); // once converged create model and apply theta LinearRegressionModel model = new LinearRegressionModel(x.Mean(VectorType.Row), x.StdDev(VectorType.Row)) { Descriptor = Descriptor, Theta = run.Item2 }; return model; }
/// <summary> /// Summarizes a given Matrix. /// </summary> /// <param name="matrix">Matrix to summarize.</param> /// <param name="byVector">Indicates which direction to summarize, default is <see cref="VectorType.Row"/> indicating top-down.</param> /// <returns></returns> public static Summary Summarize(Matrix matrix, VectorType byVector = VectorType.Row) { return new Summary() { Average = matrix.Mean(byVector), StandardDeviation = matrix.StdDev(byVector), Minimum = matrix.Min(byVector), Maximum = matrix.Max(byVector), Median = matrix.Median(byVector) }; }
/// <summary> /// Computes the standard deviation of the given matrix /// </summary> /// <param name="source"></param> /// <param name="t">Return a Row or Column vector</param> /// <returns></returns> public static Vector StdDev(this Matrix source, VectorType t) { return(Matrix.StdDev(source, t)); }