Program 2a
Problem Statement
Develop a comprehensive Python program to analyze and visualize the Breast Cancer
Wisconsin dataset using matplotlib. The primary objective of the program is to generate various
plots to illustrate the distribution of data and the relationships between different attributes of
the dataset.
import [Link] as plt # Importing the Matplotlib library for plotting
import pandas as pd # Importing the Pandas library for data manipulation
from [Link] import load_breast_cancer # Importing the Breast Cancer dataset from sklearn
# Load the breast cancer dataset
cancer = load_breast_cancer() # Loading the built-in Breast Cancer dataset
# Convert to pandas DataFrame
data = [Link]([Link], columns=cancer.feature_names) # Converting the dataset to a
pandas DataFrame
data['target'] = [Link] # Adding the target column to the DataFrame
# Display a concise summary of the DataFrame
print([Link]()) # Displaying a concise summary of the DataFrame, including the number of entries,
columns, non-null values, and data types
# Display the first few rows of the dataset
print([Link](1)) # Displaying the first few rows of the DataFrame to get an initial look at the data
# Display basic statistics
print([Link]()) # Displaying basic statistical details like mean, std deviation, min, and max
values for each column
# Check for any missing values
print([Link]().sum()) # Checking for any missing values in the DataFrame
# Line Plot
[Link](figsize=(10, 6)) # Setting the figure size for the plot
[Link]([Link], data['mean radius'], label='Mean Radius') # Creating a line plot for the 'mean
radius' column
[Link]('Line Plot of Mean Radius') # Adding a title to the plot
[Link]('Index') # Adding a label to the X-axis
[Link]('Mean Radius') # Adding a label to the Y-axis
[Link]() # Adding a legend to the plot
[Link](True) # Enabling the grid for the plot
[Link]() # Displaying the plot
# Scatter Plot
[Link](figsize=(10, 6)) # Setting the figure size for the plot
[Link](data['mean radius'], data['mean texture'], c=data['target'], cmap='coolwarm', alpha=0.5) #
Creating a scatter plot with 'mean radius' and 'mean texture', color-coded by the target class
[Link]('Scatter Plot of Mean Radius vs Mean Texture') # Adding a title to the plot
[Link]('Mean Radius') # Adding a label to the X-axis
[Link]('Mean Texture') # Adding a label to the Y-axis
[Link](True) # Enabling the grid for the plot
[Link]() # Displaying the plot
# Bar Plot
[Link](figsize=(10, 6)) # Setting the figure size for the plot
[Link](data['target'].value_counts().index, data['target'].value_counts().values) # Creating a bar plot
for the target class distribution
[Link]('Bar Plot of Target Class Distribution') # Adding a title to the plot
[Link]('Target Class') # Adding a label to the X-axis
[Link]('Count') # Adding a label to the Y-axis
[Link](ticks=[0, 1], labels=['Malignant', 'Benign']) # Setting the ticks and labels for the X-axis
[Link](True) # Enabling the grid for the plot
[Link]() # Displaying the plot
# Histogram
[Link](figsize=(10, 6)) # Setting the figure size for the plot
[Link](data['mean area'], bins=30, alpha=0.7) # Creating a histogram for the 'mean area' column
with 30 bins
[Link]('Histogram of Mean Area') # Adding a title to the plot
[Link]('Mean Area') # Adding a label to the X-axis
[Link]('Frequency') # Adding a label to the Y-axis
[Link](True) # Enabling the grid for the plot
[Link]() # Displaying the plot
# Box Plot
[Link](figsize=(10, 6)) # Setting the figure size for the plot
[Link]([data[data['target'] == 0]['mean radius'], data[data['target'] == 1]['mean radius']],
labels=['Malignant', 'Benign']) # Creating a box plot for the 'mean radius' column, grouped by the
target class
[Link]('Box Plot of Mean Radius by Target Class') # Adding a title to the plot
[Link]('Target Class') # Adding a label to the X-axis
[Link]('Mean Radius') # Adding a label to the Y-axis
[Link](True) # Enabling the grid for the plot
[Link]() # Displaying the plot
Program 2b
Problem Statement
Develop a Python program to analyze and visualize the Breast Cancer Wisconsin dataset using
the seaborn library. The primary objective of this program is to generate a variety of plots that
help illustrate the distribution, relationships, and patterns within the dataset's attributes.
import seaborn as sns # Import Seaborn for advanced data visualization
import pandas as pd # Import Pandas for data manipulation
import [Link] as plt # Import Matplotlib for plotting
from [Link] import load_breast_cancer # Import the Breast Cancer dataset from
sklearn
# Load the Breast Cancer Wisconsin dataset
cancer = load_breast_cancer() # Fetch the dataset from sklearn's built-in datasets
# Convert the dataset to a pandas DataFrame
data = [Link]([Link], columns=cancer.feature_names) # Create a DataFrame with
feature names as columns
data['target'] = [Link] # Add the target column to the DataFrame, which contains the
class labels
# Display a concise summary of the DataFrame
print([Link]()) # Displaying a concise summary of the DataFrame, including the number of
entries, columns, non-null values, and data types
# Display the first few rows of the dataset
print([Link](1)) # Displaying the first few rows of the DataFrame to get an initial look at
the data
# Display basic statistics
print([Link]()) # Displaying basic statistical details like mean, std deviation, min, and
max values for each column
# Check for any missing values
print([Link]().sum()) # Checking for any missing values in the DataFrame
# Count Plot
[Link](figsize=(6, 4)) # Set the size of the figure for the plot
[Link](x='target', data=data, palette='coolwarm') # Create a count plot to visualize the
number of Malignant vs. Benign cases
[Link]('Count Plot of Target Classes') # Add a title to the plot
[Link]('Target Class') # Add a label to the X-axis
[Link]('Count') # Add a label to the Y-axis
[Link](ticks=[0, 1], labels=['Malignant', 'Benign']) # Set the ticks and labels for the X-axis
[Link]() # Display the plot
# KDE Plot
[Link](figsize=(10, 6)) # Set the size of the figure for the plot
[Link](data=data[data['target'] == 0]['mean radius'], shade=True, label='Malignant',
color='r') # KDE plot for 'mean radius' for Malignant cases
[Link](data=data[data['target'] == 1]['mean radius'], shade=True, label='Benign',
color='b') # KDE plot for 'mean radius' for Benign cases
[Link]('KDE Plot of Mean Radius') # Add a title to the plot
[Link]('Mean Radius') # Add a label to the X-axis
[Link]('Density') # Add a label to the Y-axis
[Link]() # Add a legend to the plot
[Link]() # Display the plot
# Violin Plot
[Link](figsize=(10, 6)) # Set the size of the figure for the plot
[Link](x='target', y='mean radius', data=data, palette='coolwarm') # Create a violin plot
for 'mean radius' by target class
[Link]('Violin Plot of Mean Radius by Target Class') # Add a title to the plot
[Link]('Target Class') # Add a label to the X-axis
[Link]('Mean Radius') # Add a label to the Y-axis
[Link](ticks=[0, 1], labels=['Malignant', 'Benign']) # Set the ticks and labels for the X-axis
[Link]() # Display the plot
# Pair Plot
[Link](data, vars=['mean radius', 'mean texture', 'mean perimeter', 'mean area'],
hue='target', palette='coolwarm') # Create a pair plot for selected features, color-coded by
target class
[Link]('Pair Plot') # Add a title to the plot
[Link]() # Display the plot
# Heatmap
[Link](figsize=(20, 20)) # Set the size of the figure for the plot
[Link]([Link](), annot=True, fmt='.2f', cmap='coolwarm') # Create a heatmap for the
correlation matrix of features
[Link]('Correlation Heatmap') # Add a title to the plot
[Link]() # Display the plot