<jupyter_start><jupyter_text>This data has no missing values and the types are of float64 as displayed above<jupyter_code># we herreby remove the Cluster Label column.
cluster_data = cluster[['X', 'Y', 'Z']]
# display the new data
display(cluster_data.head())
x = cluster_data.X.values
y = cluster_data.Y.values
z = cluster_data.Z.values

sample = np.array([x,y,z]).transpose()
#  for better model performance we preprocess the data by rescaling the data to zero mean and unit variance  using sklearn.standardscaler

from sklearn.preprocessing import StandardScaler

scaler = StandardScaler()
scaler.fit(sample)
sample_scaled = scaler.transform(sample)
from sklearn.cluster import DBSCAN
from sklearn import metrics


dbscan = DBSCAN()
db = dbscan.fit(sample_scaled)
cluster_labels = db.labels_
cluster_labels += 1
cluster_labels
# help(cluster)
# db.components_.shape
from mpl_toolkits.mplot3d import Axes3D


fig = plt.figure(figsize=[15,10])
ax = fig.add_subplot(111, projection='3d')
ax.scatter(sample_scaled[:, 0], sample_scaled[:, 1], sample_scaled[:, 2], c=cluster_labels)


ax.scatter(centre[:,0], centre[:,1], centre[:,2], marker='o', s=200, color=['red', 'blue', 'red', 'black'])
# plt.show()


# plot the cluster assignments
# plt.scatter(sample_scaled[:, 0], sample_scaled[:, 1], sample_scaled[:, 2], c=clusters.unique, marker_size=60)
# plt.xlabel("Feature 0")
# plt.ylabel("Feature 1")
# plt.zlabel('feature 2')


# Number of clusters in labels, ignoring noise if present.
# n_clusters_ = len(set(labels)) - (1 if -1 in labels else 0)

# labels_ = []
# for i in labels:
#     labels_.append(i)

# n_noise_ = labels_.count(-1)
from sklearn.metrics import confusion_matrix
from sklearn.metrics import f1_score

pred_val = cluster_labels
true_val = cluster['Cluster label'].values.astype(int)

f1_sc = f1_score(true_val, pred_val, average='micro')
print(f1_sc)

# help(f1_score)
# confusion_matrix(truth_values, pred_values)
from mpl_toolkits.mplot3d import Axes3D


fig = plt.figure(figsize=[15,10])
ax = fig.add_subplot(111, projection='3d')
ax.scatter(cluster.X, cluster.Y, cluster.Z, c=cluster['Cluster label'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1349721706864564, 'fraction_numerical': 0.022727272727272728, 'mean_word_length': 6.049019607843137, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '417128', 'license': 'CC0-1.0', 'n_tokens_mistral': 780, 'n_tokens_neox': 763, 'n_words': 192, 'path': '.ipynb_checkpoints/Basic clustering with DBSCAN-checkpoint.ipynb', 'repo_name': 'omotoshoahmad/Clustering-and-Regression', 'size': '2156'}