コード例 #1
0
ファイル: Experiment.cs プロジェクト: lulzzz/gpdotnet
        /// <summary>
        /// Creates columns based of the columns properties argument
        /// </summary>
        /// <param name="colProp"></param>
        /// <returns></returns>
        private ColumnData CreateColumn(MetaColumn colProp)
        {
            //determine column type
            ColumnType colType;

            if (colProp.Type.Equals("Numeric", StringComparison.OrdinalIgnoreCase))
            {
                colType = ColumnType.Numeric;
            }
            else if (colProp.Type.Equals("Binary", StringComparison.OrdinalIgnoreCase))
            {
                colType = ColumnType.Binary;
            }
            else if (colProp.Type.Equals("Category", StringComparison.OrdinalIgnoreCase) || colProp.Type.Equals("Categorical", StringComparison.OrdinalIgnoreCase))
            {
                colType = ColumnType.Category;
            }
            else
            {
                colType = ColumnType.Unknown;
            }

            //determine encoding for category column type
            CategoryEncoding colEncoding;

            if (colProp.Encoding.Equals("Level", StringComparison.OrdinalIgnoreCase))
            {
                colEncoding = CategoryEncoding.Level;
            }
            else if (colProp.Encoding.Equals("1 out of N-1", StringComparison.OrdinalIgnoreCase) ||
                     colProp.Encoding.Equals("OnevsAll_1", StringComparison.OrdinalIgnoreCase))
            {
                colEncoding = CategoryEncoding.OnevsAll_1;
            }
            else if (colProp.Encoding.Equals("1 out of N", StringComparison.OrdinalIgnoreCase) ||
                     colProp.Encoding.Equals("OnevsAll", StringComparison.OrdinalIgnoreCase))
            {
                colEncoding = CategoryEncoding.OnevsAll;
            }
            else
            {
                colEncoding = CategoryEncoding.None;
            }


            //create column data type
            var isOutput = colProp.Param.Equals("Output", StringComparison.OrdinalIgnoreCase);

            ColumnData col = new ColumnData(isOutput);

            if (colProp.Scale.Equals("MinMax", StringComparison.OrdinalIgnoreCase))
            {
                col.SetNormalization(Scaling.MinMax);
            }
            else if (colProp.Scale.Equals("Gauss", StringComparison.OrdinalIgnoreCase))
            {
                col.SetNormalization(Scaling.Gauss);
            }
            else if (colProp.Scale.Equals("None", StringComparison.OrdinalIgnoreCase))
            {
                col.SetNormalization(Scaling.None);
            }
            else
            {
                col.SetNormalization(Scaling.None);
            }


            //set missing value action
            if (colProp.MissingValue.Equals("Ignore", StringComparison.OrdinalIgnoreCase))
            {
                col.MissingValue = MissingValue.Ignore;
            }
            else if (colProp.MissingValue.Equals("Average", StringComparison.OrdinalIgnoreCase))
            {
                col.MissingValue = MissingValue.Average;
            }
            else if (colProp.MissingValue.Equals("Random", StringComparison.OrdinalIgnoreCase))
            {
                col.MissingValue = MissingValue.Random;
            }
            else if (colProp.MissingValue.Equals("Mode", StringComparison.OrdinalIgnoreCase))
            {
                col.MissingValue = MissingValue.Mode;
            }
            else if (colProp.MissingValue.Equals("Max", StringComparison.OrdinalIgnoreCase))
            {
                col.MissingValue = MissingValue.Max;
            }
            else
            {
                col.MissingValue = MissingValue.Min;
            }

            //set column name and type
            col.Name           = colProp.Name;
            col.ColumnDataType = colType;
            col.Encoding       = colEncoding;
            col.Id             = colProp.Id;
            col.Index          = colProp.Index;
            return(col);
        }