"""
# Cardio Good Fitness Case Study 
The market research team at AdRight is assigned the task to identify the profile of the typical customer for each treadmill product offered by CardioGood Fitness. The market research team decides to investigate whether there are differences across the product lines with respect to customer characteristics. The team decides to collect data on individuals who purchased a treadmill at a CardioGoodFitness retail store during the prior three months. The data are stored in the CardioGoodFitness.csv file.

### The team identifies the following customer variables to study: 
  - product purchased, TM195, TM498, or TM798; 
  - gender; 
  - age, in years; 
  - education, in years; 
  - relationship status, single or partnered; 
  - annual household income ; 
  - average number of times the customer plans to use the treadmill each week; 
  - average number of miles the customer expects to walk/run each week; 
  - and self-rated fitness on an 1-to-5 scale, where 1 is poor shape and 5 is excellent shape.

**Objective**
- Identify differences between customers of each product
- Explore relationships between the difference attributes of customers
"""
"""
### Import required libraries:
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore') 

"""
### Load Dataset:
"""
#Load the Cardio Dataset

mydata = pd.read_csv('../input/cardiogoodfitness/CardioGoodFitness.csv')
"""
### Understanding the structure of Data:
"""
mydata.head()
mydata.tail()
mydata.shape
"""
 **Observations:** There are 180 observations of 9 columns in the dataset
"""
mydata.dtypes
"""
 **Observations:**

1. Columns Product, Gender and Marital Status are of string datatype 
2. Columns Age, Education, Usage, Fitness, Income and Miles are of integer (numerical) datatype
"""
mydata.info()
"""
**Observations:**

1. There are 6 columns of integer type
2. There are 3 objects of string type
3. The dataset is of approximately 12.8 kb in size
4. There are 180 rows

"""
mydata.columns
mydata.isnull().sum()
mydata.describe(include ='all')
"""
**Observations:** 

**A. AGE:**

    1. Customers between 18 and 50 years of age are using treadmill
    2. Average age is 28.78 years
    3. As there is not much difference in mean and median, the skewness in data is minimal

**B. INCOME:**

    1. Customers with income range of USD 29,500 to USD 104,500 are using treadmill
    2. Considering the difference between mean and median & mean being greater than median, the data is right skewed
    3. Standard deviation is very high

**C. MILES:**

    1. Customers are expected to run between 21 to 360 miles per week
    2. Considering the difference between mean and median & mean being greater than median, the data is right skewed
    3. Standard deviation is very high
"""
"""
#### Count based on model
"""
mydata.Product.value_counts()
"""
**Observations:** 

1. TM195 is the most sold model
2. TM798 is the least sold model
"""
"""
#### Count based on Gender
"""
mydata.Gender.value_counts()
"""
**Observations:** 
1. Male Customers are buying more treadmills compared to Female Customers
"""
"""
#### Count based on Marital Status
"""
mydata.MaritalStatus.value_counts()   
"""
**Observations:**  
1. Partnered Customers are buying more treadmills compared to Single Customers
"""
"""
#### Understanding data for Product Code TM195
"""
mydata[mydata['Product'] == 'TM195'].describe().T
"""
**Observations:**

1. A total of 80 customers purchased TM195 model 
2. Average age of customer is 28.5 (Median: 26) (Range: 18 - 50)
3. Data is right skewed.
4. Average number of years of Education for customers is 15 (Median: 16)
3. Customer wants to use the treadmill at least 3 times per week
4. Customers are expected to run is 82.78 miles per week (Median: 85)
5. Average income and median is approximately USD 46,000 
"""
"""
#### Understanding data for Product Code TM498
"""
mydata[mydata['Product'] == 'TM498'].describe().T
"""
**Observations:**

1. A total of 60 customers purchased TM498 model
2. Average age of customer is 28.9 (Median: 26) (Range: 19-48)
3. Data is right skewed.
4. Average number of years of Education for customers is 15 (Median: 16)
5. Customer wants use the treadmill at least 3 times per week
6. Customers are expected to run is 60 miles per week (Median: 85)
7. Average income is USD 46,000 (Median: USD 49,459)
"""
"""
#### Understanding data for Product Code TM798
"""
mydata[mydata['Product'] == 'TM798'].describe().T
"""
**Observations:**

1. A total of 40 customers purchased TM798 model
2. Average age of customer is 29 (Median: 27) (Range: 22-48)
3. Average number of years of Education for customers is 17 (Median: 18)
4. Customer wants to use the treadmill at least 4-5 times per week
5. Customers are expected to run are 166 miles per week (Median: 160)
6. Average income is USD 75,000 (Median: USD 76,000)
"""
"""
## Univeriate Analysis:
"""
"""
### Analysis Based on Age
"""
# Historam for age
plt.hist(mydata.Age, edgecolor = 'white')
plt.title("Histogram view of Age")
plt.show()
# Distribute data in Age groups
bins = [20,25,30,35,40,45,50]
plt.hist(mydata.Age,bins,edgecolor = 'white')
plt.title("Categorical histogram of Age")
plt.show()
# Distribute data in Age groups
bins = [18,20,22,24,26,28,30,32,34]
plt.hist(mydata.Age,bins,edgecolor = 'white')
plt.title("Categorical histogram of Age")
plt.show()
"""
**Observations:**

1. Most customers are in the age range of 22 - 32
2. Further classification reveals that most customers are of ages between 24 and 26 years, followed by customers from age group 22 and 24 years
"""
"""
### Analysis based on Income
"""
# Visualisation of income range
sns.distplot(mydata.Income)
plt.title("Distribution Plot of Income")
plt.show()
# boxplot view of income
sns.boxplot(mydata.Income)
plt.title("Box plot Plot of Income")
plt.show()
"""
**Observations:**

1. There are two peaks shown by the income range of people
2. Data is right skewed and shows outliers on the right
3. Most Customers fall in range of USD 45,000 - USD 60,000
4. Outliers are observed above USD 85,000
"""
"""
### Analysis based on Gender
"""
# Number of records per gender and product model
sns.countplot(mydata.Gender, hue=mydata.Product)
plt.title('Gender based distribution')
plt.show()
# Number of records per model and per gender
sns.countplot('Product', hue='Gender',data=mydata)
plt.title('Gender based distribution')
plt.show()
"""
**Observations:**

1. Number of male customers purchasing treadmill is more than Female Customers
2. TM798 is the least popular model of treadmill in Female Customers
3. TM195 is equally preferred model of treadmill in both male and Female Customers
"""
"""
### Analysis based on Marital Status
"""
# Number of records per model and per Marital Status
sns.countplot(mydata.Product, hue=mydata.MaritalStatus)
plt.title('Marital Status based distribution')
plt.show()
# Number of records per model and per Marital Status
sns.countplot(mydata.MaritalStatus, hue=mydata.Product)
plt.title('Marital Status based distribution')
plt.show()
"""
**Observations:**

1. Partnered Customers have purchased treadmill more than Single Customers
2. TM195 model is popular in both Marital Statuses

"""
"""
### Analysis based on Usage
"""
# Number of records based on usage per week
sns.countplot(mydata.Usage)
plt.title('Count based on Usage')
plt.show()
# Number of records per model and for number of times of Usage
sns.countplot(mydata.Product, hue=mydata.Usage)
plt.title('Usage based distribution')
plt.show()
# Number of records per model and per Usage
sns.countplot(mydata.Usage, hue=mydata.Product)
plt.title('Usage based distribution')
plt.show()
"""
**Observations:**

1. Most customers use Treadmill at least 3 times per week
2. TM195 is most popular amongst active customers
3. Few customers using TM798 Model use the treadmill for 7 times in a week
"""
"""
### Analysis based on Fitness Level
"""
# Number of records per Fitness
sns.countplot(mydata.Fitness)
plt.title('Count based on Self Acclaimed Fitness Levels')
plt.show()
# Number of records per model and for fitness rating
sns.countplot(mydata.Product, hue=mydata.Fitness)
plt.title('Distribution based on Fitness Levels')
plt.show()
# Number of records per model and for fitness rating
sns.countplot(mydata.Fitness, hue=mydata.Product)
plt.title('Distribution based on Fitness Levels')
plt.show()
"""
**Observations:**

1. Most customers have rated themselves at Level 3 of Fitness levels
2. TM195 is most popular amongst customers at Level 3
3. Almost all Customers at Fitness Level 5 use TM798 model
"""
"""
### Analysis based on Education
"""
# Distribution based on number of years of education
sns.countplot(mydata.Education)
plt.title("Count based on number of years of Education")
plt.show()
# Number of records per model for customer segments based on the number of years of education
sns.countplot(mydata.Education, hue=mydata.Product)
plt.title('Distribution based on Education')
plt.show()
# Number of records per model for customer segments based on the number of years of education
plt.figure(figsize=(10,5))
sns.countplot(mydata.Product, hue=mydata.Education)
plt.title('Distribution based on Education')
plt.show()
"""
**Observations:**

1. Most Customers using treadmill have 16 to 18 years of Education
2. Customers with more than 20 years of education have only purchased TM798 Model
3. TM798 is most preferred by the customer with 18 years of education
"""
"""
### Analysis based on Miles planned per week
"""
# Distribution plot of Miles with RUG and KDE
sns.distplot(mydata.Miles, rug=True)
plt.title('Count based on Miles')
plt.show()
# Boxplot view of data based on miles
sns.boxplot(mydata.Miles)
plt.title("Boxplot of Miles")
plt.show()
"""
**Observations:**

1. Outliers are seen on the higher values 
2. Customers are planning to run more than 180 miles per week


"""
# List the data where miles are greater than 180
mydata[mydata['Miles'] > 180]
"""
## Bivariate Analysis:
"""
"""
#### Average age for each model
"""
mydata.groupby('Product')['Age'].mean()
"""
#### Average Income for each model
"""
mydata.groupby('Product')['Income'].mean()
"""
#### Average miles per model
"""
mydata.groupby('Product')['Miles'].mean()
"""
#### Average of number of years of education for each model
"""
mydata.groupby('Product')['Education'].mean()
"""
### Analysis of Miles based on Age
"""
sns.jointplot(x = 'Age' , y = 'Miles', data = mydata)
plt.show()
"""
**Observations:**

There is no definite correlation observed between Age and Miles
"""
"""
### Analysis of Income based on Age
"""
sns.jointplot(x = 'Age' , y = 'Income', data = mydata, color='red', kind ='hex')
plt.show()
"""
**Observations:**

Income increases with the age, depicting positive correlation.
"""
"""
### Analysis of Miles based on Income
"""
sns.jointplot(x = 'Income' , y = 'Miles', data = mydata, color='orange', kind ='hex')
plt.show()
"""
**Observations:**

With increase in Customer Income a slight increase is observed in Miles
"""
"""
### Analysis of Income based on Gender
"""
sns.catplot(x = 'Gender' , y = 'Income', data = mydata)
plt.show()
"""
**Observations:**

Male Customers have higher income range, when compared to Female Customers
"""
"""
### Analysis of Miles based on Gender
"""
sns.catplot(x = 'Gender' , y = 'Miles', data = mydata, kind = 'violin')
plt.show()
"""
**Observations:**

Male Customers plan to run more miles, when compared to Female Customers
"""
"""
### Analysis of Usage based on Gender
"""
sns.catplot(x = 'Gender' , y = 'Usage', data = mydata, kind = 'bar')
plt.show()
"""
Observations:

Male Customers show higher usage per week, when compared to Female Customers
"""
"""
### Analysis of Income based on Marital Status
"""
sns.catplot(x = 'MaritalStatus' , y = 'Income', data = mydata, kind = 'box')
plt.show()
"""
Observations:

Partnered Customers have higher income range, when compared to Single Customers
"""
"""
### Analysis of Miles based on Marital Status
"""
sns.catplot(x = 'MaritalStatus' , y = 'Miles', data = mydata, kind = 'swarm')
plt.show()
"""
Observations:

Partnered Customers plan to run more miles, when compared to Single Customers
"""
"""
## Multivariate Analysis:
"""
"""
### Multicolumn catplot of Marital Status showing Gender based data compared to Income
"""
sns.catplot( x = "Gender", y = 'Income', hue = 'Product', col = 'MaritalStatus',data = mydata, kind = 'bar');
"""
**Observations:**

1. TM798 leads all charts across Customer Segments
2. Single Female Customers have purchased more of TM195 and TM498 models compared to Single Male Customers
3. Single Male Customers are more than Single Female Customers 
4. Partnered Female Customers are more than Partnered Male Customers
"""
"""
### Pointplot showing sales based on Education and Income
"""
sns.pointplot(x=mydata["Education"],y=mydata["Income"],hue=mydata['Product']) 
plt.show()
"""
**Observation:-**

   1. Customers with higher education has higher income range
   2. TM798 has higher income and higher education
"""
"""
### Correlation between Numerical columns of dataset
"""
# Correlation of numerical values in dataset
mydata.corr()
# Heatmap for the correlation of numerical values in dataset
sns.heatmap(mydata.corr(), annot=True, vmin=-1, vmax = 1) 
plt.show()
"""
**Observations:**

1. Miles and Usage show high correlation
2. Fitness and Miles show high correlation
3. Education and Income show notable correlation
4. Usage and Fitness show notable correlation
5. Income and Usage show little correlation
"""
"""
#### Pairplot of all numerical values with clasification of Product
"""
sns.pairplot(mydata, hue='Product')
plt.show()
"""
#### Pairplot of all numerical values using KDE
"""
sns.pairplot(mydata, kind='kde')
plt.show()
"""
## Conclusion (Important Observations):

1. TM195 is most sold model, accounting for 44.44% of total sales.
2. 57.78% of Customers are Male Customers, which is more than the Female Customers.
3. Partnered customers account for 59.44% of sales.
4. Most customers are between 22 to 26 years of age.
5. TM798 is most preferred by customers with higher income range.
"""
"""
## Recommendations:

1. TM195 and TM498 are popular with customers in USD 45,000 and USD 60,0000 income range and can be promoted as affordable models for these income groups
2. TM798 should be branded as Premium Model and marketed among high income groups and specific customer categories. Promotional programs can be run for upgrades from other models.
3. Rewards programs can be launched to promote per week of usage. Gamification based on points can also be introduced, with weekly leader boards.
4. Special promotions to be run to target Female Customers, for instance:
    1. Discounts on Women's Day and similar celebrated ocassions
    2. Purchase offers using Credit Card or Bank Reward points
    3. Free additional gifts and hampers from partners
5. Market research can be conducted to check the feasibility of attracting customers outside the age range of 18-35.
"""
"""
Kshitij
"""