Ejemplo n.º 1
0
        public double?MeasureDailyCorrelation(DatePeriodValue period = null)
        {
            if (this.SourceItems.Count == 0)
            {
                return(0);
            }
            else
            {
                if (period == null)
                {
                    period = new DatePeriodValue(
                        this.SourceItems.Min(c => c.Target),
                        this.SourceItems.Max(c => c.Target)
                        );
                }

                var groups = this.SourceItems.Where(c => c.Target >= period.Start && c.Target <= period.End)
                             .GroupBy(c => c.Target.Date).OrderBy(c => c.Key);

                var totals = groups.Select(c => c.Sum(c => (double)c.Total.GetValueOrDefault())).ToArray();
                var bad    = groups.Select(c => c.Sum(c =>
                                                      (double)(c.Bad.GetValueOrDefault())
                                                      )).ToArray();
                var correlation = QualityUtils.MeasureCorrelation(totals, bad);
                return(correlation);
            }
        }
Ejemplo n.º 2
0
                ) Measure()
        {
            var groups            = this.Items.GroupBy(c => c.Target).OrderBy(c => c.Key).ToList();
            var totals            = groups.Select(c => c.Sum(d => d.Total.GetValueOrDefault())).ToArray();
            var bad               = groups.Select(c => c.Sum(d => d.Bad.GetValueOrDefault())).ToArray();
            var dailyInteractions = new List <DateInteractionModel>();

            foreach (var item in groups)
            {
                dailyInteractions.Add(
                    new DateInteractionModel(item.Key,
                                             item.Sum(c => c.Total).GetValueOrDefault(),
                                             item.Sum(c => c.Good).GetValueOrDefault())
                    );
            }

            var pairs = totals.Zip(bad).OrderBy(c => c.First);

            totals = pairs.Select(c => c.First).ToArray();
            bad    = pairs.Select(c => c.Second).ToArray();

            double correlation = QualityUtils.MeasureCorrelation(totals, bad);

            var(b0, b1, r2) = QualityUtils.LinealRegression(totals, bad);
            return(correlation, totals, bad, b0, b1, r2, dailyInteractions);
        }