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); }
/* * 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); }
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(); }
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); } }
public DataMapEnumerator(DataMap map) { _e = map.Columns.GetEnumerator(); }
public KFold(int k, DataMap training, DataMap validation) { K = k; Training = training; Validation = validation; }