private PipelineItemDebugRow[] BuildRows()
        {
            PipelineItemDebugRow[] result = new PipelineItemDebugRow[MaxDisplayRows];

            int       i = 0;
            IDataView pipelineResult = ExecutePipeline();

            if (_pipelineExecutionException != null)
            {
                result[0] = new PipelineItemDebugRow()
                {
                    Values = _pipelineExecutionException.ToString()
                };
                return(result);
            }

            StringBuilder valuesBuilder = new StringBuilder();

            using (var cursor = pipelineResult.GetRowCursor(c => true))
            {
                var colIndices = GetColIndices(pipelineResult);
                var colCount   = colIndices.Count;

                var getters = DataViewUtils.PopulateGetterArray(cursor, colIndices);

                var row = new ReadOnlyMemory <char> [colCount];
                while (cursor.MoveNext() && i < MaxDisplayRows)
                {
                    for (int column = 0; column < colCount; column++)
                    {
                        if (column != 0)
                        {
                            valuesBuilder.Append(" | ");
                        }

                        getters[column](ref row[column]);
                        valuesBuilder.Append(row[column]);
                    }

                    result[i] = new PipelineItemDebugRow()
                    {
                        Values = valuesBuilder.ToString()
                    };

                    valuesBuilder.Clear();
                    i++;
                }
            }

            return(result);
        }
예제 #2
0
        public static Type InferPredictorCategoryType(IDataView data, PurposeInference.Column[] columns)
        {
            List <PurposeInference.Column> labels = columns.Where(col => col.Purpose == ColumnPurpose.Label).ToList();

            if (labels.Count == 0)
            {
                return(typeof(SignatureClusteringTrainer));
            }

            if (labels.Count > 1)
            {
                return(typeof(SignatureMultiOutputRegressorTrainer));
            }

            PurposeInference.Column label             = labels.First();
            HashSet <string>        uniqueLabelValues = new HashSet <string>();

            data = data.Take(1000);
            using (var cursor = data.GetRowCursor(index => index == label.ColumnIndex))
            {
                ValueGetter <DvText> getter = DataViewUtils.PopulateGetterArray(cursor, new List <int> {
                    label.ColumnIndex
                })[0];
                while (cursor.MoveNext())
                {
                    var currentLabel = new DvText();
                    getter(ref currentLabel);
                    string currentLabelString = currentLabel.ToString();
                    if (!String.IsNullOrEmpty(currentLabelString) && !uniqueLabelValues.Contains(currentLabelString))
                    {
                        uniqueLabelValues.Add(currentLabelString);
                    }
                }
            }

            if (uniqueLabelValues.Count == 1)
            {
                return(typeof(SignatureAnomalyDetectorTrainer));
            }

            if (uniqueLabelValues.Count == 2)
            {
                return(typeof(SignatureBinaryClassifierTrainer));
            }

            if (uniqueLabelValues.Count > 2)
            {
                if ((label.ItemKind == DataKind.R4) &&
                    uniqueLabelValues.Any(val =>
                {
                    float fVal;
                    return(float.TryParse(val, out fVal) && (fVal > 50 || fVal < 0 || val.Contains('.')));
                }))
                {
                    return(typeof(SignatureRegressorTrainer));
                }

                if (label.ItemKind == DataKind.R4 ||
                    label.ItemKind == DataKind.TX ||
                    data.Schema.GetColumnType(label.ColumnIndex).IsKey)
                {
                    if (columns.Any(col => col.Purpose == ColumnPurpose.Group))
                    {
                        return(typeof(SignatureRankerTrainer));
                    }
                    else
                    {
                        return(typeof(SignatureMultiClassClassifierTrainer));
                    }
                }
            }

            return(null);
        }