public KPCAResult(DataTable inputData, double[,] inputDataDeviationScores, double[,] inputDataStandardScores, string[] columnNames, AnalysisMethod method, DescriptiveMeasureCollection measures, double[,] scatterPlotValues, double[,] componentMatrix, PrincipalComponentCollection principalComponents) { this.inputData = inputData; this.inputDataDeviationScores = inputDataDeviationScores; this.inputDataStandardScores = inputDataStandardScores; this.columnNames = columnNames; this.method = method; this.measures = measures; this.scatterPlotValues = scatterPlotValues; this.componentMatrix = componentMatrix; this.principalComponents = principalComponents; }
public string ProcessLinearRegression(DataTable sourceTable, string _dependentName, string _independentName) { try { double[][] inputs; double[] outputs; LinearRegressionOutput output = new LinearRegressionOutput(); // Gets the column of the dependent variable String dependentName = _dependentName; DataTable dependent = sourceTable.DefaultView.ToTable(false, dependentName); String[] independentNames = _independentName.Split(','); //String[] independentNames = names.ToArray(); DataTable independent = sourceTable.DefaultView.ToTable(false, independentNames); // Creates the input and output matrices from the source data table inputs = independent.ToJagged(); outputs = dependent.Columns[dependentName].ToArray(); // Creates the Simple Descriptive Analysis of the given source var sda = new DescriptiveAnalysis() { ColumnNames = independentNames }.Learn(inputs); // TODO: Standardize the InputNames/OutputNames properties // Populates statistics overview tab with analysis data DescriptiveMeasureCollection DMC = sda.Measures; DistributionMesure dm = new DistributionMesure() { //Column = sda.Measures.GetEnumerator(x => x), }; //DMC.s //output.DistributionMeasuresDataSource = dm; // Creates the Logistic Regression Analysis of the given source this.lra = new LogisticRegressionAnalysis() { Inputs = independentNames, Output = dependentName }; // Create the Multiple Linear Regression Analysis of the given source this.mlr = new MultipleLinearRegressionAnalysis(intercept: true) { Inputs = independentNames, Output = dependentName }; // Compute the Linear Regression Analysis MultipleLinearRegression reg = mlr.Learn(inputs, outputs); LinearRegressionCoefficientCollection LCC = mlr.Coefficients; List <LinearCoefficients> lcs = new List <LinearCoefficients>(); foreach (var rc in LCC) { LinearCoefficients lc = new LinearCoefficients() { Name = rc.Name, Value = rc.Value, StandardError = rc.StandardError, TStatistic = rc.TTest.Statistic, P_ValueofT = rc.TTest.PValue, FStatistic = rc.FTest.Statistic, P_ValueofF = rc.FTest.PValue, ConfidenceUpper = rc.ConfidenceUpper, ConfidenceLower = rc.ConfidenceLower }; lcs.Add(lc); } output.LinearCoefficientsDataSource = lcs; //AnovaSourceCollection RDS = mlr.Table; List <RegressionAnova> acs = new List <RegressionAnova>(); foreach (var RDS in mlr.Table) { RegressionAnova ra = new RegressionAnova() { Source = RDS.Source, DegreesOfFreedom = RDS.DegreesOfFreedom, SumOfSquares = RDS.SumOfSquares, MeanSquares = RDS.MeanSquares, FStatistic = RDS.Statistic, PValueSignificance = (RDS.Significance == null) ? 0 : RDS.Significance.PValue }; acs.Add(ra); } output.RegressionAnovaDataSource = acs; output.RSquared = mlr.RSquared.ToString("N5"); output.RSquaredAdj = mlr.RSquareAdjusted.ToString("N5"); output.ChiPValue = mlr.ChiSquareTest.PValue.ToString("N5"); output.FPValue = mlr.FTest.PValue.ToString("N5"); output.ZPValue = mlr.ZTest.PValue.ToString("N5"); output.ChiStatistic = mlr.ChiSquareTest.Statistic.ToString("N5"); output.FStatistic = mlr.FTest.Statistic.ToString("N5"); output.ZStatistic = mlr.ZTest.Statistic.ToString("N5"); output.ChiSignificantChecked = mlr.ChiSquareTest.Significant; output.FSignificantChecked = mlr.FTest.Significant; output.ZSignificantChecked = mlr.ZTest.Significant; // Populate projection source table string[] cols = independentNames; if (!independentNames.Contains(dependentName)) { cols = independentNames.Concatenate(dependentName); } DataTable projSource = sourceTable.DefaultView.ToTable(false, cols); //output.ProjectionSourceDataSource = projSource; DataTable independentProj = projSource.DefaultView.ToTable(false, lra.Inputs); DataTable dependentProj = projSource.DefaultView.ToTable(false, lra.Output); double[][] input = independentProj.ToJagged(); double[] output1; output1 = mlr.Regression.Transform(input); DataTable result = projSource.Clone(); for (int i = 0; i < input.Length; i++) { DataRow row = result.NewRow(); for (int j = 0; j < lra.Inputs.Length; j++) { row[lra.Inputs[j]] = input[i][j]; } row[lra.Output] = output1[i]; result.Rows.Add(row); } output.ProjectionResultDataSource = result; var jsonResult = JsonConvert.SerializeObject(output, Formatting.Indented); return(jsonResult); } catch (Exception ex) { throw new Exception("Error:" + ex); } }