{
  "id": 179255,
  "title": "qst can any one tell me why im getting this problem with the f1 score ?????",
  "url": "/competitions/siim-isic-melanoma-classification/discussion/179255",
  "author_name": "RoRonoA-TKO",
  "post_date": "2020-09-02T01:13:51.222000",
  "votes": 0,
  "comment_count": 0,
  "views": 0,
  "content": "<p>MY PROBLEM IS HOW CAN I FIXE LOW F1 SCORE AND LOW Sensitivity</p>\n<pre><code>just to more clarify i used this before training to fixe the problem of imbalnced data \n</code></pre>\n<pre><code>lbl_value_counts = train['target'].value_counts()\n\nclass_weights = {i: max(lbl_value_counts) / v for i, v in lbl_value_counts.items()}\n\nprint('classes weigths:', class_weights)\n\nclasses weigths: {0: 1.0, 1: 55.72260273972603}\n</code></pre>\n<pre><code>cmdataset = get_dataset(files_valid, CFG, augment=True, repeat=True ,labeled=True, return_image_names=False) # since we are splitting the dataset and iterating separately on images and labels, order matters.\nimages_ds = cmdataset.map(lambda image, label: image)\nlabels_ds = cmdataset.map(lambda image, label: label).unbatch()\ncm_correct_labels = next(iter(labels_ds.batch(NUM_TEST_IMAGES))).numpy() # get everything as one batch\n#cm_probabilities = model.predict(images_ds)\n#cm_predictions = np.argmax(cm_probabilities, axis=-1)\nprint(\"Correct   labels: \", cm_correct_labels.shape, cm_correct_labels)\nprint(\"Predicted labels: \", probs, probs)\n</code></pre>\n<pre><code>from sklearn.metrics import confusion_matrix\nimport sklearn.metrics\ny_true =cm_correct_labels\ny_pred = probs\ntn, fp, fn, tp = confusion_matrix(y_true, y_pred.round()).ravel()\nspecificity = tn /(tn+fp)\nsensitivity=  tp/ (tp+fn)\nPrecision = tp/(tp+fp)\nRecall = tp/ (tp+fn)\nF1_Score = 2*(Recall * Precision) / (Recall + Precision)\n</code></pre>\n<p><code>print('Specificity : {:.3f}, Sensitivity: {:.3f}, F1_Score: {:.3f}'.format(specificity, sensitivity,F1_Score))</code></p>\n<p><code>Specificity=99.0 ,Sensitivity=44.3, F1_Score=32.1</code></p>",
  "messages": [
    {
      "id": 994820,
      "postDate": "2020-09-02T01:13:51.223Z",
      "content": "<p>MY PROBLEM IS HOW CAN I FIXE LOW F1 SCORE AND LOW Sensitivity</p>\n<pre><code>just to more clarify i used this before training to fixe the problem of imbalnced data \n</code></pre>\n<pre><code>lbl_value_counts = train['target'].value_counts()\n\nclass_weights = {i: max(lbl_value_counts) / v for i, v in lbl_value_counts.items()}\n\nprint('classes weigths:', class_weights)\n\nclasses weigths: {0: 1.0, 1: 55.72260273972603}\n</code></pre>\n<pre><code>cmdataset = get_dataset(files_valid, CFG, augment=True, repeat=True ,labeled=True, return_image_names=False) # since we are splitting the dataset and iterating separately on images and labels, order matters.\nimages_ds = cmdataset.map(lambda image, label: image)\nlabels_ds = cmdataset.map(lambda image, label: label).unbatch()\ncm_correct_labels = next(iter(labels_ds.batch(NUM_TEST_IMAGES))).numpy() # get everything as one batch\n#cm_probabilities = model.predict(images_ds)\n#cm_predictions = np.argmax(cm_probabilities, axis=-1)\nprint(\"Correct   labels: \", cm_correct_labels.shape, cm_correct_labels)\nprint(\"Predicted labels: \", probs, probs)\n</code></pre>\n<pre><code>from sklearn.metrics import confusion_matrix\nimport sklearn.metrics\ny_true =cm_correct_labels\ny_pred = probs\ntn, fp, fn, tp = confusion_matrix(y_true, y_pred.round()).ravel()\nspecificity = tn /(tn+fp)\nsensitivity=  tp/ (tp+fn)\nPrecision = tp/(tp+fp)\nRecall = tp/ (tp+fn)\nF1_Score = 2*(Recall * Precision) / (Recall + Precision)\n</code></pre>\n<p><code>print('Specificity : {:.3f}, Sensitivity: {:.3f}, F1_Score: {:.3f}'.format(specificity, sensitivity,F1_Score))</code></p>\n<p><code>Specificity=99.0 ,Sensitivity=44.3, F1_Score=32.1</code></p>",
      "rawMarkdown": "MY PROBLEM IS HOW CAN I FIXE LOW F1 SCORE AND LOW Sensitivity\n\n```\njust to more clarify i used this before training to fixe the problem of imbalnced data \n\n```\n\n```\nlbl_value_counts = train['target'].value_counts()\n\nclass_weights = {i: max(lbl_value_counts) / v for i, v in lbl_value_counts.items()}\n\nprint('classes weigths:', class_weights)\n\nclasses weigths: {0: 1.0, 1: 55.72260273972603}\n```\n\n```\ncmdataset = get_dataset(files_valid, CFG, augment=True, repeat=True ,labeled=True, return_image_names=False) # since we are splitting the dataset and iterating separately on images and labels, order matters.\nimages_ds = cmdataset.map(lambda image, label: image)\nlabels_ds = cmdataset.map(lambda image, label: label).unbatch()\ncm_correct_labels = next(iter(labels_ds.batch(NUM_TEST_IMAGES))).numpy() # get everything as one batch\n#cm_probabilities = model.predict(images_ds)\n#cm_predictions = np.argmax(cm_probabilities, axis=-1)\nprint(\"Correct   labels: \", cm_correct_labels.shape, cm_correct_labels)\nprint(\"Predicted labels: \", probs, probs)\n```\n```\n\nfrom sklearn.metrics import confusion_matrix\nimport sklearn.metrics\ny_true =cm_correct_labels\ny_pred = probs\ntn, fp, fn, tp = confusion_matrix(y_true, y_pred.round()).ravel()\nspecificity = tn /(tn+fp)\nsensitivity=  tp/ (tp+fn)\nPrecision = tp/(tp+fp)\nRecall = tp/ (tp+fn)\nF1_Score = 2*(Recall * Precision) / (Recall + Precision)\n```\n`print('Specificity : {:.3f}, Sensitivity: {:.3f}, F1_Score: {:.3f}'.format(specificity, sensitivity,F1_Score))`\n\n``Specificity=99.0 ,Sensitivity=44.3, F1_Score=32.1``\n"
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "994820": "MY PROBLEM IS HOW CAN I FIXE LOW F1 SCORE AND LOW Sensitivity\n\n```\njust to more clarify i used this before training to fixe the problem of imbalnced data \n\n```\n\n```\nlbl_value_counts = train['target'].value_counts()\n\nclass_weights = {i: max(lbl_value_counts) / v for i, v in lbl_value_counts.items()}\n\nprint('classes weigths:', class_weights)\n\nclasses weigths: {0: 1.0, 1: 55.72260273972603}\n```\n\n```\ncmdataset = get_dataset(files_valid, CFG, augment=True, repeat=True ,labeled=True, return_image_names=False) # since we are splitting the dataset and iterating separately on images and labels, order matters.\nimages_ds = cmdataset.map(lambda image, label: image)\nlabels_ds = cmdataset.map(lambda image, label: label).unbatch()\ncm_correct_labels = next(iter(labels_ds.batch(NUM_TEST_IMAGES))).numpy() # get everything as one batch\n#cm_probabilities = model.predict(images_ds)\n#cm_predictions = np.argmax(cm_probabilities, axis=-1)\nprint(\"Correct   labels: \", cm_correct_labels.shape, cm_correct_labels)\nprint(\"Predicted labels: \", probs, probs)\n```\n```\n\nfrom sklearn.metrics import confusion_matrix\nimport sklearn.metrics\ny_true =cm_correct_labels\ny_pred = probs\ntn, fp, fn, tp = confusion_matrix(y_true, y_pred.round()).ravel()\nspecificity = tn /(tn+fp)\nsensitivity=  tp/ (tp+fn)\nPrecision = tp/(tp+fp)\nRecall = tp/ (tp+fn)\nF1_Score = 2*(Recall * Precision) / (Recall + Precision)\n```\n`print('Specificity : {:.3f}, Sensitivity: {:.3f}, F1_Score: {:.3f}'.format(specificity, sensitivity,F1_Score))`\n\n``Specificity=99.0 ,Sensitivity=44.3, F1_Score=32.1``\n"
  }
}