python - Pandas - pd.crosstab gives me incorrect classification -


i built classifier , wanted try out pd.crosstab. however, seems give me incorrect numbers of total elements confusing , can't figure out why.

actual code:

df_confusion = pd.crosstab(pd.series(y_pred), pd.series(y_test),                             rownames=['predicted'], colnames= ['actual'],                            margins=true) 

typing in jupyter notebook: df_confusion yields

**actual**   0.0      1.0   **all**  **predicted**     **0.0**    6529     1951        8480  **1.0**     718     208         926  **all**     7247    2159        9406** 

whereas total number of elements of each category 0 , 1 in y_pred , y_test follows:

sum(y_pred==0) equals 34264 sum(y_pred==1) equals 3514  sum(y_test==1) equals 34259 sum(y_test==0) equals 3519 

however importing confusion_matrix yields expected answers

from sklearn.metrics  import confusion_matrix  confusion_matrix(y_test,y_pred) array([[34259,     0],        [    5,  3514]], dtype=int64) 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -