# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Explanation: <a href="https://colab.research.google.com/github/google/applied-machine-learning-intensive/blob/master/content/05_deep_learning/05_image_classification_project/colab.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
Copyright 2020 Google LLC.
End of explanation
"""


# Your code goes here

"""
Explanation: Image Classification Project
In this project we will build an image classification model and use the model to identify if the lungs pictured indicate that the patient has pneumonia. The outcome of the model will be true or false for each image.
The data is hosted on Kaggle and consists of 5,863 x-ray images. Each image is classified as 'pneumonia' or 'normal'.
Ethical Considerations
We will frame the problem as:

A hospital is having issues correctly diagnosing patients with pneumonia. Their current solution is to have two trained technicians examine every patient scan. Unfortunately, there are many times when two technicians are not available, and the scans have to wait for multiple days to be interpreted.
They hope to fix this issue by creating a model that can identify if a patient has pneumonia. They will have one technician and the model both examine the scans and make a prediction. If the two agree, then the diagnosis is accepted. If the two disagree, then a second technician is brought in to provide their analysis and break the tie.

Discuss some of the ethical considerations of building and using this model. 

Consider potential bias in the data that we have been provided. 
Should this model err toward precision or accuracy?
What are the implications of massively over-classifying patients as having pneumonia?
What are the implications of massively under-classifying patients as having pneumonia?
Are there any concerns with having only one technician make the initial call?

The questions above are prompts. Feel free to bring in other considerations you might have.
Student Solution

Your answer goes here


Modeling
In this section of the lab, you will build, train, test, and validate a model or models. The data is the "Detecting Pneumonia" dataset. You will build a binary classifier that determines if an x-ray image has pneumonia or not.
You'll need to:

Download the dataset
Perform EDA on the dataset
Build a model that can classify the data
Train the model using the training portion of the dataset. (It is already split out.)
Test at least three different models or model configurations using the testing portion of the dataset. This step can include changing model types, adding and removing layers or nodes from a neural network, or any other parameter tuning that you find potentially useful. Score the model (using accuracy, precision, recall, F1, or some other relevant score(s)) for each configuration.
After finding the "best" model and parameters, use the validation portion of the dataset to perform one final sanity check by scoring the model once more with the hold-out data.
If you train a neural network (or other model that you can get epoch-per-epoch performance), graph that performance over each epoch.

Explain your work!

Note: You'll likely want to enable GPU in this lab if it is not already enabled.

If you get to a working solution you're happy with and want another challenge, you'll find pre-trained models on the landing page of the dataset. Try to load one of those and see how it compares to your best model.
Use as many text and code cells as you need to for your solution.
Student Solution
End of explanation
"""


