[2340] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.DataAnalysis;
|
---|
| 26 | using System.Linq;
|
---|
| 27 |
|
---|
[2351] | 28 | namespace HeuristicLab.Modeling {
|
---|
[2340] | 29 | public class TargetClassesCalculator : OperatorBase {
|
---|
| 30 |
|
---|
| 31 | public TargetClassesCalculator()
|
---|
| 32 | : base() {
|
---|
| 33 | AddVariableInfo(new VariableInfo("Dataset", "The dataset", typeof(Dataset), VariableKind.In));
|
---|
[2440] | 34 | AddVariableInfo(new VariableInfo("TargetVariable", "Name the target variable", typeof(StringData), VariableKind.In));
|
---|
[2340] | 35 | AddVariableInfo(new VariableInfo("TargetClassValues", "The original class values of target variable (for instance negative=0 and positive=1).", typeof(ItemList<DoubleData>), VariableKind.New));
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | public override IOperation Apply(IScope scope) {
|
---|
| 39 | Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
|
---|
[2440] | 40 | string targetVariable = GetVariableValue<StringData>("TargetVariable", scope, true).Data;
|
---|
[2340] | 41 |
|
---|
| 42 | ItemList<DoubleData> classes = new ItemList<DoubleData>();
|
---|
[2351] | 43 | foreach (double x in dataset.GetVariableValues(targetVariable).Distinct().OrderBy(v => v)) {
|
---|
[2340] | 44 | classes.Add(new DoubleData(x));
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TargetClassValues"), classes));
|
---|
| 48 | return null;
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | }
|
---|