コード例 #1
0
        private string[] GetGroupedAttributePossibleValues(PropertyInfo prop, NominalAttribute att, string[] attvals)
        {
            var togroup = GetAttributeValuesToGroup(att, attvals);

            Array.ForEach(data, row => {
                var val = InternalHelpers.ToStringSafe(Helpers.GetValue(row, prop.Name));
                var idx = Array.BinarySearch(togroup, val);
                while (idx >= 0)
                {
                    Helpers.SetValue(row, prop.Name, "Others");
                    idx = idx == togroup.Length ? -1 : Array.BinarySearch(togroup, idx + 1, togroup.Length - (idx + 1), val);
                }
            });
            return(attvals.Concat(new[] { "Others" }).Distinct().Except(togroup).ToArray());
        }
コード例 #2
0
 private static string[] GetAttributeValuesToGroup(NominalAttribute att, string[] atts)
 {
     if (att is NominalGroupWhenLessThanAttribute)
     {
         var min = ((NominalGroupWhenLessThanAttribute)att).Min;
         return(atts.GroupBy(a => a).
                Where(g => g.Count() < min).
                Select(g => g.Key).
                OrderBy(a => a).
                ToArray());
     }
     if (att is NominalGroupMaxBinsAttribute)
     {
         var max = ((NominalGroupMaxBinsAttribute)att).Max;
         return(atts.GroupBy(a => a).
                OrderByDescending(g => g.Count()).
                Skip(max).
                Select(g => g.Key).
                OrderBy(a => a).ToArray());
     }
     throw new NotSupportedException("Type: " + att.GetType().Name + " does not support grouping");
 }