Beispiel #1
0
        public void TestExpandToOneHot()
        {
            var df     = new DataFrame();
            var column = new DataFrameColumn <int>(null, new int[] { 1, 2, 3 });

            df.DefineNewColumn("a", column);

            df.ExpandToOneHot("a", 4);

            Assert.AreEqual(3, df.RowCount);
            Assert.AreEqual(4, df.ColumnCount);

            Assert.AreEqual(0, df["a_0"].GetObject(0));
            Assert.AreEqual(1, df["a_1"].GetObject(0));
            Assert.AreEqual(0, df["a_2"].GetObject(0));
            Assert.AreEqual(0, df["a_3"].GetObject(0));

            Assert.AreEqual(0, df["a_0"].GetObject(1));
            Assert.AreEqual(0, df["a_1"].GetObject(1));
            Assert.AreEqual(1, df["a_2"].GetObject(1));
            Assert.AreEqual(0, df["a_3"].GetObject(1));

            Assert.AreEqual(0, df["a_0"].GetObject(2));
            Assert.AreEqual(0, df["a_1"].GetObject(2));
            Assert.AreEqual(0, df["a_2"].GetObject(2));
            Assert.AreEqual(1, df["a_3"].GetObject(2));
        }
        protected override void EndProcessing()
        {
            var df = new DataFrame();

            if (Transpose)
            {
                bool first = true;
                foreach (int[] seq in Combinatorics.Sequences(Symbols, true))
                {
                    if (first)
                    {
                        for (var column = 0; column < seq.Length; ++column)
                        {
                            df.AddColumn <int>("c" + column);
                        }
                        first = false;
                    }

                    for (var column = 0; column < seq.Length; ++column)
                    {
                        df.GetColumn(column).SetObject(column, seq[column]);
                    }
                }
            }
            else
            {
                int column = 0;
                foreach (int[] seq in Combinatorics.Sequences(Symbols, true))
                {
                    df.DefineNewColumn("c" + column, new DataFrameColumn <int>(df, seq));
                    ++column;
                }
            }

            WriteObject(df);
        }