Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions Marketing-Campaign/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
sensors/
# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
artifacts/
logs/
3 changes: 3 additions & 0 deletions Marketing-Campaign/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
Binary file added Marketing-Campaign/Project Pipeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions Marketing-Campaign/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Customer Personality Analysis

Customer Personality Analysis is a detailed analysis of a company's ideal customers. It helps a business to better understand its customers and makes it easier for them to modify products according to the specific needs, behaviors and concerns of different types of customers.

Customer personality analysis helps a business to modify its product based on its target customers from different types of customer segments

**For example**, instead of spending money to market a new product to every customer in the company's database, a company can analyze which customer segment is most likely to buy the product and then market the product only on that particular segment.

## Objectives

1. What people say about your product: what gives customers attitude towards the product
2. What people do: which reveals what people are doing rather than what they are saying about your product.

## How to Run

*Step 1 - Copying repo in local machine*
```bash
git clone https://github.com/DSCVITBHOPAL/ML-Reserve.git
```
*Step 2 - Navigate inside the Customer-Personality-Analysis directory.*

*Step 3 - Create a conda environment*
```bash
conda create -p env python==3.7.6 -y
```
<p align="center">or</p>

```bash
conda create --prefix ./env python=3.7 -y
```
*Step 4 - Activate the conda environment*
```bash
conda activate env/
```
<p align="center">or</p>

```bash
source activate ./env
```
*Step 5 - Installing dependencies*
```bash
pip install -r requirements.txt
```

*Step 6 - Run your app.py*
```bash
python app.py
```
65 changes: 65 additions & 0 deletions Marketing-Campaign/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import os
import sys
import pickle
from flask import Flask, render_template, request
import numpy as np
import pandas as pd
from customer_personality.logger.log import logging
from customer_personality.exception.exception_handler import AppException
from customer_personality.config.configuration import AppConfiguration
from customer_personality.pipeline.training_pipeline import TrainingPipeline

app = Flask(__name__) # initializing a flask app

@app.route('/',methods=['GET']) # route to display the home page
def homePage():
try:
return render_template("index.html")
except Exception as e:
raise AppException(e, sys) from e



@app.route('/train',methods=['POST','GET'])
def train():
if request.method == 'POST':
try:
obj = TrainingPipeline()
obj.start_training_pipeline()
logging.info("Training Completed!")
return render_template("index.html")

except Exception as e:
raise AppException(e, sys) from e



@app.route('/predict',methods=['POST','GET']) # route to show the predictions in a web UI
def predict():
if request.method == 'POST':
try:
# reading the inputs given by the user
Income =float(request.form['Income'])
Recency =int(request.form['Recency'])
Age =int(request.form['Age'])
TotalSpendings =int(request.form['TotalSpendings'])
Children =int(request.form['Children'])
MonthEnrollement =int(request.form['MonthEnrollement'])

data = [Income,Recency,Age,TotalSpendings,Children,MonthEnrollement]
model = pickle.load(open(AppConfiguration().get_prediction_config().trained_model_path,'rb'))
output = model.predict([data])[0]
print(output)

return render_template('results.html', prediction = str(output))

except Exception as e:
raise AppException(e, sys) from e

else:
return render_template('index.html')



if __name__ == "__main__":
app.run(host="127.0.0.1", port=5003,debug=True)
21 changes: 21 additions & 0 deletions Marketing-Campaign/config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
artifacts_config:
artifacts_dir: artifacts

data_ingestion_config:
dataset_download_url: https://publicdatasetvaasu.s3.us-east-2.amazonaws.com/dataset.zip
dataset_dir: dataset
ingested_dir: ingested_data
raw_data_dir: raw_data


data_validation_config:
clean_data_dir: clean_data
serialized_objects_dir: serialized_objects
marketing_campaign_csv_file: marketing_campaign.csv

data_transformation_config:
transformed_data_dir: transformed_data

model_trainer_config:
trained_model_dir: trained_model
trained_model_name: model.pkl
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import os
import sys
from six.moves import urllib
import zipfile
from customer_personality.logger.log import logging
from customer_personality.exception.exception_handler import AppException
from customer_personality.config.configuration import AppConfiguration



class DataIngestion:

def __init__(self, app_config = AppConfiguration()):
"""
DataIngestion Intialization
data_ingestion_config: DataIngestionConfig
"""
try:
logging.info(f"{'='*20}Data Ingestion log started.{'='*20} ")
self.data_ingestion_config= app_config.get_data_ingestion_config()
except Exception as e:
raise AppException(e, sys) from e


def download_data(self):
"""
Fetch the data from the url

"""
try:
dataset_url = self.data_ingestion_config.dataset_download_url
zip_download_dir = self.data_ingestion_config.raw_data_dir
os.makedirs(zip_download_dir, exist_ok=True)
data_file_name = os.path.basename(dataset_url)
zip_file_path = os.path.join(zip_download_dir, data_file_name)
logging.info(f"Downloading data from {dataset_url} into file {zip_file_path}")
urllib.request.urlretrieve(dataset_url,zip_file_path)
logging.info(f"Downloaded data from {dataset_url} into file {zip_file_path}")
return zip_file_path

except Exception as e:
raise AppException(e, sys) from e


def extract_zip_file(self,zip_file_path: str):
"""
zip_file_path: str
Extracts the zip file into the data directory
Function returns None
"""
try:
ingested_dir = self.data_ingestion_config.ingested_dir
os.makedirs(ingested_dir, exist_ok=True)
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
zip_ref.extractall(ingested_dir)
logging.info(f"Extracting zip file: {zip_file_path} into dir: {ingested_dir}")
except Exception as e:
raise AppException(e,sys) from e


def initiate_data_ingestion(self):
try:
zip_file_path = self.download_data()
self.extract_zip_file(zip_file_path=zip_file_path)
logging.info(f"{'='*20}Data Ingestion log completed.{'='*20} \n\n")
except Exception as e:
raise AppException(e, sys) from e

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os
import sys
import pandas as pd
from customer_personality.logger.log import logging
from customer_personality.exception.exception_handler import AppException
from customer_personality.config.configuration import AppConfiguration



class DataTransformation:
def __init__(self, app_config = AppConfiguration()):
try:
self.data_transformation_config = app_config.get_data_transformation_config()
except Exception as e:
raise AppException(e, sys) from e



def get_data_transformer(self):
try:
df = pd.read_csv(self.data_transformation_config.clean_data_file_path)
final_df = df.drop(
[
'ID', 'Year_Birth','Education','Marital_Status', 'Kidhome',
'Teenhome', 'Dt_Customer', 'MntWines', 'MntFruits', 'MntMeatProducts',
'MntFishProducts', 'MntSweetProducts','MntGoldProds','NumDealsPurchases',
'NumWebPurchases', 'NumCatalogPurchases', 'NumStorePurchases','NumWebVisitsMonth',
'AcceptedCmp3','AcceptedCmp4', 'AcceptedCmp5', 'AcceptedCmp1',
'AcceptedCmp2', 'Complain', 'Z_CostContact', 'Z_Revenue', 'Response','AgeGroup'
],

axis = 1
)

#saving personality data
os.makedirs(self.data_transformation_config.transformed_data_dir, exist_ok=True)
final_df.to_csv(os.path.join(os.path.join(self.data_transformation_config.transformed_data_dir),"transformed_data.csv"), index = False)
logging.info(f"Saved personality data to {self.data_transformation_config.transformed_data_dir}")


except Exception as e:
raise AppException(e, sys) from e


def initiate_data_transformation(self):
try:
logging.info(f"{'='*20}Data Transformation log started.{'='*20} ")
self.get_data_transformer()
logging.info(f"{'='*20}Data Transformation log completed.{'='*20} \n\n")
except Exception as e:
raise AppException(e, sys) from e
Loading