-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_code.py
More file actions
161 lines (138 loc) · 4.58 KB
/
setup_code.py
File metadata and controls
161 lines (138 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
"""
Setup script for Customer Segmentation System.
This script creates the initial directory structure and files.
"""
import os
import sys
def create_project_structure():
"""
Create the initial directory structure and files for the project.
"""
# Create project directory structure
directories = [
"data/raw",
"data/processed",
"docs",
"notebooks",
"src",
"models",
"reports/figures",
]
for directory in directories:
os.makedirs(directory, exist_ok=True)
print(f"Created directory: {directory}")
# Create the directory structure for src
src_directories = [
"src/data",
"src/features",
"src/models",
"src/visualization",
"src/utils",
]
for directory in src_directories:
os.makedirs(directory, exist_ok=True)
# Create __init__.py files
with open(f"{directory}/__init__.py", "w") as f:
f.write(f"# {directory} module\n")
print(f"Created {directory}")
# Create main package __init__.py
with open("src/__init__.py", "w") as f:
f.write("# Customer Segmentation package\n")
# Create empty files
files = ["requirements.txt", "README.md", ".gitignore", "run.py"]
for file in files:
with open(file, "w") as f:
pass
print(f"Created file: {file}")
# Write requirements
with open("requirements.txt", "w") as f:
f.write(
"""
numpy==1.24.3
pandas==2.0.2
matplotlib==3.7.1
seaborn==0.12.2
plotly==5.15.0
scikit-learn==1.2.2
streamlit==1.24.0
jupyter==1.0.0
"""
)
# Create basic README
with open("README.md", "w") as f:
f.write(
"""# Customer Segmentation System
A modular, extensible customer segmentation system that analyzes customer purchasing behavior and creates actionable customer segments. Built using Python, Streamlit, and scikit-learn.
## Features
- **Data Loading & Preprocessing**: Clean and preprocess raw retail transaction data
- **Feature Engineering**: Create meaningful customer-level features
- **Customer Clustering**: Segment customers using KMeans clustering
- **Segment Interpretation**: Automatically interpret clusters and create customer personas
- **Dynamic Segmentation**: Update segments as new data becomes available
- **Interactive Visualization**: Explore segments through an intuitive Streamlit dashboard
- **Marketing Recommendations**: Get actionable marketing strategies for each segment
## Project Structure
```
.
├── data/ # Data directory
│ ├── raw/ # Raw data files
│ └── processed/ # Processed data files
├── models/ # Saved models
├── reports/ # Reports and visualizations
│ └── figures/ # Generated figures
├── src/ # Source code
│ ├── data/ # Data loading and preprocessing
│ ├── features/ # Feature engineering
│ ├── models/ # Clustering models
│ ├── visualization/ # Visualization and dashboard
│ └── utils/ # Helper utilities
├── requirements.txt # Project dependencies
├── README.md # Project documentation
└── run.py # Script to run the application
```
"""
)
# Create a basic .gitignore
with open(".gitignore", "w") as f:
f.write(
"""# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# Jupyter Notebook
.ipynb_checkpoints
# Data files - uncomment if you want to ignore data files
# data/raw/
# data/processed/
# Model files - uncomment if you want to ignore model files
# models/
# Virtual Environment
venv/
env/
ENV/
# IDE files
.idea/
.vscode/
*.swp
*.swo
"""
)
if __name__ == "__main__":
create_project_structure()