Skip to content

Commit

Permalink
accuracy for application
Browse files Browse the repository at this point in the history
  • Loading branch information
mufwan authored and fzoepffel committed Feb 20, 2024
1 parent 711b766 commit 481e42c
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions scripts/keywordSpotting.dml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


X = read("tmp/waves.csv", format="csv")
y = read("tmp/labels.csv", format="csv")

Expand All @@ -11,42 +10,25 @@ Xy_shuffled = Xy_shuffled[,1:num_col] # Remove the random column
X_shuffled = Xy_shuffled[,1:(num_col-1)] # Features, excluding the last column which is labels
y_shuffled = Xy_shuffled[,num_col] # Labels, the last column


[X_train, X_test, y_train, y_test] = split(X=X_shuffled, Y=y_shuffled, seed= 13)

# Preprocess with fft Optionally move before split.
[X_train_re, X_train_im] = stft(X_train, 4, 2)
[X_test_re, X_test_im] = stft(X_test, 4, 2)


X_train_re_sq = X_train_re^2
X_train_im_sq = X_train_im^2


X_test_re_sq = X_test_re^2
X_test_im_sq = X_test_im^2


# Sum the squared matrices
sum_X_train_sq = X_train_re_sq + X_train_im_sq
sum_X_test_sq = X_test_re_sq + X_test_im_sq

# Compute the square root of each element in the sum matrix to get the magnitudes
magnitudes_train = sqrt(sum_X_train_sq)
magnitudes_test = sqrt(sum_X_test_sq)

bias = lm(X=magnitudes_train, y=y_train, reg=1e-1, maxi=10, verbose=TRUE)
predictions = lmPredict(X=magnitudes_test, B=bias, verbose=FALSE)

#sign_predictions = sign(predictions)
#sign_Y = sign(y_test)

#correct = sum(sign_predictions == sign_Y)
#total = nrow(y_test)
#accuracy = correct / total

#print(toString(predictions))
#print(toString(accuracy))

R = lmPredictStats(yhat=predictions, ytest=y_test, lm=TRUE)
print(toString(R))
accuracy = auc(Y=y_test, P=predictions)
print(toString(accuracy))

0 comments on commit 481e42c

Please sign in to comment.