【发布时间】:2014-02-17 10:38:38
【问题描述】:
我有一个输入
5.3,3.6,1.6,0.3,Iris-setosa
4.9,3.3,1.6,0.3,Iris-setosa
4.9,3.3,1.3,0.3,Iris-setosa
4.6,3.3,1.6,0.3,Iris-setosa
5.3,3.6,1.6,0.3,Iris-setosa
我有一个列表
BinList {3=[index=0 {from=1.3,to=1.42}, index=1 {from=1.42,to=1.5399999999999998}, index=2 {from=1.5399999999999998,to=1.6599999999999997}, index=3 {from=1.6599999999999997,to=1.7799999999999996}, index=4 {from=1.7799999999999996,to=1.8999999999999995}, index=5 {from=1.8999999999999995,to=1.9}], 2=[index=0 {from=2.9,to=3.2399999999999998}, index=1 {from=3.2399999999999998,to=3.5799999999999996}, index=2 {from=3.5799999999999996,to=3.9199999999999995}, index=3 {from=3.9199999999999995,to=4.26}, index=4 {from=4.26,to=4.6}, index=5 {from=4.6,to=4.6}], 1=[index=0 {from=4.3,to=4.62}, index=1 {from=4.62,to=4.94}, index=2 {from=4.94,to=5.260000000000001}, index=3 {from=5.260000000000001,to=5.580000000000001}, index=4 {from=5.580000000000001,to=5.9}], 4=[index=0 {from=0.3,to=0.36}, index=1 {from=0.36,to=0.42}, index=2 {from=0.42,to=0.48}, index=3 {from=0.48,to=0.54}, index=4 {from=0.54,to=0.6}]}
例如在哪里
3=[index=0 {from=1.3,to=1.42}, index=1 {from=1.42,to=1.5399999999999998}, index=2 {from=1.5399999999999998,to=1.6599999999999997}, index=3 {from=1.6599999999999997,to=1.7799999999999996}, index=4 {from=1.7799999999999996,to=1.8999999999999995}, index=5 {from=1.8999999999999995,to=1.9}]
key 3 代表column number,value 代表Index 和range。
例如
5.3,3.6,1.6,0.3,Iris-setosa
这应该替换为索引值。
3,2,2,0,Iris-setosa
到目前为止我所做的是
我找到了索引并尝试将已识别的索引添加到列表中。 但是我的列表没有更新。我无法在列表中添加最后一个标记 我得到正确的索引。 代码
List<String> mapList = new ArrayList<String>();
Map<String, List<Attribute>> binList = new HashMap<String, List<Attribute>>();
//mapList contains the input value
for (String temp : mapList) {
System.out.println("temp: "+temp);
//Setting column number for inputdata
int indexMap=1;
StringTokenizer st = new StringTokenizer(temp,",");
while(st.hasMoreTokens()){
String token = st.nextToken();
System.out.println("token ()"+token);
//Checking to find same column number in list
List<String> mapFinalList = new ArrayList<String>();
for (Map.Entry<String, List<Attribute>> entry : binList.entrySet())
{
//Key similarity
if(entry.getKey().equals(String.valueOf(indexMap))){
System.out.println("equal"+entry.getKey()+"=="+indexMap);
//Iterating through the values of found out key
for (Attribute a : entry.getValue())
{
//Parsing the values
ParseValue.parse(a).toString();
int index = ParseValue.getIndex();
double rangeFrom = ParseValue.getrangeFrom();
double rangeTo = ParseValue.getrangeTo();
// Condition Checking for bins
if((Double.parseDouble(token) <= rangeTo)&& (Double.parseDouble(token) < rangeTo)){
System.out.println("replace: "+index);
if(mapFinalList == null) {
mapFinalList = new ArrayList<String>();
}
mapFinalList.add(String.valueOf(index));
System.out.println("List "+mapFinalList);
break;
}//if loop
}//for loop
}//if loop
}//for loop
indexMap++;
}//while
}//for
输出
In BinningInput
5.3,3.6,1.6,0.3,Iris-setosa
temp: 5.3,3.6,1.6,0.3,Iris-setosa
token ()5.3
equal1==1
replace: 3
List [3]
token ()3.6
equal2==2
replace: 2
List [2]
token ()1.6
equal3==3
replace: 2
List [2]
token ()0.3
equal4==4
replace: 0
List [0]
token ()Iris-setosa
请提出建议。
【问题讨论】:
-
您的意思是每次添加索引时您的值都会被替换?