<jupyter_start><jupyter_text>Recommendation to clientsBased on the analysis below, the cryptocurrencies can be clustered. I recommend using three to five clusters.<jupyter_code># Import dependencies
import pandas as pd
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
# Read in raw data
raw_crypto_data_df = pd.read_csv("crypto_data.csv")
raw_crypto_data_df
# Filter by IsTrading == True
traded_crypto_df = raw_crypto_data_df.loc[raw_crypto_data_df.IsTrading == True, :]
traded_crypto_df.head()
# Remove IsTrading column
traded_crypto_df = traded_crypto_df.drop(columns="IsTrading")
traded_crypto_df.head()
# Remove all rows with at least one null value
traded_crypto_not_null_df = traded_crypto_df.dropna()
traded_crypto_not_null_df.head()
# Filter for only mined currencies
mined_crypto_df = traded_crypto_not_null_df.loc[traded_crypto_not_null_df.TotalCoinsMined > 0, :]
mined_crypto_df.head()
# Remove columns that do not contribute to data analysis
mined_crypto_clean_df = mined_crypto_df.drop(columns = ["Unnamed: 0", "CoinName"])
mined_crypto_clean_df.head()
mined_crypto_clean_df.shape
# Transforme categorical data to numeric
mined_crypto_dummies_df = pd.get_dummies(data=mined_crypto_clean_df, columns=["Algorithm", "ProofType"])
mined_crypto_dummies_df.head()
mined_crypto_dummies_df.shape<jupyter_output><empty_output><jupyter_text>ObservationAfter transforming the categorical data to numeric, the dataframe changed for 532 rows and four columns to the same number of rows but 98 columns.<jupyter_code># Scaling the data to prevent any one feature from having undue weight
scaler = StandardScaler()
scaled_data = scaler.fit_transform(mined_crypto_dummies_df)
scaled_data_df = pd.DataFrame(scaled_data, columns=mined_crypto_dummies_df.columns)
scaled_data_df
# Applying PCA to reduce the feature dimentionality
pca = PCA(n_components=0.9)
crypto_pca = pca.fit_transform(mined_crypto_dummies_df)
crypto_pca.shape<jupyter_output><empty_output><jupyter_text>ObservationThe number of features decreased from 98 to two.<jupyter_code># Apply t-SNE to further reduce the dimentionality of the dataset
tsne = TSNE(learning_rate=35)
tsne_features = tsne.fit_transform(crypto_pca)
tsne_features.shape<jupyter_output><empty_output><jupyter_text>ObservationThe number of features remained the same at two.<jupyter_code># The first column of transformed features
x = tsne_features[:,0]

# The second column of transformed features
y = tsne_features[:,1]

# Visualize the clusters
plt.scatter(x, y)
plt.show()<jupyter_output><empty_output><jupyter_text>ObservationUpon visitual inspection, there seems to be five clusters.<jupyter_code># Finding the best k
inertia = []
k = [1,2,3,4,5,6,7,8,9,10]

for i in k:
    km = KMeans(n_clusters=i, random_state=0)
    km.fit(tsne_features)
    inertia.append(km.inertia_)
# Create a dataframe and plot the elbow curve
elbow_data = {"k": k, "inertia": inertia}
elbow_df = pd.DataFrame(elbow_data)

plt.plot(df_elbow["k"], elbow_df["inertia"])
plt.xticks(range(1,11))
plt.xlabel("Number of clusters")
plt.ylabel("Inertia")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0867283950617284, 'fraction_numerical': 0.009259259259259259, 'mean_word_length': 7.665775401069519, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 22, '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': '63129', 'license': 'Apache-2.0', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1109, 'n_words': 270, 'path': 'crypto_clusters.ipynb', 'repo_name': 'nappytrails/cryptocurrency_clusters', 'size': '3240'}