#Validation KNN algorithm
35 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @scarlet parcel! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
shouldn't the method return boolean instead of Boolean?
and that doesn't seem to be valid Java code in your file with all the text outside comments and missing characters
Can you paste the actual code using a Discord codeblock?
I've tried to but it is too many characters
maybe split it up?
yeah i'll do that now
like <>/
static public Boolean validateDataFormat(ArrayList<String[]> data, Boolean predicted) {
boolean formatCorrect = false;
// Check that the first three column headers are "Path", "ActualClass", and "PredictedClass" if predicted is true
// or just "Path" and "ActualClass" if predicted is false
String[] expectedHeaders = predicted ? new String[]{"Path", "ActualClass", "PredictedClass"} : new String[]{"Path", "ActualClass"};
String[] actualHeaders = data.get(0);
if (actualHeaders.length < expectedHeaders.length) {
return false;
}
for (int i = 0; i < expectedHeaders.length; i++) {
if (!actualHeaders[i].equals(expectedHeaders[i])) {
return false;
}
}
// Check that all values in the "Path" column are file paths
for (int i = 1; i < data.size(); i++) {
String[] row = data.get(i);
String path = row[0];
if (!path.startsWith("/")) {
return false;
}
}
// Check that all values in the "ActualClass" and "PredictedClass" columns (if predicted is true) are classes from the scheme
for (int i = 1; i < data.size(); i++) {
String[] row = data.get(i);
String actualClass = row[1];
if (!Arrays.asList(classificationScheme).contains(actualClass)) {
return false;
}
if (predicted) {
String predictedClass = row[2];
if (!Arrays.asList(classificationScheme).contains(predictedClass)) {
return false;
}
}
}
// Check that there are as many Path entries as ActualClass and PredictedClass entries (if predicted is true)
for (int i = 1; i < data.size(); i++) {
String[] row = data.get(i);
if (predicted) {
if (row.length != 3) {
return false;
}
} else {
if (row.length != 2) {
return false;
}
}
}
return formatCorrect;
}
if(actualHeaders.length<expectedHeaders.length)
Why did you use<instead of!=here?
What is classificationScheme?
i'm not sure if i've done any of it correctly but i'm trying to say that I expect the max leugn to be 3 because of the 3 predicted headers, if not then return false
and is your definition of a valid path really just starting with /?
what if it's more?
your code would allow that for the title row
i'm guessing my code is very wrong
well, it seems pretty ok
just a few things I would do differently
like using != instead of < - that woukd forve it to be exactly 2/3 entries in the array
but overall, it seems fine
oh ok
but test it
and good luck with k-nearest-neighbours
thank you