how to reduce overfitting and improve confusion matrix

I am trying to apply the following model on my data which is consists of (4030 samples as 5 classes) each sample is MFCC features which is extracted from an audio clip consisting of (20 second) and I am trying to apply classification, but I got very poor accuracy and I also have overfitting, , Although I am using data augmentation and I also try to apply Batch Normalization to improve overfitting but the result is very bad. the Model: …
Category: Data Science

How to add class labels to confusion matrix of multi class classification

How do I add class labels to the confusion matrix? The label display number in the label not the actual value of the label Eg. labels = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'] Here is the code I used to generate it. x_train, y_train, x_test, y_test = train_images, train_labels, test_images, test_labels model = KNeighborsClassifier(n_neighbors=7, metric='euclidean') model.fit(x_train, y_train) # predict labels for test data predictions = model.predict(x_test) # Print overall accuracy print("KNN Accuracy = ", metrics.accuracy_score(y_test, predictions)) # Print confusion matrix cm = confusion_matrix(y_test, predictions) plt.subplots(figsize=(30, …
Category: Data Science

why is H2O using only a part of the data?

I have this dataframe: > head(df_clas_sn) country serial_no_of_generator_1 serial_no_of_generator_2 serial_no_of_generator_3 unit_type 11 Germany XY 01 0620 ORiP 12 India XY 01 0631 ORiP 13 Germany XY 02 0683 ORiP 14 Germany XZ 02 0735 KRIT 15 England XY 03 0844 KRIT 16 Germany XZ 05 0243 ORiP position_in_unit hours_balance status_code 11 Y 2771 1 12 DE 3783 1 13 G 1267 1 14 DE 7798 1 15 G 1136 1 16 M 6197 1 with these dimensions: > dim(df_clas_sn) [1] …
Category: Data Science

Deep Learning accuracy vs Confusion Matrix accuracy

I am working on deep learning with fer2013 dataset. After training the model I got val_precision: 0.9168 (precision: 0.8492) Epoch 67/100 238/238 [==============================] - 31s 130ms/step - loss: 1.5087 - tp: 2622.4142 - fp: 474.9121 - tn: 45584.3013 - fn: 5054.1213 - accuracy: 0.8972 - precision: 0.8492 - recall: 0.3410 - auc: 0.9042 - prc: 0.6758 - val_loss: 0.9754 - val_tp: 1389.0000 - val_fp: 126.0000 - val_tn: 22698.0000 - val_fn: 2415.0000 - val_accuracy: 0.9046 - **val_precision: 0.9168** - val_recall: 0.3651 …
Category: Data Science

specificity for 3 class

I was reading an answer in qoura to calculate the specificity of a 3 class classifier from a confusion matrix. In the below answer https://www.quora.com/How-do-I-get-specificity-and-sensitivity-from-a-three-classes-confusion-matrix For below 3-class confusion matrix, The below is a screenshot from the answer. the sensitivity and specificity would be found by calculating the following: My question is in numerator for specificity which is false negatives shouldnt it be 4 terms. Eg if we are calculating w/r 1, Then in the table n22,n33,n32 and n23 were …
Category: Data Science

Does it make sense to build a ROC for a decision tree where there are multiple threshold you can adjust?

I understand building a ROC curve when the output is a probability, say, from a logistic regression model. You can build a ROC curve by varying the cutoff threshold. But what about decision trees of the form: if attribute_1 > x: decision = positive else: if attribute_2 < y: decision = position else: decision = negative You can adjust the cutoff for both attributes and all will affect your confusion matrix. Does it make sense to build a ROC curves …
Category: Data Science

How to balance sensitivity(sn) and specificity(sp) of an Artificial Neural Network model?

I have been working on a binary classification problem of protein sequences. I have used a feed-forward neural network with two hidden layers. I have the training and validation accuracy/loss curves that the model has trained pretty well without overfitting/underfitting. Then, while testing on independent dataset, I have following results: Accuracy: 0.7672583826429981, MCC: 0.5401163645598229, Sensitivity: 0.8379446640316206, Specificity: 0.6968503937007874, Confusion matrix: [[177 77] [ 41 212]] The results are already pretty impressive for this particular problem in terms of Accuracy and …
Category: Data Science

Confusion matrix, when mistakes below diagonal are better than above the diagonal

I have a classification problem and I am producing a confusion matrix. Ideally one wants to get all results in the diagonal. I get quite many points around diagonal for different algorithms. Still for my use-case I want to favor algorithms that underpredict the class (I have ordinal data) and not overpredict. Is there a metric that can measure under and overprediction and rate those errors with a different weight? The typical accuracy, precision terms assume that all mistakes are …
Category: Data Science

Difficulties in create a confusion matrix in R for Yes or No

I am new to regression and confusion matrix and trying to create a confusion matrix from logistic binary regression model. I am trying to create a confusion matrix from Yes or No values from the column, Survived. I am using a default dataset, Titanic. I received an error when trying to perform Confusion Matrix The dataset, Titanic content is found here. Titanic Content Here is the R code below. example$Class<- as.factor(example$Class) example$Sex<- as.factor(example$Sex) example$Age<- as.factor(example$Age) example$Survived<- as.factor(example$Survived) trainRowNum <- createDataPartition(example$Survived, …
Category: Data Science

Why rejection of a true null hypothesis is called type I error?

I’m comparing two confusion matrices: https://en.wikipedia.org/wiki/Confusion_matrix#Table_of_confusion https://en.wikipedia.org/wiki/Type_I_and_type_II_errors The 2nd is rotated, the Decision is on Y-axis. But I assume both reflect the same concept. I have two options to render the word “Reject”. (1) When we look at Null hypothesis matrix, the Reject of a “True Null hypothesis” means a decision which doesn’t reflect reality (convicting an innocent), and this is indeed FP (type I). (2) Following Confusion_matrix wiki, I interpret Reject as False. Therefore, making a False decision (H0 …
Category: Data Science

How do you calculate Precision and Recall using a confusion matrix in Matlab?

I am working on a three class problem. How do you calculate precision, recall, f-score, and MCC for each class while using MATLAB? Here is my confusion matrix: 2775 0 0 1 591 0 4 0 845 I am calculating Accuracy from the Confusion matrix in this way: Accuracyy = 100*sum(diag(confusionMat))./sum(confusionMat(:)); I would like to measure the below performance measures for each class. I know the formulas, but not how to execute this in MATLAB. Please help. I would really …
Category: Data Science

Viewing false positive rows in python

I got values for the confusion matrix using: tn, fp, fn, tp = confusion_matrix(y_true, y_pred).ravel() 10000 13000 500 1500 Now, I wish to see what data is in the each tn, fp, fn, and tp. I have tried various options, but the kernel keeps on dying. I am working with Python3 on Jupyter Notebook. X_train, X_test, y_train, y_test = train_test_split( X, y, train_size=5000, random_state=1) X_train.shape, y_train.shape, X_test.shape, y_test.shape ((5000, 21), (5000, 1), (25000, 21), (25000, 1)) y_pred = pd.Series(clf_iforest.predict(X_test)) For …
Category: Data Science

What does the color coding and normalized values in confusion matrix actually specify?

I am unable to infer anything about the model from the following confusion matrix. What is the color coding actually specifying? For example, when predicted label is 1 and true label is 1, the value in the matrix at that point is 0.20. Does that mean its accuracy? Does it mean that the model is only able to predict 1 only 20% of times when the label is actually 1? PS: SO URL for a more clear image
Category: Data Science

Logistic Regression test accuracy vs deployment

I am working on a problem where I make some weekly predictions. I gathered the data myself and did some pre-processing steps and I end up with 6 features. I split the dataset 60-20-20 in train, holdout, test sets and I train a Logistic Regression model. I get very good holdout and test accuracy (>95%) with only a few FP, FN. However, when making predictions for new data in the end the results are nowhere near there. I make predictions …
Category: Data Science

Discrepancy between cross-validation and un-seen data predictions

I am facing an issue with an imbalanced dataset. The dataset contains 20% targets and 80% non-targets. I am expecting a confusion matrix below when I give un-seen data to the trained model. [[1200 0 ] [0 240]] In reality I am getting a confusion matrix below. As you must have observed, it is classifying very less targets. [[1133 67] [ 227 13]] The training and validation curve of a CNN model looks like below. Any thoughts on, why so …
Category: Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.