# 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/03_regression/09_regression_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
"""


! chmod 600 kaggle.json && (ls ~/.kaggle 2>/dev/null || mkdir ~/.kaggle) && mv kaggle.json ~/.kaggle/ && echo 'Done'

"""
Explanation: Regression Project
We have learned about regression and how to build regression models using both scikit-learn and TensorFlow. Now we'll build a regression model from start to finish. We will acquire data and perform exploratory data analysis and data preprocessing. We'll build and tune our model and measure how well our model generalizes.
Framing the Problem
Overview
Friendly Insurance, Inc. has requested we do a study for them to help predict the cost of their policyholders. They have provided us with sample anonymous data about some of their policyholders for the previous year. The dataset includes the following information:
Column   | Description
---------|-------------
age      | age of primary beneficiary
sex      | gender of the primary beneficiary (male or female)
bmi      | body mass index of the primary beneficiary
children | number of children covered by the plan
smoker   | is the primary beneficiary a smoker (yes or no)
region   | geographic region of the beneficiaries (northeast, southeast, southwest, or northwest)
charges  | costs to the insurance company
We have been asked to create a model that, given the first six columns, can predict the charges the insurance company might incur.
The company wants to see how accurate we can get with our predictions. If we can make a case for our model, they will provide us with the full dataset of all of their customers for the last ten years to see if we can improve on our model and possibly even predict cost per client year over year.
Exercise 1: Thinking About the Data
Before we dive in to looking closely at the data, let's think about the problem space and the dataset. Consider the questions below.
Question 1
Is this problem actually a good fit for machine learning? Why or why not?
Student Solution

Please Put Your Answer Here


Question 2
If we do build the machine learning model, what biases might exist in the data? Is there anything that might cause the model to have trouble generalizing to other data? If so, how might we make the model more resilient?
Student Solution

Please Put Your Answer Here


Question 3
We have been asked to take input features about people who are insured and predict costs, but we haven't been given much information about how these predictions will be used. What effect might our predictions have on decisions made by the insurance company? How might this affect the insured?
Student Solution

Please Put Your Answer Here


Exploratory Data Analysis
Now that we have considered the societal implications of our model, we can start looking at the data to get a better understanding of what we are working with.
The data we'll be using for this project can be found on Kaggle. Upload your kaggle.json file and run the code block below.
End of explanation
"""


# Add code and text blocks to explore the data and explain your work

"""
Explanation: Exercise 2: EDA and Data Preprocessing
Using as many code and text blocks as you need, download the dataset, explore it, and do any model-independent preprocessing that you think is necessary. Feel free to use any of the tools for data analysis and visualization that we have covered in this course so far. Be sure to do individual column analysis and cross-column analysis. Explain your findings.
Student Solution
End of explanation
"""


# Add code and text blocks to build and validate a model and explain your work

"""
Explanation: Modeling
Now that we understand our data a little better, we can build a model. We are trying to predict 'charges', which is a continuous variable. We'll use a regression model to predict 'charges'.
Exercise 3: Modeling
Using as many code and text blocks as you need, build a model that can predict 'charges' given the features that we have available. To do this, feel free to use any of the toolkits and models that we have explored so far.
You'll be expected to:
1. Prepare the data for the model (or models) that you choose. Remember that some of the data is categorical. In order for your model to use it, you'll need to convert the data to some numeric representation.
1. Build a model or models and adjust parameters.
1. Validate your model with holdout data. Hold out some percentage of your data (10-20%), and use it as a final validation of your model. Print the root mean squared error. We were able to get an RMSE between 3500 and 4000, but your final RMSE will likely be different.
Student Solution
End of explanation
"""


