<jupyter_start><jupyter_text>PCA dimentional reduction<jupyter_code>pca_99 = PCA(n_components=0.99)
crypto_pca_99 = pca_99.fit_transform(crypto_cluster_scaled_df)
pca_99.explained_variance_ratio_
pca_90 = PCA(n_components=0.90)
crypto_pca_90 = pca_90.fit_transform(crypto_cluster_scaled_df)
pca_90.explained_variance_ratio_<jupyter_output><empty_output><jupyter_text>Insights:* Preserving 90% of the explained variance , we need the first 12 components.* The higher the explained variance, the more components are needed.  t-SNE<jupyter_code># Run t-SNE
tsne = TSNE(learning_rate=250)
tsne_features = tsne.fit_transform(crypto_cluster_scaled_df)
# Plot the results
plt.scatter(tsne_features[:,0], tsne_features[:,1])
plt.show()<jupyter_output><empty_output><jupyter_text>Insights:- the t-SNE shows that there are distict clusters.<jupyter_code>tsne_features.shape<jupyter_output><empty_output><jupyter_text>K-Means<jupyter_code>inertia = []
k = list(range(1, 11))

# Calculate the inertia for the range of k values
for i in k:
    km = KMeans(n_clusters=i, random_state=0)
    km.fit(crypto_cluster_scaled_df)
    inertia.append(km.inertia_)

# Create the Elbow Curve using hvPlot
elbow_data = {"k": k, "inertia": inertia}
df_elbow = pd.DataFrame(elbow_data)
df_elbow.head()
# Plot the elbow curve to find the best candidate(s) for k
plt.plot(df_elbow['k'], df_elbow['inertia'])
plt.xticks(range(1,11))
plt.xlabel('Number of clusters')
plt.ylabel('Inertia')
plt.title('Elbow curve for customer data')
plt.show()<jupyter_output><empty_output><jupyter_text>Insight:- The elbow appears at k=8.<jupyter_code># Using the elbow number k=8 to fit and label clusters
def get_clusters(k, data):
    # Initialize the K-Means model
    model = KMeans(n_clusters=k, random_state=0)

    # Train the model
    model.fit(data)

    # Predict clusters
    predictions = model.predict(data)

    # Create return DataFrame with predicted clusters
    data["class"] = model.labels_

    return data
clusters = get_clusters(8, crypto_cluster_scaled_df)
clusters['class'].unique()
clusters.head()
# Visualizing the clustered data by t-SNE
plt.scatter(tsne_features[:,0], tsne_features[:,1],c=clusters['class'])
plt.xlabel('t-sne feature 1')
plt.ylabel('t-sne feature 1')
plt.show()
crypto_is_mined_raw_copy_df=crypto_is_mined_raw_df.drop(labels=572, axis=0).copy()
label=LabelEncoder()
algorithm=label.fit_transform(crypto_is_mined_raw_copy_df['Algorithm'])
prooftype=label.fit_transform(crypto_is_mined_raw_copy_df['ProofType'])
plt.scatter(algorithm,prooftype,c=clusters['class'])
plt.xlabel('Algorithm')
plt.ylabel('Prooftype')
plt.show()
crypto_is_mined_raw_copy_df['algorithm_encode']=algorithm
crypto_is_mined_raw_copy_df['prooftype_encode']=prooftype
crypto_is_mined_raw_copy_df['class']=clusters['class']
crypto_is_mined_raw_copy_df.head(20)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1192724728926198, 'fraction_numerical': 0.01818817768450507, 'mean_word_length': 7.827160493827161, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 21, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '262294', 'license': 'ADSL', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1057, 'n_words': 190, 'path': 'cryptocurrency_unsupervised_machine_learning.ipynb', 'repo_name': 'LingLv-git/unsupervised_machine_learning_chanllege', 'size': '2859'}