Ejemplo n.º 1
0
        public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataView input)
        {
            Contracts.CheckValue(env, nameof(env));
            var h = env.Register("CategoricalHash");

            using (var ch = h.Start("CategoricalHash"))
            {
                h.CheckValue(args, nameof(args));
                h.CheckValue(input, nameof(input));
                h.CheckUserArg(Utils.Size(args.Column) > 0, nameof(args.Column), "Columns must be specified");
                if (args.HashBits < 1 || args.HashBits >= NumBitsLim)
                {
                    throw h.ExceptUserArg(nameof(args.HashBits), "Number of bits must be between 1 and {0}", NumBitsLim - 1);
                }

                // creating the Hash function
                var hashArgs = new HashTransform.Arguments
                {
                    HashBits   = args.HashBits,
                    Seed       = args.Seed,
                    Ordered    = args.Ordered,
                    InvertHash = args.InvertHash,
                    Column     = new HashTransform.Column[args.Column.Length]
                };
                for (int i = 0; i < args.Column.Length; i++)
                {
                    var column = args.Column[i];
                    if (!column.TrySanitize())
                    {
                        throw h.ExceptUserArg(nameof(Column.Name));
                    }
                    h.Assert(!string.IsNullOrWhiteSpace(column.Name));
                    h.Assert(!string.IsNullOrWhiteSpace(column.Source));
                    hashArgs.Column[i] = new HashTransform.Column
                    {
                        HashBits   = column.HashBits,
                        Seed       = column.Seed,
                        Ordered    = column.Ordered,
                        Name       = column.Name,
                        Source     = column.Source,
                        InvertHash = column.InvertHash,
                    };
                }

                return(CategoricalTransform.CreateTransformCore(
                           args.OutputKind, args.Column,
                           args.Column.Select(col => col.OutputKind).ToList(),
                           new HashTransform(h, hashArgs, input),
                           h,
                           env,
                           args));
            }
        }
        public static CommonOutputs.TransformOutput CatTransformDict(IHostEnvironment env, CategoricalTransform.Arguments input)
        {
            Contracts.CheckValue(env, nameof(env));
            var host = env.Register("CatTransformDict");

            host.CheckValue(input, nameof(input));
            EntryPointUtils.CheckInputArgs(host, input);

            var xf = CategoricalTransform.Create(host, input, input.Data);

            return(new CommonOutputs.TransformOutput {
                Model = new TransformModel(env, xf, input.Data), OutputData = xf
            });
        }