Answered step by step
Verified Expert Solution
Question
1 Approved Answer
mport seaborn as sns import matplotlib.pyplot as plt import pandas as pd # Create the DataFrame from the table data data = { 'Risk Description':
mport seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
# Create the DataFrame from the table data
data
'Risk Description':
'Unwanted Outputs, Bias', 'Lack of Quality, Factuality', 'Lack of Timeliness',
'Lack of Explainability', 'Insecure Generated Code', 'Incorrect Response to Inputs',
'Automation Bias', 'Misinterpreting Text as Instruction', 'Lack of Confidentiality',
'Selfreinforcing Impacts', 'Developer Dependence', 'Misinformation',
'Social Engineering', Reidentification', 'Surveillance Concerns',
'Malware Creation', 'Malware Placement', 'RCE Attacks', 'Training Data Reconstruction',
'Model Subversion', 'Member Reasoning Attacks', 'Homograph Attacks', 'Prompt Injection Attacks',
'Data Poisoning', 'Model Poisoning', 'Learning Transfer Attacks', 'Environmental Impact',
'Economic Disruption', 'OverrelianceDependency 'Dual Use Concerns', 'Unforeseen Consequences'
'Planning':
'Data':
'Development':
'Operation':
'Risk Level': High 'Medium', 'Medium', 'High', 'High', 'Medium', 'Medium', 'Medium', 'High', 'Medium', 'Medium', 'High', 'Medium', 'High', 'High', 'High', 'Medium', 'High', 'Medium', 'Medium', 'Medium', 'Low', 'Medium', 'Medium', 'Medium', 'Low', 'Low', 'Low', 'Medium', 'High', 'High'
df pdDataFramedata
df dfsetindexRisk Description'
dfheatmap dftranspose
# Create heatmap
pltfigurefigsize
snssetfontscale
# Create a custom color palette white to red gradient
cmap snscolorpaletteReds ascmapTrue
ax snsheatmapdfheatmap, cmapcmap, annotdfRisk Level' fmt linewidths cbarkwslabel: 'Risk Level'
# Add tooltips
for i in rangelendfheatmap:
for j in rangelendfheatmap.columns:
text axtextj i dfheatmap.valuesi j ha"center", va"center", color"black"
text.setgidftooltipij
tooltiptext dfindexj: dfcolumnsi
axaddartistAnchoredTexttooltiptext, loc"center", frameonTrue, propdictfontsize
# Set up the hover functionality
from matplotlib.offsetbox import AnchoredText
def onhoverevent:
for text in axtexts:
cont, ind text.containsevent
if cont:
text.setweightbold
text.setbboxdictfacecolor'white', alpha edgecolor'black'
annotation text.getgidsplit:
tooltiptext dfindexintannotation: dfcolumnsintannotation
axaddartistAnchoredTexttooltiptext, loc"center", frameonTrue, propdictfontsize
else:
text.setweightnormal
text.setbboxdictfacecolor'white', alpha edgecolor'black'
pltgcfcanvas.mplconnectmotionnotifyevent", onhover
# Add a title
plttitleAI System Lifecycle & Impact Risk Assessment Heatmap', fontsize
# Show the plot
pltshow
Chi rho eta sigma iota mu omicron pi omicron iota sigma tau epsi tau omicron
u kappa delta iota kappa alpha mu epsi pi rho omicron sigma omicron chi
playcircleeditcontentcopy
Key Changes:
Gradient Color Map: Uses "Reds" colormap to represent risk intensity from low white to high red
Risk Level Annotations: Directly annotates cells with "High," "Medium," or "Low" instead of numerical values.
Gridlines: Adds gridlines for easier visual separation of cells.
Enhanced Tooltips: Provides full risk descriptions in tooltips when hovering over cells.
Sorting: Groups risks by lifecycle phase and impact for better visual organization. OPTIMAZE THE HEATMAP WITH THE CODE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started