~ schnellere Version mit weniger Weka
#SPM-17 add work development 20m
This commit is contained in:
parent
5541e1b9c8
commit
f3770b09f9
|
@ -1,10 +1,7 @@
|
|||
package de.hsel.spm.baudas.analysis;
|
||||
|
||||
import weka.core.AttributeStats;
|
||||
import weka.core.Instance;
|
||||
import weka.core.Instances;
|
||||
import weka.filters.Filter;
|
||||
import weka.filters.unsupervised.attribute.Remove;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
@ -36,44 +33,15 @@ public class ShoppingTimes implements Analysis<Map<DayHour, Integer>> {
|
|||
public Map<DayHour, Integer> getResult() {
|
||||
if (result == null) {
|
||||
result = new HashMap<>();
|
||||
int[] keepIndexes = new int[]{Attribute.SHOPPING_DAY, Attribute.SHOPPING_HOUR};
|
||||
int dayIndex = 0;
|
||||
int hourIndex = 1;
|
||||
|
||||
try {
|
||||
//Remove all other attributes
|
||||
Remove remove = new Remove();
|
||||
remove.setAttributeIndicesArray(keepIndexes);
|
||||
remove.setInvertSelection(true);
|
||||
remove.setInputFormat(instances);
|
||||
instances = Filter.useFilter(instances, remove);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
for(Instance instance : instances) {
|
||||
DayHour dayHour = new DayHour(instance.stringValue(Attribute.SHOPPING_DAY), instance.stringValue(Attribute.SHOPPING_HOUR));
|
||||
int tmp = 1;
|
||||
if(result.containsKey(dayHour))
|
||||
tmp = result.get(dayHour) + 1;
|
||||
|
||||
result.put(dayHour, tmp);
|
||||
}
|
||||
|
||||
/*
|
||||
remove all days except one and get the stats
|
||||
needed because weka has no other way to combine attributes
|
||||
*/
|
||||
for (int i = 0; i < instances.attribute(dayIndex).numValues(); i++) {
|
||||
String day = instances.attribute(dayIndex).value(i);
|
||||
Instances instancesCopy = new Instances(instances, 0, instances.numInstances());
|
||||
|
||||
|
||||
for (int j = instancesCopy.numInstances() - 1; j >= 0; j--) {
|
||||
Instance instance = instancesCopy.get(j);
|
||||
if(!instance.stringValue(dayIndex).equals(day))
|
||||
instancesCopy.delete(j);
|
||||
}
|
||||
|
||||
//get customer count and put into map
|
||||
AttributeStats stats = instancesCopy.attributeStats(hourIndex);
|
||||
for (int j = 0; j < instancesCopy.attribute(hourIndex).numValues(); j++) {
|
||||
DayHour dayHour = new DayHour(day, instancesCopy.attribute(hourIndex).value(j));
|
||||
result.put(dayHour, stats.nominalCounts[j]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -16,12 +16,10 @@ import static org.junit.jupiter.api.Assertions.assertTimeout;
|
|||
* @version 0.1
|
||||
* @since 0.1
|
||||
**/
|
||||
public class ShoppingTimesTest {
|
||||
|
||||
//TODO: mehr Tests
|
||||
class ShoppingTimesTest {
|
||||
|
||||
@Test
|
||||
public void test100() {
|
||||
void test100() {
|
||||
URL url = getClass().getClassLoader().getResource("kd100.csv");
|
||||
assert url != null;
|
||||
ShoppingTimes overview = new ShoppingTimes(new File(url.getFile()));
|
||||
|
@ -38,7 +36,7 @@ public class ShoppingTimesTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test1000(){
|
||||
void test1000(){
|
||||
URL url = getClass().getClassLoader().getResource("kd1000.csv");
|
||||
assert url != null;
|
||||
ShoppingTimes overview = new ShoppingTimes(new File(url.getFile()));
|
||||
|
@ -55,7 +53,7 @@ public class ShoppingTimesTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test10000() {
|
||||
void test10000() {
|
||||
URL url = getClass().getClassLoader().getResource("kd10000.csv");
|
||||
assert url != null;
|
||||
ShoppingTimes overview = new ShoppingTimes(new File(url.getFile()));
|
||||
|
|
Loading…
Reference in New Issue