Esempio n. 1
0
 internal void WrapTermWithDelegate(Action <ValueToKeyMappingTransformer> onFit)
 {
     _term = (ValueToKeyMappingEstimator)_term.WithOnFitDelegate(onFit);
 }
Esempio n. 2
0
        internal OneHotEncodingEstimator(IHostEnvironment env, ColumnOptions[] columns, IDataView keyData = null)
        {
            Contracts.CheckValue(env, nameof(env));
            _host = env.Register(nameof(OneHotEncodingEstimator));
            _term = new ValueToKeyMappingEstimator(_host, columns, keyData);
            var binaryCols = new List <(string outputColumnName, string inputColumnName)>();
            var cols       = new List <(string outputColumnName, string inputColumnName, bool bag)>();

            for (int i = 0; i < columns.Length; i++)
            {
                var column = columns[i];
                OneHotEncodingTransformer.OutputKind kind = columns[i].OutputKind;
                switch (kind)
                {
                default:
                    throw _host.ExceptUserArg(nameof(column.OutputKind));

                case OneHotEncodingTransformer.OutputKind.Key:
                    continue;

                case OneHotEncodingTransformer.OutputKind.Bin:
                    binaryCols.Add((column.OutputColumnName, column.OutputColumnName));
                    break;

                case OneHotEncodingTransformer.OutputKind.Ind:
                    cols.Add((column.OutputColumnName, column.OutputColumnName, false));
                    break;

                case OneHotEncodingTransformer.OutputKind.Bag:
                    cols.Add((column.OutputColumnName, column.OutputColumnName, true));
                    break;
                }
            }
            IEstimator <ITransformer> toBinVector = null;
            IEstimator <ITransformer> toVector    = null;

            if (binaryCols.Count > 0)
            {
                toBinVector = new KeyToBinaryVectorMappingEstimator(_host, binaryCols.Select(x => (x.outputColumnName, x.inputColumnName)).ToArray());
            }
            if (cols.Count > 0)
            {
                toVector = new KeyToVectorMappingEstimator(_host, cols.Select(x => new KeyToVectorMappingEstimator.ColumnOptions(x.outputColumnName, x.inputColumnName, x.bag)).ToArray());
            }

            if (toBinVector != null && toVector != null)
            {
                _toSomething = toVector.Append(toBinVector);
            }
            else
            {
                if (toBinVector != null)
                {
                    _toSomething = toBinVector;
                }
                else
                {
                    _toSomething = toVector;
                }
            }
        }