<jupyter_start><jupyter_text>Dimensionality Reduction  PCA<jupyter_code># Perform dimensionality reduction with PCA
from sklearn.decomposition import PCA
pca = PCA(n_components=0.9)
# Get two principal components for the X_data_scaled
crypto_pca = pca.fit_transform(data_scaled)
crypto_pca.shape<jupyter_output><empty_output><jupyter_text>t-SNE<jupyter_code>from sklearn.manifold import TSNE
tsne = TSNE(learning_rate=35)

# Reduce dimensions
tsne_features = tsne.fit_transform(crypto_pca)
tsne_features.shape
tsne_df = pd.DataFrame(tsne_features, columns = ["x", "y"], index = crypto_df5.index)
tsne_df.head()
plt.scatter(tsne_df['x'], tsne_df['y'])
plt.show()<jupyter_output><empty_output><jupyter_text>Cluster Analysis with k-Means<jupyter_code>inertia = []
# Same as k = list(range(1, 11))
k = [1,2,3,4,5,6,7,8,9,10]


# Looking for the best k
for i in k:
    km = KMeans(n_clusters=i, random_state=0)
    km.fit(tsne_df)
    inertia.append(km.inertia_)

# Define a DataFrame to plot the Elbow Curve using hvPlot
elbow_data = {"k": k, "inertia": inertia}
df_elbow = pd.DataFrame(elbow_data)

plt.plot(df_elbow['k'], df_elbow['inertia'])
plt.xticks(range(1,11))
plt.xlabel('Number of clusters')
plt.ylabel('Inertia')
plt.show()
model = KMeans(n_clusters=4, random_state=0)
model.fit(tsne_df)
predictions = model.predict(tsne_df)
tsne_df.plot(kind='scatter',x='x',y='y',colormap='plasma',c=predictions)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14186851211072665, 'fraction_numerical': 0.01730103806228374, 'mean_word_length': 7.607142857142857, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '438058', 'license': 'ADSL', 'n_tokens_mistral': 617, 'n_tokens_neox': 589, 'n_words': 102, 'path': 'Cryptocurrency Unsupervised ML.ipynb', 'repo_name': 'Andrewsr220a/Crypto-currency-UnsupML', 'size': '1445'}