internal C45FeatureSetCollection GetFSCFromFile(String filename) { C45FeatureSetCollection featureSetCollection = new C45FeatureSetCollection(); C45Schema schema = C45Schema.CreateFromFile(filename.Replace(".data".ToString(), ".names".ToString())); int character = 0; String line = String.Empty; FileStream file = new FileStream( filename, FileMode.Open); while (character >= 0) { line = String.Empty; character = file.ReadByte(); while (character != 0x0A && character > 0) { line += Convert.ToChar(character); character = file.ReadByte(); } featureSetCollection.Add(C45FeatureSet.GetFSFromLine(line, schema)); } return(featureSetCollection); }
private void AppendFeatureValueFromGridView( DataGridViewCell cell, C45FeatureSet featureSet) { if (cell.ColumnIndex < this.schema.Properties.Count) { String cellValue = String.Empty; if (cell.IsInEditMode) { cellValue = cell.EditedFormattedValue.ToString(); } else { cellValue = cell.FormattedValue.ToString(); } C45SchemaProperty col = (C45SchemaProperty)this.dataGridView.Columns[cell.ColumnIndex].Tag; if (cellValue == "?".ToString() || cellValue == "".ToString()) { featureSet.AddUnknownFeature(); } else { if (col.IsDiscrete) { // Just one attribute with 100 % probability supported, yet. // Multiple attribute has to be implemented in future. C45DiscreteFeature discreteFeature = new C45DiscreteFeature(); C45DiscreteFeatureAttribute discreteFeatureAttribute = new C45DiscreteFeatureAttribute(); discreteFeatureAttribute.AttributeName = (String)cellValue; discreteFeatureAttribute.Probability = 100; discreteFeature.Add(discreteFeatureAttribute); featureSet.AddDiscreteFeature(discreteFeature); } else { // Just a fix continous value or ignore-value supported, yet. // Lower and upper bound has to be implemented in future. C45ContinuousFeature continuousFeature = new C45ContinuousFeature(); continuousFeature.LowerBound = Convert.ToInt32(cellValue); continuousFeature.UpperBound = Convert.ToInt32(cellValue); featureSet.AddContinousFeature(continuousFeature); } } } }
private C45FeatureSet GetFeatureSetFromGrid(DataGridViewRow row) { C45FeatureSet newSet = new C45FeatureSet(); foreach (DataGridViewCell cell in row.Cells) { this.AppendFeatureValueFromGridView(cell, newSet); } newSet.IsMarked = row.Selected; newSet.UserResult.ClassName = row.Cells[this.userClassColumn].FormattedValue.ToString(); return(newSet); }
internal static C45FeatureSet GetFSFromLine(String line, C45Schema schema) { C45FeatureSet featureSet = new C45FeatureSet(); int currentFeature = 0; String[] features = line.Split(",".ToCharArray()); for (int i = 0; i < features.Length; i++) { features[i] = features[i].Trim(); } foreach (C45SchemaProperty column in schema.Properties) { if (features[currentFeature] == "" || features[currentFeature] == "?") { featureSet.AddUnknownFeature(); } else { if (column.IsDiscrete) { C45DiscreteFeature discreteFeature = new C45DiscreteFeature(); C45DiscreteFeatureAttribute discreteFeatureAttribute = new C45DiscreteFeatureAttribute(); discreteFeatureAttribute.AttributeName = features[currentFeature]; discreteFeatureAttribute.Probability = 100; discreteFeature.Add(discreteFeatureAttribute); featureSet.AddDiscreteFeature(discreteFeature); } else { C45ContinuousFeature continuousFeature = new C45ContinuousFeature(); continuousFeature.LowerBound = Convert.ToInt32(features[currentFeature]); continuousFeature.UpperBound = Convert.ToInt32(features[currentFeature]); featureSet.AddContinousFeature(continuousFeature); } } currentFeature++; } featureSet.UserResult.ClassName = features[currentFeature]; return(featureSet); }
private void InsertFeatureSetIntoGridView( C45FeatureSet fs, int rowIndex) { int columnIndex = 0; foreach (object f in fs) { this.InsertFeatureValueIntoGridView( f, columnIndex, rowIndex); columnIndex++; } }
public void AddResult( C45FeatureSet featureSet, String result) { try { String dataFile = this.Settings.C45SchemaFilename + @".data"; FileStream fs = new FileStream(dataFile, FileMode.Append); String newCase = String.Empty; for (int i = 0; i < featureSet.Count; i++) { if (featureSet._featureArray[i].bIsKnown) { if (featureSet._featureArray[i].bIsDiscreteFeature) { newCase += this.ConvertByteArrayToString(featureSet._featureArray[i].discreteFeature.data, 4) + @","; } else { //Calculate the average continuous value int continuous = Convert.ToInt32((featureSet._featureArray[i].continuousFeature.fLowerBound + featureSet._featureArray[i].continuousFeature.fUpperBound) / 2); newCase += continuous.ToString() + @","; } } else { newCase += @"?,"; } } newCase += result; fs.WriteByte(0x0A); foreach (byte b in newCase.ToCharArray()) { fs.WriteByte(b); } fs.Close(); } catch (Exception ex) { throw (new C45Exception(C45Exceptions.CASES_NOT_ADDED, ex)); } }