# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="dZN9P40wNVBI"
# <img src="https://drive.google.com/uc?id=1E_GYlzeV8zomWYNBpQk0i00XcZjhoy3S" width="100"/>  
# # Drill Week 3: Feature Manipulation   
#
# In this drill, you will use essential pandas manipulations on a NEW dataset.   
# We will get this dataset from an outside source :)    
#
# Specifically, we will be using the wine dataset.  
#
#
# <img src="https://img.clipartlook.com/wine-clipart-set-of-vector-and-watercolor-drawings-of-wine-glasses-vector-art-illustration-612.jpg" width="400"/>  
#

# + id="o2FgwyrPNYw3"
from sklearn.datasets import load_wine

import pandas as pd  # fill in with the proper package name 


# + [markdown] id="DK8ctvzGPN3j"
# This dataset contains 3 types of wines, and the following measures for each   
#
# - Alcohol
# - Malic acid
# - Ash
# - Alcalinity of ash
# - Magnesium
# - Total phenols
# - Flavanoids
# - Nonflavanoid phenols
# - Proanthocyanins
# - Color intensity
# - Hue
# - OD280/OD315 of diluted wines
# - Proline

# + id="RrYCSMV6OHqp"
data = load_wine() 
features = data.data # these are our features 
labels = data.target
df = pd.DataFrame(features)
df.columns = data.feature_names
df['labels'] = labels

# + id="Asvh4DRNOak-" colab={"base_uri": "https://localhost:8080/", "height": 430} executionInfo={"status": "ok", "timestamp": 1615292473732, "user_tz": 300, "elapsed": 375, "user": {"displayName": "<NAME>", "photoUrl": "https://<KEY>", "userId": "09876300174086012890"}} outputId="52385021-0f5c-46e0-c191-0954e2304519"
df

# + [markdown] id="imQd6EjmQzqh"
# ## Drilling Feature Manipulation   
# Use pd.columns to return the title of each feature 

# + id="qz3YY3wUSdob"


# + [markdown] id="sttZTn3rRFMX"
# Your equipment measurer was not callibrated correctly. Add 2 points to the magnesium of each entry 

# + id="By-yRqVRSeAe"


# + [markdown] id="G2VdlHvqReJ9"
# Create a new feature called flav_to_non_flav ratio that is the ratio between flavanoids and nonflavanoid_phenols.   
# Run a df.head to make sure your changes were made 

# + id="vz-G55U_R8Ri"


# + [markdown] id="nOGFFOysSOqN"
# Create a new dataframe called high_alcohol_content. Have it only contain the entries with the alcohol value over 13.5  
# Hint -- use the solution as shown in the lecture 

# + id="wFYgV_H9Sgpj"


# + [markdown] id="vXUIUilUSJvj"
# Increase the malic_acid value by 1 where the total_phenols is over 1.7

# + id="gY2o8qjrShRR"


# + [markdown] id="AOE8YPF7P-I9"
# ## Drilling Feature Selection   
# You hate the number 13. Use loc to drop the entry at position 13. (Remember -- Python uses 0 indexing!) 

# + id="mC-B27MsP8gt"


# + [markdown] id="H99w0SKqQYEp"
# You also know that having too many features may increase computational overhead and not help accuracy.  
# Drop the 3 columns you think are the least helpful in determining the wine class 

# + id="ayhZoUlfPt2N"


# + [markdown] id="l_9xb70nlGAe"
# #Preprocessing

# + [markdown] id="Zw_Nbh6XlIPF"
# For each column, find the number of missing values

# + id="3omGILfBlNAW"


# + [markdown] id="lIJbWEfnlNmA"
# Take the correlation among the features using a heatmap. Drop the 3 columns with the lowest amount of correlation with "label" in magnitude.

# + id="I0jlfC8pnVS9"


# + [markdown] id="OV6pXSdzTMso"
# ## Drilling Critical Thinking    
# Say you are given a new dataset. You see there are over 30 features.   
# What are some benefits and drawbacks to having this many features?     
# If you had to drop some, what are a few ways that you could select which features to keep?  

StarcoderdataJupyterScriptsDedupFiltered