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 example, this is the last one I have tried:

concatpredtest = pd.concat([y_pred, X_test], axis=1, join='inner')

fp_filter = (y_test == 1)  (concatpredtest == 0)

Do you know what could I do to see my false positive rows - of course entire row i.e. X_test along with y_pred?

Topic confusion-matrix

Category Data Science


I don't believe the sklearn module provides the row index you are looking for, but I guess you could just do it using good old fashioned python!

Something like:

fp_rows = []

for i in range(len(y_pred)):
    if y_pred[i] == 1 and y_test[i] == 0:
        fp_rows.append[i]

Hope that works or gives you an idea.

About

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