| 53 | |
| 54 | /// <inheritdoc /> |
| 55 | public IDataView Transform(IDataView input) |
| 56 | { |
| 57 | HashSet<string> numTypes = new HashSet<string> |
| 58 | { |
| 59 | "Boolean", "Single", "Int32" |
| 60 | }; |
| 61 | |
| 62 | int nFloat = 0, nCat = 0; |
| 63 | Collection<int> catFeatureIxs = new Collection<int>(); |
| 64 | |
| 65 | using (var cursor = input.GetRowCursor(input.Schema)) |
| 66 | { |
| 67 | cursor.MoveNext(); |
| 68 | int ix = -1; |
| 69 | int ptr = 0; |
| 70 | foreach (var col in cursor.Schema) |
| 71 | { |
| 72 | ix++; |
| 73 | if (col.Name == TargetFeature) |
| 74 | { |
| 75 | continue; |
| 76 | } |
| 77 | |
| 78 | string typeId = col.Type.ToString(); |
| 79 | if (numTypes.Contains(typeId)) |
| 80 | { |
| 81 | nFloat++; |
| 82 | } |
| 83 | else if (typeId == "String") |
| 84 | { |
| 85 | catFeatureIxs.Add(ptr); |
| 86 | nCat++; |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | throw new NotSupportedException($"Data type {typeId} is not supported."); |
| 91 | } |
| 92 | ptr++; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | List<float[]> floatFeatures = new List<float[]>(); |
| 97 | List<string[]> catFeatures = new List<string[]>(); |
| 98 | |
| 99 | using (var cursor = input.GetRowCursor(input.Schema)) |
| 100 | { |
| 101 | int rowIx = 0; |
| 102 | while (cursor.MoveNext()) |
| 103 | { |
| 104 | int ix = -1; |
| 105 | int ptr = 0; |
| 106 | int realPtr = 0; |
| 107 | int catPtr = 0; |
| 108 | |
| 109 | float[] floats = new float[nFloat]; |
| 110 | string[] cats = new string[nCat]; |
| 111 | |
| 112 | foreach (var col in cursor.Schema) |