1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 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 System.Collections;
|
---|
24 | using System.Collections.Generic;
|
---|
25 | using System.Linq;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Problems.DataAnalysis.Benchmarks {
|
---|
29 | public class Iris : ClassificationRealWorldBenchmark {
|
---|
30 |
|
---|
31 | private const string fileName = "iris.data";
|
---|
32 |
|
---|
33 | public Iris() {
|
---|
34 | Name = "RealWorldProblem Iris";
|
---|
35 | Description = "Data Set Information: This is perhaps the best known database to be found in the pattern "
|
---|
36 | + "recognition literature. Fisher's paper is a classic in the field and is referenced frequently to this "
|
---|
37 | + "day. (See Duda & Hart, for example.) The data set contains 3 classes of 50 instances each, where each class "
|
---|
38 | + "refers to a type of iris plant. One class is linearly separable from the other 2; the latter are NOT linearly "
|
---|
39 | + "separable from each other." + Environment.NewLine
|
---|
40 | + "Website: http://archive.ics.uci.edu/ml/datasets/Iris" + Environment.NewLine
|
---|
41 | + "Attribute Information:" + Environment.NewLine
|
---|
42 | + "1. sepal length in cm" + Environment.NewLine
|
---|
43 | + "2. sepal width in cm" + Environment.NewLine
|
---|
44 | + "3. petal length in cm" + Environment.NewLine
|
---|
45 | + "4. petal width in cm" + Environment.NewLine
|
---|
46 | + "5. class:" + Environment.NewLine
|
---|
47 | + "-- Iris Setosa" + Environment.NewLine
|
---|
48 | + "-- Iris Versicolour" + Environment.NewLine
|
---|
49 | + "-- Iris Virginica" + Environment.NewLine + Environment.NewLine
|
---|
50 | + "Note: Iris Setosa = 0; Iris Versicolour = 1; Iris Virginica = 2;";
|
---|
51 | }
|
---|
52 |
|
---|
53 | protected override List<IList> GetData() {
|
---|
54 | csvFileParser = Benchmark.getParserForFile(fileName);
|
---|
55 |
|
---|
56 | targetVariable = csvFileParser.VariableNames.Last();
|
---|
57 | inputVariables = new List<string>(csvFileParser.VariableNames.Take(csvFileParser.Columns - 1));
|
---|
58 | int trainingPartEnd = csvFileParser.Rows * 2 / 3;
|
---|
59 | trainingPartition = new IntRange(0, trainingPartEnd);
|
---|
60 | testPartition = new IntRange(trainingPartEnd, csvFileParser.Rows);
|
---|
61 |
|
---|
62 | //get ordered list
|
---|
63 | List<IList> orderList = csvFileParser.Values.Skip(csvFileParser.Columns - 1).Union(csvFileParser.Values.Take(csvFileParser.Columns - 1)).ToList();
|
---|
64 |
|
---|
65 | IEnumerable<int> random = Enumerable.Range(0, orderList[0].Count).OrderBy(x => rand.Next());
|
---|
66 |
|
---|
67 | List<IList> result = new List<IList>();
|
---|
68 |
|
---|
69 | foreach (var item in orderList) {
|
---|
70 | result.Add(new List<double>());
|
---|
71 | }
|
---|
72 | foreach (var index in random) {
|
---|
73 | for (int i = 0; i < orderList.Count; i++) {
|
---|
74 | result[i].Add(orderList[i][index]);
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | return result;
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|