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

# %matplotlib inline
import sys
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import math
import os

# +
regression_example = '../Data/RegressionExamples/BikeTrain/train.csv'

binary_class_example = '../Data/ClassExamples/DiabetesData/pima-indians-diabetes.data.txt'

multi_class_example = '../Data/ClassExamples/Iris/iris.data.csv'

data_type_example = '../Data/ClassExamples/TwitterAWS/aml_training_dataset.csv'
# -

# ## Labeled Data 
# Labeled Data - contains the features and target attribute with correct answer
# ## Training Set
# Part of labeled data that is used for training the model. 60-70% of the labeled data is used for training
# ## Evaluation Set
# 30-40% of the labeled data is reserved for checking prediction quality with known correct answer
# ## Training Example
# Training Example or a row. Contains one complete observation of features and the correct answer
# ## Features
# Known by different names: Columns, Features, variables, attributes. These are values that define a particular example. Values for some of the features could be missing or invalid in real-world datasets.  So, some cleaning may have to be done before feeding to Machine Learning  
#
# 1. Input Feature - Variables that are provided as input to the model
# 2. Target Attribute - Variable that model needs to predict
#
#

# <h2>AWS ML Data Types</h2>
# <h5>Data from training set needs to be mapped to one of these data types</h5>
# <h4>1. Binary.  Can contain only two state 1/0.</h4>
#   <ul>
#   <li>Positive Values: 1, y, yes, t, true</li>
#   <li>Negative Values: 0, n, no, f, false</li>
#   <li>Values are case-insensitive and AWS ML converts the above values to 1 or 0</li>
#   </ul>
# <h4>2. Categorical.  Qualitative attribute that describes something about an observation.</h4>
# <h5>Example</h5>
#    <ul>
#    <li>Day of the week: Sunday, Monday, Tuesday,...</li>
#    <li>Size: XL, L, M, S </li>
#    <li>Month: 1, 2, 3, 4,...12</li>
#    <li>Season: 1, 2, 3, 4</li>
#    </ul>
# <h4>3. Numeric. Measurements, Counts are represented as numeric types</h4>
#    <ul>
#    <li>Discrete: 20 cars, 30 trees, 2 ships</li>
#    <li>Continous: 98.7 degree F, 32.5 KMPH, 2.6 liters </li>   
#    </ul>
# <h4>4. Text.  String of words. AWS ML automatically tokenizes at white space boundary</h4>
# <h5>Example</h5>
#    <ul>
#    <li>product description, comment, reviews</li>
#    <li>Tokenized: 'Wildlife Photography for beginners' => {‘Wildlife’, ‘Photography’, ‘for’, ‘beginners’}</li>   
#    </ul>   

# <h1>Algorithms</h1>
# <h2>Linear Regression</h2>
# Predict a numeric value as output based on given features
# <p>Examples: 
# What is the market value of a car? 
# What is the current value of a House?
# For a product, how many units can we sell?</p>
#
# <h5>Concrete Example</h5>
# Kaggle Bike Rentals - Predict number of bike rentals every hour.  Total should include both casual
#     rentals and registered users rentals
#
# Input Columns/Features = ['datetime', 'season', 'holiday', 'workingday', 'weather', 'temp',
#                           'atemp', 'humidity', 'windspeed']
#
# Output Column/Target Attribute = 'count'<br>
# count = casual + registered <br>
# Option 1: Predict casual and registered counts separately and then sum it up <br>
# Option 2: Predict count directly

# read the bike train csv file
df = pd.read_csv(regression_example)

df.head()

df.corr()

df['count'].describe()

df.season.value_counts()

df.holiday.value_counts()

df.workingday.value_counts()

df.weather.value_counts()

df.temp.describe()

# <h2>Binary Classification</h2>
# Predict a binary class as output based on given features
#
# <p>Examples: Do we need to follow up on a customer review?
# Is this transaction fraudulent or valid one?
# Are there signs of onset of a medical condition or disease?
# Is this considered junk food or not?
# </p>
#
#
# <h5>Concrete Example</h5>
# pima-indians-diabetes - Predict if a given patient has a risk of getting diabetes<br>
# https://archive.ics.uci.edu/ml/datasets/Pima+Indians+Diabetes
#
# Input Columns/Features = ['preg_count', 'glucose_concentration', 'diastolic_bp',
#        'triceps_skin_fold_thickness', 'two_hr_serum_insulin', 'bmi',
#        'diabetes_pedi', 'age']
#
# Output Column/Target Attribute = 'diabetes_class'.  1 = diabetic, 0 = normal

df = pd.read_csv(binary_class_example)

df.head()

df.columns

df.corr()

df.age.value_counts().head()

df.diabetes_class.value_counts()

# <h2>Multiclass Classification</h2>
# Predict a class as output based on given features
#
# Examples:
#     1. How healthy is the food based on given ingredients?
#     Classes: Healthy, Moderate, Occasional, Avoid.
#     
#     2. Identify type of mushroom based on features
#     
#     3. What type of advertisement can be placed for this search?
#
# <h5>Concrete Example</h5>
# Iris Classification - Predict the type of Iris plant based on flower measurments<br>
# https://archive.ics.uci.edu/ml/datasets/Iris
#
# Input Columns / Features = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width']
#
# Output Column / Target Attribute = 'class'.  
#
# Class: Iris-setosa, Iris-virginica, Iris-versicolor

df = pd.read_csv(multi_class_example)

np.random.seed(5)
# print 10 random rows
df.iloc[np.random.randint(0, df.shape[0], 10)]

df.columns

df['class'].value_counts()

df.sepal_length.describe()

# # Data Types

df = pd.read_csv(data_type_example)

df.columns

df[['description', 'favourites_count', 'favorited', 'text', 'screen_name', 'trainingLabel']].head()

StarcoderdataJupyterScriptsDedupFiltered