exam-sub 1.0.0 → 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 CHANGED
@@ -1,83 +1,265 @@
1
- MongoDB CRUD Operations – CollegeDB
2
- Complete practical code for Questions 1–3 using one MongoDB database with separate collections: employees,
3
- students, and books.
4
- Complete Code
5
- // Create / Select Database
1
+ ================================================================================
2
+ MONGODB CRUD OPERATIONS – COLLEGE DB
3
+ ================================================================================
4
+
5
+ AIM:
6
+ To implement CRUD (Create, Read, Update, Delete) operations using MongoDB
7
+ queries across three collections: employees, students, and books inside a single
8
+ database named collegeDB.
9
+
10
+
11
+ ================================================================================
12
+ OPTIONAL: RESET / CLEAN RUN COMMANDS
13
+ ================================================================================
14
+
15
+ NOTE:
16
+ If you run the practical multiple times, existing collections and data may cause
17
+ duplicate records or collection-exists errors. Use the following commands first
18
+ when you want a clean start.
19
+
20
+ JAVASCRIPT / MONGODB SHELL COMMANDS:
21
+ --------------------------------------------------------------------------------
22
+ // Select Database
6
23
  use collegeDB
7
- // ==========================================
8
- // Q1: EMPLOYEES
9
- // ==========================================
10
- // Create Collection
24
+
25
+ // Drop Existing Collections
26
+ db.employees.drop()
27
+ db.students.drop()
28
+ db.books.drop()
29
+ --------------------------------------------------------------------------------
30
+
31
+
32
+ ================================================================================
33
+ Q1: EMPLOYEES COLLECTION
34
+ ================================================================================
35
+
36
+ JAVASCRIPT / MONGODB SHELL COMMANDS:
37
+ --------------------------------------------------------------------------------
38
+ // Select Database
39
+ use collegeDB
40
+
41
+ // Step 1: Create Collection
11
42
  db.createCollection("employees")
12
- // Insert Values
43
+
44
+ // Step 2: Insert Multiple Documents
13
45
  db.employees.insertMany([
14
- {name:"Alice", position:"Manager", salary:70000},
15
- {name:"Bob", position:"Developer", salary:55000},
16
- {name:"Charlie", position:"HR", salary:45000}
46
+ { name: "Alice", position: "Manager", salary: 70000 },
47
+ { name: "Bob", position: "Developer", salary: 55000 },
48
+ { name: "Charlie", position: "HR", salary: 45000 }
17
49
  ])
18
- // Read - Salary greater than 50000
19
- db.employees.find({salary:{$gt:50000}})
20
- // Update - Increase Developer salary by 10%
50
+
51
+ // Step 3: Read - Retrieve employees with salary greater than 50,000
52
+ db.employees.find({ salary: { $gt: 50000 } })
53
+
54
+ // Step 4: Update - Increase Developer salary by 10%
21
55
  db.employees.updateMany(
22
- {position:"Developer"},
23
- {$mul:{salary:1.10}}
56
+ { position: "Developer" },
57
+ { $mul: { salary: 1.10 } }
24
58
  )
25
- // Delete - Remove Charlie
26
- db.employees.deleteOne({name:"Charlie"})
27
- // ==========================================
28
- // Q2: STUDENTS
29
- // ==========================================
30
- // Create Collection
59
+
60
+ // Step 5: Delete - Remove employee named Charlie
61
+ db.employees.deleteOne({ name: "Charlie" })
62
+ --------------------------------------------------------------------------------
63
+
64
+
65
+ ================================================================================
66
+ Q2: STUDENTS COLLECTION
67
+ ================================================================================
68
+
69
+ JAVASCRIPT / MONGODB SHELL COMMANDS:
70
+ --------------------------------------------------------------------------------
71
+ // Select Database
72
+ use collegeDB
73
+
74
+ // Step 1: Create Collection
31
75
  db.createCollection("students")
32
- // Insert Values
76
+
77
+ // Step 2: Insert Single Document
33
78
  db.students.insertOne({
34
- name:"John Doe",
35
- age:22,
36
- course:"Computer Science"
79
+ name: "John Doe",
80
+ age: 22,
81
+ course: "Computer Science"
37
82
  })
38
- // Read - Age greater than 20
39
- db.students.find({age:{$gt:20}})
40
- // Update - Change course
83
+
84
+ // Step 3: Read - Retrieve students with age greater than 20
85
+ db.students.find({ age: { $gt: 20 } })
86
+
87
+ // Step 4: Update - Change course to Data Science
41
88
  db.students.updateOne(
42
- {name:"John Doe"},
43
- {$set:{course:"Data Science"}}
89
+ { name: "John Doe" },
90
+ { $set: { course: "Data Science" } }
44
91
  )
45
- // Delete - Age less than 21
46
- db.students.deleteMany({age:{$lt:21}})
47
- // ==========================================
48
- // Q3: BOOKS
49
- // ==========================================
50
- // Create Collection
92
+
93
+ // Step 5: Delete - Remove students with age less than 21
94
+ db.students.deleteMany({ age: { $lt: 21 } })
95
+ --------------------------------------------------------------------------------
96
+
97
+
98
+ ================================================================================
99
+ Q3: BOOKS COLLECTION
100
+ ================================================================================
101
+
102
+ JAVASCRIPT / MONGODB SHELL COMMANDS:
103
+ --------------------------------------------------------------------------------
104
+ // Select Database
105
+ use collegeDB
106
+
107
+ // Step 1: Create Collection
51
108
  db.createCollection("books")
52
- // Insert Values
109
+
110
+ // Step 2: Insert Single Document
53
111
  db.books.insertOne({
54
- title:"The Alchemist",
55
- author:"Paulo Coelho",
56
- publishedYear:1988,
57
- copiesSold:65000000
112
+ title: "The Alchemist",
113
+ author: "Paulo Coelho",
114
+ publishedYear: 1988,
115
+ copiesSold: 65000000
58
116
  })
59
- // Read - Books published before 2000
60
- db.books.find({publishedYear:{$lt:2000}})
61
- // Update - Add rating
117
+
118
+ // Step 3: Read - Retrieve books published before the year 2000
119
+ db.books.find({ publishedYear: { $lt: 2000 } })
120
+
121
+ // Step 4: Update - Add rating field to 'The Alchemist'
62
122
  db.books.updateOne(
63
- {title:"The Alchemist"},
64
- {$set:{rating:4.8}}
123
+ { title: "The Alchemist" },
124
+ { $set: { rating: 4.8 } }
65
125
  )
66
- // Delete - Books with copies sold less than 1 million
67
- db.books.deleteMany({copiesSold:{$lt:1000000}})
68
- Fresh Run / Reset Database Collections
69
- If you run the practical multiple times, existing collections and data may cause duplicate records or collection-exists
70
- errors. Use the following commands first when you want a clean run.
71
- use collegeDB
72
- db.employees.drop()
73
- db.students.drop()
74
- db.books.drop()
75
- Important MongoDB Note
76
- MongoDB does not use tables like MySQL. MongoDB stores data in collections. For this practical, employees,
77
- students, and books are collections inside the same collegeDB database.
78
- CRUD Summary
79
- Create: createCollection(), insertOne(), insertMany()
80
- Read: find()
81
- Update: updateOne(), updateMany()
82
- Delete: deleteOne(), deleteMany()
83
-  
126
+
127
+ // Step 5: Delete - Remove books with copies sold less than 1 million
128
+ db.books.deleteMany({ copiesSold: { $lt: 1000000 } })
129
+ --------------------------------------------------------------------------------
130
+
131
+
132
+ ================================================================================
133
+ IMPORTANT MONGODB CONCEPTS & SUMMARY
134
+ ================================================================================
135
+
136
+ DATABASE CONCEPT:
137
+ MongoDB does not use tables like relational databases (e.g., MySQL). Instead,
138
+ it stores JSON-like documents inside collections. In this practical,
139
+ 'employees', 'students', and 'books' are separate collections stored inside
140
+ the single 'collegeDB' database.
141
+
142
+ CRUD METHOD SUMMARY:
143
+ --------------------------------------------------------------------------------
144
+ Operation | MongoDB Functions / Methods
145
+ --------------------------------------------------------------------------------
146
+ CREATE | createCollection(), insertOne(), insertMany()
147
+ READ | find()
148
+ UPDATE | updateOne(), updateMany()
149
+ DELETE | deleteOne(), deleteMany()
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
+