1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Windows.Forms;
|
---|
6 | using HeuristicLab.DataImporter.Data;
|
---|
7 | using HeuristicLab.DataImporter.Data.CommandBase;
|
---|
8 | using HeuristicLab.DataImporter.Data.Model;
|
---|
9 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
10 |
|
---|
11 | namespace HeuristicLab.DataImporter.Command {
|
---|
12 | [StorableClass]
|
---|
13 | [ViewableCommandInfoAttribute("Mean", 1, ColumnGroupState.DoubleColumnSelected | ColumnGroupState.AnySelectedColumnContainsNull,
|
---|
14 | "Handle Missing Values", Position = 0)]
|
---|
15 | public class FillMissingValuesWithMeanCommand : FillMissingValueCommandBase {
|
---|
16 | private FillMissingValuesWithMeanCommand()
|
---|
17 | : base(null, string.Empty, null) {
|
---|
18 | }
|
---|
19 |
|
---|
20 | public FillMissingValuesWithMeanCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns) :
|
---|
21 | base(dataSet, columnGroupName, affectedColumns) {
|
---|
22 | }
|
---|
23 |
|
---|
24 | public override void Execute() {
|
---|
25 | base.Execute();
|
---|
26 | DoubleColumn column;
|
---|
27 | double? mean;
|
---|
28 | oldSortOrder = ColumnGroup.SortOrdersForColumns.ToList();
|
---|
29 | oldSortedColumnIndexes = new List<int>(ColumnGroup.SortedColumnIndexes);
|
---|
30 | foreach (int col in AffectedColumns) {
|
---|
31 | if (ColumnGroup.GetColumn(col) is DoubleColumn && ColumnGroup.GetColumn(col).ContainsNullValues) {
|
---|
32 | column = (DoubleColumn)ColumnGroup.Columns.ElementAt(col);
|
---|
33 | if (column.SortOrder != SortOrder.None)
|
---|
34 | ColumnGroup.ResetSorting();
|
---|
35 | nullValues.Add(col, new List<int>());
|
---|
36 | mean = column.Mean;
|
---|
37 | for (int j = 0; j < column.TotalValuesCount; j++) {
|
---|
38 | if (column.GetValue(j) == null) {
|
---|
39 | column.ChangeValue(j, mean);
|
---|
40 | this.nullValues[col].Add(j);
|
---|
41 | }
|
---|
42 | }
|
---|
43 | }
|
---|
44 | }
|
---|
45 | ColumnGroup.FireChanged();
|
---|
46 | ColumnGroup = null;
|
---|
47 | }
|
---|
48 |
|
---|
49 | public override string Description {
|
---|
50 | get { return "Fill missing values with mean"; }
|
---|
51 | }
|
---|
52 | }
|
---|
53 | }
|
---|