public override IEstimator <ITransformer> Reconcile(IHostEnvironment env, PipelineColumn[] toOutput, IReadOnlyDictionary <PipelineColumn, string> inputNames, IReadOnlyDictionary <PipelineColumn, string> outputNames, IReadOnlyCollection <string> usedNames) { var infos = new CategoricalEstimator.ColumnInfo[toOutput.Length]; Action <TermTransform> onFit = null; for (int i = 0; i < toOutput.Length; ++i) { var tcol = (ICategoricalCol)toOutput[i]; infos[i] = new CategoricalEstimator.ColumnInfo(inputNames[tcol.Input], outputNames[toOutput[i]], (CategoricalTransform.OutputKind)tcol.Config.OutputKind, tcol.Config.Max, (TermTransform.SortOrder)tcol.Config.Order); if (tcol.Config.OnFit != null) { int ii = i; // Necessary because if we capture i that will change to toOutput.Length on call. onFit += tt => tcol.Config.OnFit(tt.GetTermMap(ii)); } } var est = new CategoricalEstimator(env, infos); if (onFit != null) { est.WrapTermWithDelegate(onFit); } return(est); }
public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataView input) { Contracts.CheckValue(env, nameof(env)); var h = env.Register("Categorical"); h.CheckValue(args, nameof(args)); h.CheckValue(input, nameof(input)); h.CheckUserArg(Utils.Size(args.Column) > 0, nameof(args.Column)); var columns = new List <CategoricalEstimator.ColumnInfo>(); foreach (var column in args.Column) { var col = new CategoricalEstimator.ColumnInfo( column.Source ?? column.Name, column.Name, column.OutputKind ?? args.OutputKind, column.MaxNumTerms ?? args.MaxNumTerms, column.Sort ?? args.Sort, column.Term ?? args.Term); col.SetTerms(column.Terms); columns.Add(col); } return(new CategoricalEstimator(env, columns.ToArray()).Fit(input).Transform(input) as IDataTransform); }