+ erste Versuche mit Weka
Signed-off-by: Johannes Theiner <j.theiner@live.de>
This commit is contained in:
parent
691481dbc5
commit
094e539c76
58
src/main/java/de/hsel/spm/baudas/analysis/ShoppingTimes.java
Normal file
58
src/main/java/de/hsel/spm/baudas/analysis/ShoppingTimes.java
Normal file
@ -0,0 +1,58 @@
|
||||
package de.hsel.spm.baudas.analysis;
|
||||
|
||||
import javafx.util.Pair;
|
||||
import weka.core.Instances;
|
||||
import weka.filters.Filter;
|
||||
import weka.filters.unsupervised.attribute.Remove;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
**/
|
||||
public class ShoppingTimes implements Analysis<Map<Pair<String, String>, Integer>>{
|
||||
|
||||
private Instances instances;
|
||||
private Map<Pair<String, String>, Integer> result;
|
||||
|
||||
public ShoppingTimes(File file) {
|
||||
instances = load(file);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<Pair<String, String>, Integer> getResult() {
|
||||
if(result == null) {
|
||||
int dayIndex = 0;
|
||||
int hourIndex = 1;
|
||||
int[] keepIndexes = new int[]{5, 6};
|
||||
|
||||
Remove remove = new Remove();
|
||||
try {
|
||||
remove.setAttributeIndicesArray(keepIndexes);
|
||||
remove.setInvertSelection(true);
|
||||
remove.setInputFormat(instances);
|
||||
instances = Filter.useFilter(instances, remove);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*Map<Pair<String, String>, Integer> hours = new HashMap<>();
|
||||
AttributeStats stats = instances.attributeStats(hourIndex);
|
||||
for(int i = 0; i <= instances.attribute(hourIndex).numValues() - 1; i++) {
|
||||
Pair<String, String> pair = new Pair<>(instances.attribute(hourIndex).value(i), instances.attribute(0).value(i));
|
||||
hours.put(pair, stats.nominalCounts[i]);
|
||||
}
|
||||
result = hours;*/
|
||||
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package de.hsel.spm.baudas.analysis;
|
||||
|
||||
import javafx.util.Pair;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTimeout;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
**/
|
||||
public class ShoppingTimesTest {
|
||||
|
||||
//TODO: mehr Tests
|
||||
|
||||
@Test
|
||||
public void test100() {
|
||||
URL url = getClass().getClassLoader().getResource("kd100.csv");
|
||||
assert url != null;
|
||||
ShoppingTimes overview = new ShoppingTimes(new File(url.getFile()));
|
||||
|
||||
AtomicReference<Map<Pair<String, String>, Integer>> results = new AtomicReference<>();
|
||||
|
||||
assertTimeout(Duration.ofMillis(450), () -> results.set(overview.getResult()));
|
||||
/*for(Pair<String, String> pair : results.get().keySet()) {
|
||||
System.out.println(pair);
|
||||
}*/
|
||||
|
||||
|
||||
//assertEquals(21, results.get().get(new Pair<>("Montag", ">17 Uhr")));
|
||||
//TODO: mehr Tests
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user