Discover visualizations with AWS Glue interactive periods

AWS Glue interactive periods supply a robust approach to iteratively discover datasets and fine-tune transformations utilizing Jupyter-compatible notebooks. Interactive periods allow you to work with a selection of in style built-in growth environments (IDEs) in your native surroundings or with AWS Glue or Amazon SageMaker Studio notebooks on the AWS Administration Console, all whereas seamlessly harnessing the facility of a scalable, on-demand Apache Spark backend. This publish is a part of a sequence exploring the options of AWS Glue interactive periods.

AWS Glue interactive periods now embrace native help for the matplotlib visualization library (AWS Glue model 3.0 and later). On this publish, we take a look at how we will use matplotlib and Seaborn to discover and visualize information utilizing AWS Glue interactive periods, facilitating fast insights with out advanced infrastructure setup.

Answer overview

You’ll be able to rapidly provision new interactive periods immediately out of your pocket book with no need to work together with the AWS Command Line Interface (AWS CLI) or the console. You should utilize magic instructions to supply configuration choices on your session and set up any further Python modules which are wanted.

On this publish, we use the basic Iris and MNIST datasets to navigate by way of a number of generally used visualization methods utilizing matplotlib on AWS Glue interactive periods.

Create visualizations utilizing AWS Glue interactive periods

We begin by putting in the Sklearn and Seaborn libraries utilizing the additional_python_modules Jupyter magic command:

%additional_python_modules scikit-learn, seaborn

You can too add Python wheel modules to Amazon Easy Storage Service (Amazon S3) and specify the complete path as a parameter worth to the additional_python_modules magic command.

Now, let’s run a number of visualizations on the Iris and MNIST datasets.

  1. Create a pair plot utilizing Seaborn to uncover patterns inside sepal and petal measurements throughout the iris species:
    import seaborn as sns
    import matplotlib.pyplot as plt
    # Load the Iris dataset
    iris = sns.load_dataset("iris")
    # Create a pair plot
    sns.pairplot(iris, hue="species")
    %matplot plt

  2. Create a violin plot to disclose the distribution of the sepal width measure throughout the three species of iris flowers:
    # Create a violin plot of the Sepal Width measure
    plt.determine(figsize=(10, 6))
    sns.violinplot(x="species", y="sepal_width", information=iris)
    plt.title("Violin Plot of Sepal Width by Species")
    %matplot plt

  3. Create a warmth map to show correlations throughout the iris dataset variables:
    # Calculate the correlation matrix
    correlation_matrix = iris.corr()
    # Create a heatmap utilizing Seaborn
    plt.determine(figsize=(8, 6))
    sns.heatmap(correlation_matrix, annot=True, cmap="coolwarm")
    plt.title("Correlation Heatmap")
    %matplot plt

  4. Create a scatter plot on the MNIST dataset utilizing PCA to visualise distributions among the many handwritten digits:
    import matplotlib.pyplot as plt
    from sklearn.datasets import fetch_openml
    from sklearn.decomposition import PCA
    # Load the MNIST dataset
    mnist = fetch_openml('mnist_784', model=1)
    X, y = mnist['data'], mnist['target']
    # Apply PCA to scale back dimensions to 2 for visualization
    pca = PCA(n_components=2)
    X_pca = pca.fit_transform(X)
    # Scatter plot of the lowered information
    plt.scatter(X_pca[:, 0], X_pca[:, 1], c=y.astype(int), cmap='viridis', s=5)
    plt.xlabel("Principal Element 1")
    plt.ylabel("Principal Element 2")
    plt.title("PCA - MNIST Dataset")
    plt.colorbar(label="Digit Class")
    %matplot plt

  5. Create one other visualization utilizing matplotlib and the mplot3d toolkit:
    import numpy as np
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    # Generate mock information
    x = np.linspace(-5, 5, 100)
    y = np.linspace(-5, 5, 100)
    x, y = np.meshgrid(x, y)
    z = np.sin(np.sqrt(x**2 + y**2))
    # Create a 3D plot
    fig = plt.determine(figsize=(10, 8))
    ax = fig.add_subplot(111, projection='3d')
    # Plot the floor
    floor = ax.plot_surface(x, y, z, cmap='viridis')
    # Add coloration bar to map values to colours
    fig.colorbar(floor, ax=ax, shrink=0.5, facet=10)
    # Set labels and title
    ax.set_title('3D Floor Plot Instance')
    %matplot plt

As illustrated by the previous examples, you need to use any suitable visualization library by putting in the required modules after which utilizing the %matplot magic command.


On this publish, we mentioned how extract, remodel, and cargo (ETL) builders and information scientists can effectively visualize patterns of their information utilizing acquainted libraries by way of AWS Glue interactive periods. With this performance, you’re empowered to deal with extracting useful insights from their information, whereas AWS Glue handles the infrastructure heavy lifting utilizing a serverless compute mannequin. To get began at the moment, seek advice from Creating AWS Glue jobs with Notebooks and Interactive periods.

Concerning the authors

Annie Nelson is a Senior Options Architect at AWS. She is a knowledge fanatic who enjoys downside fixing and tackling advanced architectural challenges with prospects.

Keerthi Chadalavada is a Senior Software program Improvement Engineer at AWS Glue. She is captivated with designing and constructing end-to-end options to deal with buyer information integration and analytic wants.

Zach Mitchell is a Sr. Huge Knowledge Architect. He works inside the product group to reinforce understanding between product engineers and their prospects whereas guiding prospects by way of their journey to develop their enterprise information structure on AWS.

Gal blog picGal Heyne is a Product Supervisor for AWS Glue with a robust deal with AI/ML, information engineering and BI. She is captivated with growing a deep understanding of buyer’s enterprise wants and collaborating with engineers to design simple to make use of information merchandise.

Related Articles


Please enter your comment!
Please enter your name here

Latest Articles