Question: I build an SVM classifier but get an inverse ROC curve. The AUC is only 0.08. I've used the same datasets to build a Logistic Regression classifier and a Decision Tree classifier, and the ROC curves for them look good.

Here are my codes for SVM:

```
from sklearn.svm import SVC
svm = SVC(max_iter = 12, probability = True)
svm.fit(train_x_sm, train_y_sm)
svm_test_y = svm.predict(X = test_x)
svm_roc = plot_roc_curve(svm, test_x, test_y)
plt.show()

```

Could anyone tell me what is wrong in my codes?

Answer: 
> 
> **tf.keras.preprocessing.image\_dataset\_from\_directory**
>   
> *Generates a tf.data.Dataset from image files in a directory*.
> 
> 
> 

> 
> **ImageDataGenerator.flow\_from\_directory**
>   
> *Takes the path to a directory & generates batches of augmented data*.
> 
> 
> 

While their return type also differs but the key difference is that *flow\_from\_directory* is a method of ImageDataGenerator while *image\_dataset\_from\_directory* is a preprocessing function to read image form directory.

*image\_dataset\_from\_directory* will not facilitate you with augmented image generation capability on-the-fly.

> 
> which one should I use?
> 
> 
> 

It's quite common to generate augmented images when working with CNN, so better to use *flow\_from\_directory*.
If you do not need augmented image, you may control the same by the parameters of *ImageDataGenerator*

[*Reference - Keras docs*](https://keras.io/api/preprocessing/image/#imagedatagenerator-class)
Some response elements can be found in this interesting [post](https://towardsdatascience.com/time-to-choose-tensorflow-data-over-imagedatagenerator-215e594f2435)

As mentioned above:

> 
> tf.keras.preprocessing\*\*.image\_dataset\_from\_directory\*\* Generates a
> **tf.data.Dataset** from image files in a directory.
> 
> 
> 

The **.image\_dataset\_from\_directory** function/method enables the use of the new tf 2.8.x (and later version) data structure **tf.data.Dataset**.
Rather than loading your data into lists, which is not a recommended practice, the **.image\_dataset\_from\_directory** allows to load your data in the **tf.data.Dataset** format.
Hence, it enables also the use, and this is the best, of the [Keras preprocessing layers](https://keras.io/guides/preprocessing_layers/), including data augmentation.
Contrary to what is being said that:

> 
> image\_dataset\_from\_directory will not facilitate you with augmented
> image generation capability on-the-fly.
> 
> 
> 

the **.image\_dataset\_from\_director** allows to put data in a format that can be directly pluged into the **keras pre-processing layers**, and data augmentation is run on the fly (real time) with other downstream layers.

This is the main advantage beside allowing the use of the advantageous **tf.data.Dataset.from\_tensor\_slices** method.

To sum up, **.image\_dataset\_from\_director** is an upgraded version of **.flow\_from\_directory** for handling datasets and passing them to deep learning models.