vendredi 6 août 2021

Python: Mathematical operation with conditional

I am trying to learn how to apply a DBSCAN model by following this Towards Data Science publication: https://towardsdatascience.com/k-means-vs-dbscan-clustering-49f8e627de27

Within their code, they typed:

Finding the number of clusters in labels (ignoring noise if present)

n_clusters_ = len(set(labels)) — (1 if -1 in labels else 0)
n_noise_ = list(labels).count(-1)

which leads to the error:

  File "<ipython-input-29-958473fb9d26>", line 8
    n_clusters_ = len(set(labels)) — (1 if -1 in labels else 0)
                                   ^
SyntaxError: invalid character in identifier

I don't even know what to Google to replicate an example for this syntax and understand it. How can this be fixed? and I'm wondering how this worked for them? I literally copied/pasted the code.

Aucun commentaire:

Enregistrer un commentaire