Row 7698
Content Data
This page contains data entry 7698 from the Axioma AXP content repository. The structured data below represents the complete record for this entry.
Currently taking the FCC Machine Learning Course.
I dont know how to correctly interpret the probabilities of the Model.predict function output. The CNN is meant to determine whether is an image of a cat or a dog. Some probabilities are negative and very low. I dont know how to interpret that data. Also mention the model achieves its goal with an aceptable margin. Here an example:
https://preview.redd.it/yyss5v202y0d1.png?width=759&format=png&auto=webp&s=b1141a6e7150fcfdf0b65dc2119de956a9fc8ec8
Here the code.
Link of images:
wget https://cdn.freecodecamp.org/project-data/cats-and-dogs/cats_and_dogs.zip
Code:
# 3 train_image_generator = ImageDataGenerator(rescale=1./255) validation_image_generator = ImageDataGenerator(rescale=1./255) test_image_generator = ImageDataGenerator(rescale=1./255) train_data_gen = train_image_generator.flow_from_directory( train_dir, target_size=(IMG_HEIGHT,IMG_WIDTH), batch_size = batch_size, class_mode = 'binary') val_data_gen = validation_image_generator.flow_from_directory( directory = validation_dir, target_size=(IMG_HEIGHT,IMG_WIDTH), batch_size = batch_size, class_mode = 'binary') test_data_gen = test_image_generator.flow_from_directory( directory=test_dir, target_size=(IMG_HEIGHT,IMG_WIDTH), batch_size = batch_size, class_mode = 'binary', shuffle=False)
# 4 def plotImages(images_arr, probabilities = False): fig, axes = plt.subplots(len(images_arr), 1, figsize=(5,len(images_arr) * 3)) if probabilities is False: for img, ax in zip( images_arr, axes): ax.imshow(img) ax.axis('off') else: for img, probability, ax in zip( images_arr, probabilities, axes): ax.imshow(img) ax.axis('off') if probability > 0.5: ax.set_title("%.2f" % (probability*100) + "% dog") else: ax.set_title("%.2f" % ((1-probability)*100) + "% cat") plt.show() sample_training_images, _ = next(train_data_gen) plotImages(sample_training_images[:5])
# 5 train_image_generator = train_image_generator = ImageDataGenerator( rotation_range = 360, horizontal_flip = True, vertical_flip = True, zoom_range = 0.2, shear_range = 60, rescale=1./255)
# 6 train_data_gen = train_image_generator.flow_from_directory(batch_size=batch_size, directory=train_dir, target_size=(IMG_HEIGHT, IMG_WIDTH), class_mode='binary') augmented_images = [train_data_gen[0][0][0] for i in range(5)] plotImages(augmented_images)
# 7 model = Sequential() model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(150, 150, 3))) model.add(MaxPooling2D((2, 2))) model.add(Conv2D(64, (3, 3), activation='relu')) model.add(MaxPooling2D((2, 2))) model.add(Conv2D(64, (3, 3), activation='relu')) model.add(Flatten()) model.add(Dense(64, activation='relu')) model.add(Dense(2)) model.compile(optimizer='adam', loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=['accuracy']) model.summary()
# 8 history = model.fit(x = train_data_gen, epochs = epochs, validation_data = val_data_gen) acc = history.history['accuracy'] print(acc)
# 9 acc = history.history['accuracy'] val_acc = history.history['val_accuracy'] loss = history.history['loss'] val_loss = history.history['val_loss'] epochs_range = range(epochs) print(epochs_range) print(acc) plt.figure(figsize=(8, 8)) plt.subplot(1, 2, 1) plt.plot(epochs_range, acc, label='Training Accuracy') plt.plot(epochs_range, val_acc, label='Validation Accuracy') plt.legend(loc='lower right') plt.title('Training and Validation Accuracy') plt.subplot(1, 2, 2) plt.plot(epochs_range, loss, label='Training Loss') plt.plot(epochs_range, val_loss, label='Validation Loss') plt.legend(loc='upper right') plt.title('Training and Validation Loss') plt.show()
#10 probabilities = model.predict(test_data_gen) print(probabilities) probabilities = np.argmax(probabilities, axis = 1) sample_test_images, _ = next(test_data_gen) plotImages(sample_test_images, probabilities=probabilities)
# 11 answers = [1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0] correct = 0 for probability, answer in zip(probabilities, answers): if round(probability) == answer: correct +=1 percentage_identified = (correct / len(answers)) * 100 passed_challenge = percentage_identified >= 63 print(f"Your model correctly identified {round(percentage_identified, 2)}% of the images of cats and dogs.") if passed_challenge: print("You passed the challenge!") else: print("You haven't passed yet. Your model should identify at least 63% of the images. Keep trying. You will get it!")
| Field | Value |
|---|---|
| text | Currently taking the FCC Machine Learning Course. I dont know how to correctly interpret the probabilities of the Model.predict function output. The CNN is meant to determine whether is an image of a cat or a dog. Some probabilities are negative and very low. I dont know how to interpret that data. Also mention the model achieves its goal with an aceptable margin. Here an example: https://preview.redd.it/yyss5v202y0d1.png?width=759&format=png&auto=webp&s=b1141a6e7150fcfdf0b65dc2119de956a9f… |
| label | r/machinelearning |
| dataType | post |
| communityName | r/MachineLearning |
| datetime | 2024-05-17 |
| username_encoded | Z0FBQUFBQm5Lakwzdnd4c3Y1ODZqVFdFZG9yLUVXcTBXc19UZ0s3dDJ1RmxHVGk5TkR6WXVGbWF1UnlMeGJNdENITy1fSE1teVhwZklqX0djbklXb3VSTHdLX0Z3LTZyMEE9PQ== |
| url_encoded | Z0FBQUFBQm5Lak9IeGZwMkhnanhOcTY1WDhmZ0lLbU4wTTNOTS12ZGZaX2Zqa0NULS04TFV1SnNGN1R1M1VaTGhIbVNrMHhmQVBHSHZNZlNtMTBqTlQyc01mQzZ2MmZnS1RSNE5wckNSeHNJY25xTUNSNnNnS1E4aWJUVWRxRmZSNU1pQWlDQUE5ZmpJR1dNdmc5SXkzNFdoNklKU1E5c2NoOE5TVkxscUVFWll4dkY1cS1ZeDNiZGliUDlZOFNxV0E3MTNYQTZVa0Q3VWQwallDQXdpSWhmUlkwUG5WYzlYUT09 |
Raw Record
{
"text": "Currently taking the FCC Machine Learning Course.\n\nI dont know how to correctly interpret the probabilities of the Model.predict function output. The CNN is meant to determine whether is an image of a cat or a dog. Some probabilities are negative and very low. I dont know how to interpret that data. \nAlso mention the model achieves its goal with an aceptable margin. \nHere an example:\n\nhttps://preview.redd.it/yyss5v202y0d1.png?width=759&format=png&auto=webp&s=b1141a6e7150fcfdf0b65dc2119de956a9fc8ec8\n\nHere the code.\n\nLink of images:\n\n wget https://cdn.freecodecamp.org/project-data/cats-and-dogs/cats_and_dogs.zip\n\nCode:\n\n # 3\n train_image_generator = ImageDataGenerator(rescale=1./255)\n validation_image_generator = ImageDataGenerator(rescale=1./255)\n test_image_generator = ImageDataGenerator(rescale=1./255)\n \n train_data_gen = train_image_generator.flow_from_directory(\n train_dir,\n target_size=(IMG_HEIGHT,IMG_WIDTH),\n batch_size = batch_size,\n class_mode = 'binary')\n val_data_gen = validation_image_generator.flow_from_directory(\n directory = validation_dir,\n target_size=(IMG_HEIGHT,IMG_WIDTH),\n batch_size = batch_size,\n class_mode = 'binary')\n test_data_gen = test_image_generator.flow_from_directory(\n directory=test_dir,\n target_size=(IMG_HEIGHT,IMG_WIDTH),\n batch_size = batch_size,\n class_mode = 'binary',\n shuffle=False)\n\n # 4\n def plotImages(images_arr, probabilities = False):\n fig, axes = plt.subplots(len(images_arr), 1, figsize=(5,len(images_arr) * 3))\n if probabilities is False:\n for img, ax in zip( images_arr, axes):\n ax.imshow(img)\n ax.axis('off')\n else:\n for img, probability, ax in zip( images_arr, probabilities, axes):\n ax.imshow(img)\n ax.axis('off')\n if probability > 0.5:\n ax.set_title(\"%.2f\" % (probability*100) + \"% dog\")\n else:\n ax.set_title(\"%.2f\" % ((1-probability)*100) + \"% cat\")\n plt.show()\n \n sample_training_images, _ = next(train_data_gen)\n plotImages(sample_training_images[:5])\n \n \n \n\n # 5\n train_image_generator = train_image_generator = ImageDataGenerator(\n rotation_range = 360,\n horizontal_flip = True,\n vertical_flip = True,\n zoom_range = 0.2,\n shear_range = 60,\n rescale=1./255)\n \n \n\n # 6\n train_data_gen = train_image_generator.flow_from_directory(batch_size=batch_size,\n directory=train_dir,\n target_size=(IMG_HEIGHT, IMG_WIDTH),\n class_mode='binary')\n \n augmented_images = [train_data_gen[0][0][0] for i in range(5)]\n \n plotImages(augmented_images)\n\n # 7\n model = Sequential()\n model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(150, 150, 3)))\n model.add(MaxPooling2D((2, 2)))\n model.add(Conv2D(64, (3, 3), activation='relu'))\n model.add(MaxPooling2D((2, 2)))\n model.add(Conv2D(64, (3, 3), activation='relu'))\n model.add(Flatten())\n model.add(Dense(64, activation='relu'))\n model.add(Dense(2))\n \n model.compile(optimizer='adam',\n loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),\n metrics=['accuracy'])\n model.summary()\n\n # 8\n history = model.fit(x = train_data_gen, \n epochs = epochs,\n validation_data = val_data_gen)\n acc = history.history['accuracy']\n print(acc)\n\n # 9\n acc = history.history['accuracy']\n val_acc = history.history['val_accuracy']\n \n loss = history.history['loss']\n val_loss = history.history['val_loss']\n \n epochs_range = range(epochs)\n print(epochs_range)\n print(acc)\n \n plt.figure(figsize=(8, 8))\n plt.subplot(1, 2, 1)\n plt.plot(epochs_range, acc, label='Training Accuracy')\n plt.plot(epochs_range, val_acc, label='Validation Accuracy')\n plt.legend(loc='lower right')\n plt.title('Training and Validation Accuracy')\n \n plt.subplot(1, 2, 2)\n plt.plot(epochs_range, loss, label='Training Loss')\n plt.plot(epochs_range, val_loss, label='Validation Loss')\n plt.legend(loc='upper right')\n plt.title('Training and Validation Loss')\n plt.show()\n\n #10\n probabilities = model.predict(test_data_gen)\n print(probabilities)\n probabilities = np.argmax(probabilities, axis = 1)\n sample_test_images, _ = next(test_data_gen)\n plotImages(sample_test_images, probabilities=probabilities)\n\n # 11\n answers = [1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0,\n 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0,\n 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1,\n 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1,\n 0, 0, 0, 0, 0, 0]\n \n correct = 0\n \n for probability, answer in zip(probabilities, answers):\n if round(probability) == answer:\n correct +=1\n \n percentage_identified = (correct / len(answers)) * 100\n \n passed_challenge = percentage_identified >= 63\n \n print(f\"Your model correctly identified {round(percentage_identified, 2)}% of the images of cats and dogs.\")\n \n if passed_challenge:\n print(\"You passed the challenge!\")\n else:\n print(\"You haven't passed yet. Your model should identify at least 63% of the images. Keep trying. You will get it!\")\n ",
"label": "r/machinelearning",
"dataType": "post",
"communityName": "r/MachineLearning",
"datetime": "2024-05-17",
"username_encoded": "Z0FBQUFBQm5Lakwzdnd4c3Y1ODZqVFdFZG9yLUVXcTBXc19UZ0s3dDJ1RmxHVGk5TkR6WXVGbWF1UnlMeGJNdENITy1fSE1teVhwZklqX0djbklXb3VSTHdLX0Z3LTZyMEE9PQ==",
"url_encoded": "Z0FBQUFBQm5Lak9IeGZwMkhnanhOcTY1WDhmZ0lLbU4wTTNOTS12ZGZaX2Zqa0NULS04TFV1SnNGN1R1M1VaTGhIbVNrMHhmQVBHSHZNZlNtMTBqTlQyc01mQzZ2MmZnS1RSNE5wckNSeHNJY25xTUNSNnNnS1E4aWJUVWRxRmZSNU1pQWlDQUE5ZmpJR1dNdmc5SXkzNFdoNklKU1E5c2NoOE5TVkxscUVFWll4dkY1cS1ZeDNiZGliUDlZOFNxV0E3MTNYQTZVa0Q3VWQwallDQXdpSWhmUlkwUG5WYzlYUT09"
}
Entry Information
- Entry ID: 7698
- Repository: Axioma AXP
- Dataset: arrmlet/reddit_dataset_36
- Total Entries: 100,000