exam-sub 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/div.txt +116 -1
- package/package.json +1 -1
package/data/div.txt
CHANGED
|
@@ -147,4 +147,119 @@ CREATE | createCollection(), insertOne(), insertMany()
|
|
|
147
147
|
READ | find()
|
|
148
148
|
UPDATE | updateOne(), updateMany()
|
|
149
149
|
DELETE | deleteOne(), deleteMany()
|
|
150
|
-
--------------------------------------------------------------------------------
|
|
150
|
+
--------------------------------------------------------------------------------
|
|
151
|
+
|
|
152
|
+
================================================================================
|
|
153
|
+
THREADORA BOUTIQUE DATA ANALYSIS & MACHINE LEARNING PIPELINE
|
|
154
|
+
================================================================================
|
|
155
|
+
|
|
156
|
+
AIM:
|
|
157
|
+
Perform data acquisition, preprocessing, normalization, exploratory data analysis,
|
|
158
|
+
visualization, and build both Linear and Logistic Regression models on the
|
|
159
|
+
Threadora Boutique dataset.
|
|
160
|
+
|
|
161
|
+
PYTHON PROGRAM:
|
|
162
|
+
--------------------------------------------------------------------------------
|
|
163
|
+
import pandas as pd
|
|
164
|
+
import numpy as np
|
|
165
|
+
import matplotlib.pyplot as plt
|
|
166
|
+
from sklearn.model_selection import train_test_split
|
|
167
|
+
from sklearn.linear_model import LinearRegression, LogisticRegression
|
|
168
|
+
from sklearn.preprocessing import MinMaxScaler
|
|
169
|
+
from sklearn.metrics import (
|
|
170
|
+
r2_score,
|
|
171
|
+
mean_absolute_error,
|
|
172
|
+
mean_squared_error,
|
|
173
|
+
accuracy_score,
|
|
174
|
+
confusion_matrix,
|
|
175
|
+
classification_report
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
# 1. Data Acquisition
|
|
179
|
+
df = pd.read_csv("threadora_boutique_data.csv")
|
|
180
|
+
print("Shape:", df.shape)
|
|
181
|
+
print("Missing Values:\n", df.isnull().sum())
|
|
182
|
+
|
|
183
|
+
# 2. Data Pre-processing
|
|
184
|
+
num_cols = ["Footfall", "Sales", "Ad_Spend", "Insta_Mentions", "Whatsapp_Inquiries"]
|
|
185
|
+
for col in num_cols:
|
|
186
|
+
df[col] = df[col].fillna(df[col].median())
|
|
187
|
+
|
|
188
|
+
df["Deal_Offered"] = df["Deal_Offered"].fillna(df["Deal_Offered"].mode()[0])
|
|
189
|
+
df["Date"] = pd.to_datetime(df["Date"])
|
|
190
|
+
df["Deal_Encoded"] = (df["Deal_Offered"].str.lower() == "yes").astype(int)
|
|
191
|
+
|
|
192
|
+
# 3. Data Transformation - Min-Max Normalization
|
|
193
|
+
scaler = MinMaxScaler()
|
|
194
|
+
normalized = pd.DataFrame(scaler.fit_transform(df[num_cols]), columns=num_cols)
|
|
195
|
+
print("Normalized Data:\n", normalized.head())
|
|
196
|
+
|
|
197
|
+
# 4. EDA - Summary Statistics & Correlation Analysis
|
|
198
|
+
print("Summary Statistics:\n", df[num_cols].describe())
|
|
199
|
+
|
|
200
|
+
corr_cols = [
|
|
201
|
+
"Sales",
|
|
202
|
+
"Footfall",
|
|
203
|
+
"Ad_Spend",
|
|
204
|
+
"Insta_Mentions",
|
|
205
|
+
"Whatsapp_Inquiries",
|
|
206
|
+
"Deal_Encoded"
|
|
207
|
+
]
|
|
208
|
+
print("Correlation with Sales:\n", df[corr_cols].corr()["Sales"].sort_values(ascending=False))
|
|
209
|
+
|
|
210
|
+
# 5. Data Visualization
|
|
211
|
+
plt.figure(figsize=(10, 5))
|
|
212
|
+
plt.plot(df["Date"], df["Sales"], label="Sales")
|
|
213
|
+
plt.plot(df["Date"], df["Footfall"], label="Footfall")
|
|
214
|
+
plt.title("Sales and Footfall Over Time")
|
|
215
|
+
plt.xlabel("Date")
|
|
216
|
+
plt.ylabel("Value")
|
|
217
|
+
plt.xticks(rotation=45)
|
|
218
|
+
plt.legend()
|
|
219
|
+
plt.tight_layout()
|
|
220
|
+
plt.show()
|
|
221
|
+
|
|
222
|
+
# 6. Linear Regression (Sales Prediction)
|
|
223
|
+
features = ["Ad_Spend", "Footfall", "Whatsapp_Inquiries", "Insta_Mentions"]
|
|
224
|
+
X = df[features]
|
|
225
|
+
y = df["Sales"]
|
|
226
|
+
|
|
227
|
+
X_train, X_test, y_train, y_test = train_test_split(
|
|
228
|
+
X, y, test_size=0.20, random_state=42
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
linear_model = LinearRegression()
|
|
232
|
+
linear_model.fit(X_train, y_train)
|
|
233
|
+
|
|
234
|
+
y_pred = linear_model.predict(X_test)
|
|
235
|
+
|
|
236
|
+
print("Linear Regression:")
|
|
237
|
+
print("R2 =", r2_score(y_test, y_pred))
|
|
238
|
+
print("MAE =", mean_absolute_error(y_test, y_pred))
|
|
239
|
+
print("RMSE =", mean_squared_error(y_test, y_pred) ** 0.5)
|
|
240
|
+
print("Coefficients:")
|
|
241
|
+
for feature, coef in zip(features, linear_model.coef_):
|
|
242
|
+
print(feature, "=", coef)
|
|
243
|
+
|
|
244
|
+
# 7. Logistic Regression (High Sales Day Classification)
|
|
245
|
+
df["High_Sales_Day"] = (df["Sales"] > 5000).astype(int)
|
|
246
|
+
|
|
247
|
+
X_cls = df[features]
|
|
248
|
+
y_cls = df["High_Sales_Day"]
|
|
249
|
+
|
|
250
|
+
Xc_train, Xc_test, yc_train, yc_test = train_test_split(
|
|
251
|
+
X_cls, y_cls, test_size=0.20, random_state=42, stratify=y_cls
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
log_model = LogisticRegression(max_iter=1000, class_weight="balanced")
|
|
255
|
+
log_model.fit(Xc_train, yc_train)
|
|
256
|
+
|
|
257
|
+
predictions = log_model.predict(Xc_test)
|
|
258
|
+
|
|
259
|
+
print("Logistic Regression:")
|
|
260
|
+
print("Accuracy =", accuracy_score(yc_test, predictions))
|
|
261
|
+
print("Confusion Matrix:\n", confusion_matrix(yc_test, predictions))
|
|
262
|
+
print("Classification Report:\n", classification_report(yc_test, predictions))
|
|
263
|
+
--------------------------------------------------------------------------------
|
|
264
|
+
|
|
265
|
+
|