Ejemplo n.º 1
0
        public static DataMap FromJagged <T>(T[][] source, string[] columnNames = null, bool transpose = false, IEqualityComparer <string> keyComparaer = null)
        {
            var result = new DataMap(keyComparaer);

            if (!transpose)
            {
                if (columnNames == null)
                {
                    var c = source[0].Length;
                    columnNames = new string[c];
                    for (var i = 0; i < c; ++i)
                    {
                        columnNames[i] = "Column" + i;
                    }
                }

                for (var i = 0; i < columnNames.Length; ++i)
                {
                    var data = new List <T>(source.Length);
                    result.Add(columnNames[i], data);
                    for (var j = 0; j < source.Length; ++j)
                    {
                        var row = source[j];
                        if (i < row.Length)
                        {
                            data.Add(row[i]);
                        }
                        else
                        {
                            data.Add(TypeTrait <T> .GetNaN());
                        }
                    }
                }
            }
            else
            {
                if (columnNames == null)
                {
                    var c = source.Length;
                    columnNames = new string[c];
                    for (var i = 0; i < c; ++i)
                    {
                        columnNames[i] = "Column" + i;
                    }
                }

                for (var i = 0; i < columnNames.Length; ++i)
                {
                    result.Add(columnNames[i], source[i]);
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        /*
         *      public static DataMap FromDictionary(IDictionary<string, IList> source)
         *      {
         *          var result = new DataMap();
         *
         *          foreach (var entry in source)
         *              result.AddLast(entry.Key, entry.Value);
         *
         *          return result;
         *      }
         */

        public static DataMap FromDictionary(IDictionary source, IEqualityComparer <string> keyComparaer = null)
        {
            var result = new DataMap(keyComparaer);

            foreach (DictionaryEntry entry in source)
            {
                result.AddLast((string)entry.Key, (IList)entry.Value);
            }

            return(result);
        }
Ejemplo n.º 3
0
        public JoinKeyMap(DataMap dataMap, string[] keyColumns)
        {
            if (keyColumns.Length > 6)
            {
                throw new ArgumentException("More than six key columns are not supported");
            }

            _dataMap    = dataMap;
            _keyColumns = keyColumns;
            _indexMap   = GetJoinKeyMap();
        }
Ejemplo n.º 4
0
        public KFoldSplitter(DataMap dataMap, int k, bool shuffle = false, IRandom random = null)
        {
            _k       = k;
            _dataMap = dataMap;
            _folds   = new int[dataMap.MaxRowCount];

            for (var i = 0; i < _folds.Length; ++i)
            {
                _folds[i] = (int)(i / k);
            }

            if (shuffle)
            {
                _folds.ShuffleFill(random);
            }
        }
Ejemplo n.º 5
0
 public DataMapEnumerator(DataMap map)
 {
     _e = map.Columns.GetEnumerator();
 }
Ejemplo n.º 6
0
 public KFold(int k, DataMap training, DataMap validation)
 {
     K          = k;
     Training   = training;
     Validation = validation;
 }