Exemple #1
0
        private static void ByClientMode(string dataPath, string ids, string target, DataModifier modifier, AbstractClassifier cls)
        {
            try
            {
                cls.LoadClassifier();

                // loading data
                var loader = target == null ? new DataLoader() : new DataLoader(target);
                loader.AddIdsString(ids);
                loader.Load(dataPath);

                using (var sw = new StreamWriter(new FileStream(dataPath + "_calc.csv", FileMode.Create, FileAccess.Write)))
                {
                    if (target!=null)
                        sw.WriteLine(loader.IdName + ";prob;target");
                    else
                        sw.WriteLine(loader.IdName + ";prob");

                    int idx = 0;
                    // calculating prob for each row
                    foreach (var row in loader.Rows)
                    {
                        idx++;
                        double[] mvals = GetRowValues(modifier, loader, row);
                        var prob = cls.PredictProba(mvals);

                        string targStr = target != null ? (";" + row.Target) : null;
                        string oinfo = prob.ObjectInfo != null ? (";" + prob.ObjectInfo) : null;
                        sw.WriteLine(row.Id + ";" + prob.Probs[1] + targStr + oinfo);

                        if (idx % 123 == 0)
                        {
                            Logger.Log(idx + " lines writed;");
                            sw.Flush();
                        }
                    }

                    Logger.Log(idx + " lines writed; done;");

                    sw.Close();
                }
            }
            catch (Exception e)
            {
                Logger.Log(e);
            }
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            string DataPath = ConfigReader.Read("DataPath");
            string ConfPath = ConfigReader.Read("ConfPath");
            int BucketSize = int.Parse(ConfigReader.Read("BucketSize"));
            string ClassifierType = ConfigReader.Read("ClassifierType");
            string IdName = ConfigReader.Read("IdName");
            string TargetName = ConfigReader.Read("TargetName");

            Logger.Log("DataPath = " + DataPath);
            Logger.Log("ConfPath = " + ConfPath);
            Logger.Log("ClassifierType = " + ClassifierType);
            Logger.Log("IdName = " + IdName);
            Logger.Log("TargetName = " + TargetName);

            try
            {
                // loading modifier
                DataModifier modifier = null;
                if (ConfPath != null)
                    modifier = new DataModifier(File.ReadAllLines(ConfPath));

                // loading classifier
                AbstractClassifier cls = LoadClassifier(ClassifierType);

                //if (BucketSize > 0)
                //{
                //    // by tree bucket mode
                //    Logger.Log("by tree bucket mode, BucketSize = " + BucketSize);
                //    ByBucketMode(DataPath, IdName, TargetName, BucketSize, modifier);
                //}
                //else
                //{
                // by client mode
                Logger.Log("by client mode");
                ByClientMode(DataPath, IdName, TargetName, modifier, cls);
                //}
            }
            catch (Exception e)
            {
                Logger.Log(e);
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            string DataInPath = ConfigReader.Read("DataInPath");
            string DataOutPath = ConfigReader.Read("DataOutPath");
            string ConfigPath = ConfigReader.Read("ConfigPath");

            Logger.Log("DataInPath: " + DataInPath);
            Logger.Log("DataOutPath : " + DataOutPath);
            Logger.Log("ConfigPath: " + ConfigPath);

            try
            {
                _modifier = ConfigPath == null ? null : new DataModifier(File.ReadAllLines(ConfigPath));
                _sw = new StreamWriter(new FileStream(DataOutPath, FileMode.Create, FileAccess.Write), Encoding.GetEncoding(1251));

                _loader.ProceedRowFunc = ProceedRow;
                _loader.Load(DataInPath);
            }
            catch (Exception e)
            {
                Logger.Log(e);
            }
            finally
            {
                _sw.Close();
            }
        }
Exemple #4
0
        private static double[] GetRowValues(DataModifier modifier, DataLoader loader, Domain.DataRow<float> row)
        {
            if (modifier == null)
                return Array.ConvertAll(row.Coeffs, x => (double)x);

            var vals = new Dictionary<string, double>();
            for (int i = 0; i < row.Coeffs.Length; i++)
            {
                string colname = loader.RowColumnByIdx[i];
                vals.Add(colname, row.Coeffs[i]);
            }
            var mvals = modifier.GetModifiedDataVector(vals);
            return mvals;
        }