import pandas as pd
pd.plotting.register_matplotlib_converters()
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
print("Setup Complete")

"""
Explanation: In this exercise, you will use your new knowledge to propose a solution to a real-world scenario.  To succeed, you will need to import data into Python, answer questions using the data, and generate histograms and density plots to understand patterns in the data.
Scenario
You'll work with a real-world dataset containing information collected from microscopic images of breast cancer tumors, similar to the image below.

Each tumor has been labeled as either benign (noncancerous) or malignant (cancerous).
To learn more about how this kind of data is used to create intelligent algorithms to classify tumors in medical settings, watch the short video at this link.
Setup
Run the next cell to import and configure the Python libraries that you need to complete the exercise.
End of explanation
"""


# Set up code checking
from learntools.core import binder
binder.bind(globals())
from learntools.data_viz_to_coder.ex5 import *
print("Setup Complete")

"""
Explanation: The questions below will give you feedback on your work. Run the following cell to set up our feedback system.
End of explanation
"""


# Path of the files to read
cancer_filepath = "../input/cancer.csv"

# Fill in the line below to read the file into a variable cancer_data
cancer_data = ____

# Run the line below with no changes to check that you've loaded the data correctly
step_1.check()

#%%RM_IF(PROD)%%
cancer_data = pd.read_csv(cancer_filepath, index_col="Id")
step_1.assert_check_passed()

# Lines below will give you a hint or solution code
#_COMMENT_IF(PROD)_
step_1.hint()
#_COMMENT_IF(PROD)_
step_1.solution()

"""
Explanation: Step 1: Load the data
In this step, you will load the data.
- Load the data file into a DataFrame called cancer_data.
- The corresponding filepath is cancer_filepath.
- Use the "Id" column to label the rows.
End of explanation
"""


# Print the first five rows of the data
____ # Your code here

"""
Explanation: Step 2: Review the data
Use a Python command to print the first 5 rows of the data.
End of explanation
"""


# Fill in the line below: In the first five rows of the data, what is the
# largest value for 'Perimeter (mean)'?
max_perim = ____

# Fill in the line below: What is the value for 'Radius (mean)' for the tumor with Id 8510824?
mean_radius = ____

# Check your answers
step_2.check()

#%%RM_IF(PROD)%%
max_perim = 87.46
mean_radius = 9.504
step_2.assert_check_passed()

# Lines below will give you a hint or solution code
#_COMMENT_IF(PROD)_
step_2.hint()
#_COMMENT_IF(PROD)_
step_2.solution()

"""
Explanation: In the dataset, each row corresponds to a different image.  The dataset has 31 different columns, corresponding to:
- 1 column ('Diagnosis') that classifies tumors as either benign (which appears in the dataset as B) or malignant (M), and
- 30 columns containing different measurements collected from the images.
Use the first 5 rows of the data to answer the questions below.
End of explanation
"""


# Histograms for benign and maligant tumors
____

# Check your answer
step_3.a.check()

#%%RM_IF(PROD)%%
sns.histplot(data=cancer_data, x='Area (mean)', hue='Diagnosis')
step_3.a.assert_check_passed()

# Lines below will give you a hint or solution code
#_COMMENT_IF(PROD)_
step_3.a.hint()
#_COMMENT_IF(PROD)_
step_3.a.solution_plot()

"""
Explanation: Step 3: Investigating differences
Part A
Use the code cell below to create two histograms that show the distribution in values for 'Area (mean)', separately for both benign and malignant tumors.  (To permit easy comparison, create a single figure containing both histograms in the code cell below.)
End of explanation
"""


#_COMMENT_IF(PROD)_
step_3.b.hint()

# Check your answer (Run this code cell to receive credit!)
step_3.b.solution()

"""
Explanation: Part B
A researcher approaches you for help with identifying how the 'Area (mean)' column can be used to understand the difference between benign and malignant tumors.  Based on the histograms above, 
- Do malignant tumors have higher or lower values for 'Area (mean)' (relative to benign tumors), on average?
- Which tumor type seems to have a larger range of potential values?
End of explanation
"""


# KDE plots for benign and malignant tumors
____ 

# Check your answer
step_4.a.check()

#%%RM_IF(PROD)%%
sns.kdeplot(data=cancer_data, x='Radius (worst)', hue='Diagnosis', shade=True)
step_4.a.assert_check_passed()

#%%RM_IF(PROD)%%
#sns.kdeplot(data=cancer_b_data['Radius (worst)'], shade=True, label="Benign")
#step_4.a.assert_check_failed()

# Lines below will give you a hint or solution code
#_COMMENT_IF(PROD)_
step_4.a.hint()
#_COMMENT_IF(PROD)_
step_4.a.solution_plot()

"""
Explanation: Step 4: A very useful column
Part A
Use the code cell below to create two KDE plots that show the distribution in values for 'Radius (worst)', separately for both benign and malignant tumors.  (To permit easy comparison, create a single figure containing both KDE plots in the code cell below.)
End of explanation
"""


#_COMMENT_IF(PROD)_
step_4.b.hint()

# Check your answer (Run this code cell to receive credit!)
step_4.b.solution()

"""
Explanation: Part B
A hospital has recently started using an algorithm that can diagnose tumors with high accuracy.  Given a tumor with a value for 'Radius (worst)' of 25, do you think the algorithm is more likely to classify the tumor as benign or malignant?
End of explanation
"""


