public void TestOldSavingAndLoading() { var data = new[] { new TestClass() { A = "1", B = "2", C = "3", }, new TestClass() { A = "4", B = "5", C = "6" } }; var dataView = ComponentCreation.CreateDataView(Env, data); var pipe = new OneHotHashEncodingEstimator(Env, new[] { new OneHotHashEncodingEstimator.ColumnInfo("A", "CatHashA"), new OneHotHashEncodingEstimator.ColumnInfo("B", "CatHashB"), new OneHotHashEncodingEstimator.ColumnInfo("C", "CatHashC") }); var result = pipe.Fit(dataView).Transform(dataView); var resultRoles = new RoleMappedData(result); using (var ms = new MemoryStream()) { TrainUtils.SaveModel(Env, Env.Start("saving"), ms, null, resultRoles); ms.Position = 0; var loadedView = ModelFileUtils.LoadTransforms(Env, dataView, ms); } }
public void TestMetadataPropagation() { var data = new[] { new TestMeta() { A = new string[2] { "A", "B" }, B = "C", C = new float[2] { 1.0f, 2.0f }, D = 1.0f, E = new string[2] { "A", "D" }, F = "D" }, new TestMeta() { A = new string[2] { "A", "B" }, B = "C", C = new float[2] { 3.0f, 4.0f }, D = -1.0f, E = new string[2] { "E", "A" }, F = "E" }, new TestMeta() { A = new string[2] { "A", "B" }, B = "C", C = new float[2] { 5.0f, 6.0f }, D = 1.0f, E = new string[2] { "D", "E" }, F = "D" } }; var dataView = ComponentCreation.CreateDataView(Env, data); var bagPipe = new OneHotHashEncodingEstimator(Env, new OneHotHashEncodingEstimator.ColumnInfo("A", "CatA", OneHotEncodingTransformer.OutputKind.Bag, invertHash: -1), new OneHotHashEncodingEstimator.ColumnInfo("B", "CatB", OneHotEncodingTransformer.OutputKind.Bag, invertHash: -1), new OneHotHashEncodingEstimator.ColumnInfo("C", "CatC", OneHotEncodingTransformer.OutputKind.Bag, invertHash: -1), new OneHotHashEncodingEstimator.ColumnInfo("D", "CatD", OneHotEncodingTransformer.OutputKind.Bag, invertHash: -1), new OneHotHashEncodingEstimator.ColumnInfo("E", "CatE", OneHotEncodingTransformer.OutputKind.Ind, invertHash: -1), new OneHotHashEncodingEstimator.ColumnInfo("F", "CatF", OneHotEncodingTransformer.OutputKind.Ind, invertHash: -1), new OneHotHashEncodingEstimator.ColumnInfo("A", "CatG", OneHotEncodingTransformer.OutputKind.Key, invertHash: -1), new OneHotHashEncodingEstimator.ColumnInfo("B", "CatH", OneHotEncodingTransformer.OutputKind.Key, invertHash: -1), new OneHotHashEncodingEstimator.ColumnInfo("A", "CatI", OneHotEncodingTransformer.OutputKind.Bin, invertHash: -1), new OneHotHashEncodingEstimator.ColumnInfo("B", "CatJ", OneHotEncodingTransformer.OutputKind.Bin, invertHash: -1)); var bagResult = bagPipe.Fit(dataView).Transform(dataView); ValidateMetadata(bagResult); Done(); }