This report is generated of what cryptocurrencies are available on the trading market and how they can be grouped using classification. I have used unsupervivsed machine learning and Amazon SageMaker by clustering cryptocurrencies and creating plots to present the results.
The following tasks have been completed:
- Data Preprocessing: Prepare data for dimension reduction with PCA and clustering using K-Means.
- Reducing Data Dimensions Using PCA: Reduce data dimension using the PCA algorithm from sklearn.
- Clustering Cryptocurrencies Using K-Means: Predict clusters using the cryptocurrencies data using the KMeans algorithm from sklearn.
- Visualizing Results: Create some plots and data tables to present the results.
- Challenge: Deploy notebook to Amazon SageMaker.
In this section, you will load the information about cryptocurrencies and perform data preprocessing tasks. You can choose one of the following methods to load the data:
-
Using the provided
CSV
file, create aPath
object and read the file data directly into a DataFrame namedcrypto_df
usingpd.read_csv()
. -
Using the following
requests
library, retreive the necessary data from the following API endpoint from CryptoCompare -https://min-api.cryptocompare.com/data/all/coinlist
. You will need to use the 'Data' key from the json response, then transpose the DataFrame. Name your DataFramecrypto_df
.
With the data loaded into a Pandas DataFrame, continue with the following data preprocessing tasks.
-
Keep only the necessary columns: 'CoinName','Algorithm','IsTrading','ProofType','TotalCoinsMined','TotalCoinSupply'
-
Keep only the cryptocurrencies that are trading.
-
Keep only the cryptocurrencies with a working algorithm.
-
Remove the
IsTrading
column. -
Remove all cryptocurrencies with at least one null value.
-
Remove all cryptocurrencies that have no coins mined.
-
Drop all rows where there are 'N/A' text values.
-
Store the names of all cryptocurrencies in a DataFrame named
coins_name
, use thecrypto_df.index
as the index for this new DataFrame. -
Remove the
CoinName
column. -
Create dummy variables for all the text features, and store the resulting data in a DataFrame named
X
. -
Use the
StandardScaler
fromsklearn
to standardize all the data of theX
DataFrame. Remember, this is important prior to using PCA and K-Means algorithms.
Use the PCA
algorithm from sklearn
to reduce the dimensions of the X
DataFrame down to three principal components.
Once you have reduced the data dimensions, create a DataFrame named pcs_df
using as columns names "PC 1", "PC 2"
and "PC 3"
; use the crypto_df.index
as the index for this new DataFrame.
You should have a DataFrame like the following:
In this section, you will use the KMeans
algorithm from sklearn
to cluster the cryptocurrencies using the PCA data.
Perform the following tasks:
-
Create an Elbow Curve to find the best value for
k
using thepcs_df
DataFrame. -
Once you define the best value for
k
, run theKmeans
algorithm to predict thek
clusters for the cryptocurrencies data. Use thepcs_df
to run theKMeans
algorithm. -
Create a new DataFrame named
clustered_df
, that includes the following columns"Algorithm", "ProofType", "TotalCoinsMined", "TotalCoinSupply", "PC 1", "PC 2", "PC 3", "CoinName", "Class"
. You should maintain the index of thecrypto_df
DataFrames as is shown bellow.
In this section, you will create some data visualization to present the final results. Perform the following tasks:
-
Create a 3D-Scatter using Plotly Express to plot the clusters using the
clustered_df
DataFrame. You should include the following parameters on the plot:hover_name="CoinName"
andhover_data=["Algorithm"]
to show this additional info on each data point. -
Use
hvplot.table
to create a data table with all the current tradable cryptocurrencies. The table should have the following columns:"CoinName", "Algorithm", "ProofType", "TotalCoinSupply", "TotalCoinsMined", "Class"
-
Create a scatter plot using
hvplot.scatter
, to present the clustered data about cryptocurrencies havingx="TotalCoinsMined"
andy="TotalCoinSupply"
to contrast the number of available coins versus the total number of mined coins. Use thehover_cols=["CoinName"]
parameter to include the cryptocurrency name on each data point.
For the challenge section, you have to upload your Jupyter notebook to Amazon SageMaker and deploy it.
The hvplot
and Plotly Express libraries are not included in the built-in anaconda environments, so for this challenge section, you should use the altair
library instead.
Perform the following tasks:
-
Upload your Jupyter notebook and rename it as
crypto_clustering_sm.ipynb
-
Select the
conda_python3
environment. -
Import the
altair
library by running the following code before the initial imports.
!pip install -U altair
-
Use the
altair
scatter plot to create the Elbow Curve. -
Use the
altair
scatter plot, instead of the 3D-Scatter from Plotly Express, to visualize the clusters. Since this is a 2D-Scatter, usex="PC 1"
andy="PC 2"
for the axes, and add the following columns as tool tips:"CoinName", "Algorithm", "TotalCoinsMined", "TotalCoinSupply"
. -
Use the
altair
scatter plot to visualize the tradable cryptocurrencies usingx="TotalCoinsMined"
andy="TotalCoinSupply"
for the axes. -
Show the table of current tradable cryptocurrencies using the
display()
command. -
Remove all
hvplot
and Plotly Express references from your code.