Question 1: Explain the concept of Data Integration and Provide example.
ببساطة زي فكرة التطبيقات اللي بتجمع اشتراكاتك في Netflix و YouTube وكل حاجة في شاشة واحدة.
يعني: عندك بيانات في أماكن مختلفة بـأشكال مختلفة → الـ Data Integration بتحول الكل لـشكل واحد موحد وتدمجهم مع بعض.
| Data | Original Format | Integrated Format |
|---|---|---|
| 🛒 Sales | SQL Database | Unified CSV |
| 👤 Customers | Excel Sheet | Unified CSV |
Question 2: Explain the concept of Data Filtering and Provide example.
زي ما بتفلتر السوشيال ميديا وبتشوف بس اللي يهمك. الـ Data Filtering يعني بتاخد من البيانات الكبيرة بس الجزء اللي مفيدك وبيخص المستخدم.
- Type: Action
- Release Year: > 2020
- Rating: > 8.0
Question 3: Using Pandas, define each of the following operations:
- Merge
- Join
Then write the appropriate Python code example for each operation.
الاستخدام: لما عندك جدولين وفيهم عمود مشترك زي "customer_id" مثلاً.
الاستخدام: لما عايز تدمج DataFrames بناءً على الـ row index.
import pandas as pd # --- 1. merge() (using column) --- df1 = pd.DataFrame({'id': [1, 2], 'name': ['Ali', 'Sara']}) df2 = pd.DataFrame({'id': [1, 2], 'grade': [90, 85]}) print("--- merge() output ---") print(pd.merge(df1, df2, on='id')) # --- 2. join() (using index) --- df3 = pd.DataFrame({'name': ['Ali', 'Sara']}, index=[1, 2]) df4 = pd.DataFrame({'grade': [90, 85]}, index=[1, 2]) print("\n--- join() output ---") print(df3.join(df4))
--- merge() output --- id name grade 0 1 Ali 90 1 2 Sara 85 --- join() output --- name grade 1 Ali 90 2 Sara 85
| Feature | merge() | join() |
|---|---|---|
| Combines on | Common column | Index |
| Similar to | SQL JOIN | Index-based join |
| Usage | More flexible | Simpler & faster with index |
Question 4: Using Pandas, define each of the following operations:
- Append
- Concat
Then write the appropriate Python code example for each operation.
تخيل عندك جدول فيه اسمين (Ali, Sara)، وعندك جدول تاني فيه اسم (Omar).
الـ
append بتاخد الجدول التاني وتحطه أسفل الأول في نفس الجدول:
import pandas as pd df1 = pd.DataFrame({ 'name': ['Ali', 'Sara'], 'grade': [90, 85] }) df2 = pd.DataFrame({ 'name': ['Omar'], 'grade': [92] }) # append: بضيف صفوف df2 على df1 result = df1.append(df2, ignore_index=True) print(result)
name grade 0 Ali 90 1 Sara 85 2 Omar 92
لو ما كتبناهاش، الأرقام (الـ Index) هتفضل زي ما هي في الجداول القديمة وهتتكرر.
name grade
0 Ali 90
1 Sara 85
0 Omar 92 ← الـ index باظ
name grade
0 Ali 90
1 Sara 85
2 Omar 92 ← تسلسل نظيف
- axis=0 → رأسي (بيضيف صفوف / rows)
- axis=1 → أفقي (بيضيف أعمدة / columns)
import pandas as pd df1 = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) df2 = pd.DataFrame({'A': [5, 6], 'B': [7, 8]}) # concat رأسي (بيضيف rows) result_rows = pd.concat([df1, df2], axis=0, ignore_index=True) # concat أفقي (بيضيف columns) result_cols = pd.concat([df1, df2], axis=1) print("Rows:\n", result_rows) print("Cols:\n", result_cols)
Rows: A B 0 1 3 1 2 4 2 5 7 3 6 8 Cols: A B A B 0 1 3 5 7 1 2 4 6 8
| الفرق | append() | concat() |
|---|---|---|
| بيضيف | rows فقط | rows أو columns |
| المحور | axis=0 دايماً | axis=0 أو axis=1 |
| الحالة | قديم (deprecated) | الأحدث والأقوى |
Question 5: Guess the output of the following Python code.
import pandas as pd df1 = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) df2 = pd.DataFrame({'A': [5, 6], 'C': [7, 8]}) df_appended = df1.append(df2, sort=False) # sort=False to handle different columns print("Appended DataFrame:") print(df_appended)
Appended DataFrame: A B C 0 1 3.0 NaN 1 2 4.0 NaN 0 5 NaN 7.0 1 6 NaN 8.0
هنا عندنا 3 أعمدة في الإجمالي (A, B, C).
الجدول الأول (df1) مفيهوش العمود C، والجدول التاني (df2) مفيهوش العمود B.
لما نعمل
append، الـ Pandas بتحط NaN في الأماكن الناقصة.⚠️ طب هل الصح نحط NaN ولا 0؟
الصح هو NaN طبعاً! لأن
0 ده "قيمة" حقيقية (زي إن طالب جاب صفر في الامتحان)، لكن NaN (Not a Number) معناها إن "البيانات دي مفقودة ومش موجودة أصلاً"، وده الأدق في الـ Data Analysis!🤔 ليه في أرقام طلعت Float (3.0) وأرقام طلعت Integer (1)؟
دي حتة ذكية جداً! البانداز بتعتبر الـ
NaN قيمة عشرية (Float).- العمود A مفيهوش أي NaN، ففضل زي ما هو أرقام صحيحة (1, 2, 5, 6).
- لكن الأعمدة B و C دخل فيهم NaN، فالـ Pandas حولت العمود كله تلقائياً لـ Float (زي 3.0 و 4.0) عشان تقدر تخزن الـ NaN جواهم.
ملاحظة: الـ index (0, 1) اتكرر هنا عشان مكتبناش
ignore_index=True زي ما شرحنا فوق.
Question 6: Guess the output of the following Python code.
import pandas as pd # Creating DataFrames with unequal columns df1 = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) df2 = pd.DataFrame({'A': [5, 6], 'C': [7, 8]}) # Concatenating along columns (axis=1) with unequal columns df_concatenated = pd.concat([df1, df2], axis=1, sort=False) print("Concatenated DataFrame:") print(df_concatenated)
Concatenated DataFrame: A B A C 0 1 3 5 7 1 2 4 6 8
استخدمنا
concat مع axis=1، وده معناه إنه بيلزق الجدولين أفقياً جنب بعض مش تحت بعض (بيضيف أعمدة). عشان كده أعمدة df2 اتحطت يمين df1 على طول!
import pandas as pd # DataFrame shape: rows x columns df = pd.DataFrame({ 'A': [1, 2, 3], 'B': [4, 5, 6] }) # الـ merge على عمود مشترك df2 = pd.DataFrame({'A': [1, 2], 'C': [7, 8]}) merged = pd.merge(df, df2, on='A') # Output: # A B C # 0 1 4 7 # 1 2 5 8
Question 7: Guess the output of the following Python code.
import pandas as pd # Creating DataFrames df1 = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}, index=['X', 'Y']) df2 = pd.DataFrame({'C': [5, 6], 'D': [7, 8]}, index=['X', 'Y']) # Joining based on index joined_df = df1.join(df2, how='outer') print("Joined DataFrame:") print(joined_df)
Joined DataFrame: A B C D X 1 3 5 7 Y 2 4 6 8
join() اللي بتدمج الجداول بناءً على الـ Index المشترك (اللي هو X, Y). وعملنا how='outer' يعني بناخد كل البيانات من الجدولين.لازم تعرف الـ 4 أنواع دول عشان تتوقع الـ output صح:
| النوع | how= | بياخد |
|---|---|---|
| Inner Join | inner | الـ rows المشتركة فقط |
| Left Join | left | كل rows الـ Left + المشتركة |
| Right Join | right | كل rows الـ Right + المشتركة |
| Outer Join | outer | كل rows من الاتنين + NaN للناقص |
- لو بتستخدم
pd.merge() ⬅️ الـ Default بتاعه هو inner.- لو بتستخدم
df.join() ⬅️ الـ Default بتاعه هو left.
import pandas as pd # الجداول هنا بتستخدم الـ Index للدمج df1 = pd.DataFrame({'name': ['Ali', 'Sara']}, index=[1, 2]) df2 = pd.DataFrame({'age': [20, 22]}, index=[2, 3]) # Inner - المشترك بس (index=2) inner = df1.join(df2, how='inner') # Left (وهو الـ default بتاع join) - كل اللي في df1 (index=1, 2) left = df1.join(df2, how='left') # Right - كل اللي في df2 (index=2, 3) right = df1.join(df2, how='right') # Outer - كل حاجة، والناقص بـ NaN (index=1, 2, 3) outer = df1.join(df2, how='outer')
--- Inner Join --- name age 2 Sara 20 --- Left Join --- name age 1 Ali NaN 2 Sara 20.0 --- Right Join --- name age 2 Sara 20 3 NaN 22 --- Outer Join --- name age 1 Ali NaN 2 Sara 20.0 3 NaN 22.0
- لو شفت NaN في الـ output يبقى عمل outer أو left/right join وفيه قيم ناقصة.
- أول ما تظهر الـ NaN في أي عمود أرقام، الـ Pandas بيحول كل الأرقام الصحيحة (Integer) اللي في العمود ده لـ Float (عشرية) تلقائياً عشان يقدر يخزن الـ NaN معاهم.
Question 8: Draw and explain the complete architecture of the U-Net Model.
- Contracting Path
- Expanding Path
السؤال صريح: "Draw and explain the complete architecture of the U-Net Model".
عشان تاخد الدرجة النهائية (Full Mark) لازم إجابتك يكون فيها 3 حاجات:
- الرسمة (Draw): ترسم شكل الـ U-Net (زي الرسمة اللي تحت دي بالظبط)، وتوضح إن فيه 5 مستويات للـ Filters بتبدأ من 64 وتوصل لـ 1024 تحت خالص في الـ Bottleneck.
- شرح الـ Contracting Path: تكتب إنه بيستخدم Convolution و Pooling عشان يستخرج الـ Features ويصغر أبعاد الصورة (سطرين بالظبط).
- شرح الـ Expanding Path: تكتب إنه بيستخدم Up-Convolution عشان يرجع الصورة لحجمها الأصلي، وبيستخدم الـ Skip Connections عشان يحافظ على التفاصيل (سطرين بالظبط).
- معلومة Extra للتميز: خلي بالك إن كل بلوك Conv في الرسمة هو في الحقيقة طبقتين ورا بعض (Conv ×2)، وإن الـ Skip Connections بتعمل دمج للقنوات (Concatenation) مش جمع (Addition).
- بيستخدم Convolution layers عشان يستخرج الـ features
- بيستخدم MaxPooling عشان يصغر الـ spatial dimensions (الصورة بتتصغر)
- فيه 5 blocks، في كل block بتتضاعف الـ filters: 64 → 128 → 256 → 512 → 1024
- بيستخدم Up-Convolution (Transpose Convolution) عشان يكبر الصورة تاني
- بيستخدم الـ Skip Connections عشان يجيب details دقيقة من الـ contracting path
- في الآخر بيطلع Segmentation Map
Question 9: Differentiate between:
- Descriptive Statistics
- Inferential Statistics
- Descriptive (وصفي): إنت ذقت معلقة واحدة من حلة الشوربة وقولت: "المعلقة دي طعمها مالح".. إنت كده بتوصف العينة اللي في إيدك بالظبط (Sample).
- Inferential (استنتاجي): بناءً على المعلقة دي، إنت استنتجت وقولت: "أكيد حلة الشوربة كلها مالحة".. إنت كده استنتجت وخدت قرار عن الحلة كلها (Population) من غير ما تشربها كلها!
| Descriptive Statistics | Inferential Statistics |
|---|---|
|
|
Question 10: Differentiate between the following data types with practical examples:
- Qualitative (Categorical or Nominal)
- Quantitative (Measurable or Countable)
Provide suitable examples for each type.
Qualitative = صفة/نوع → مش رقم → زي لون العين (أزرق/بني)
Quantitative = رقم/عدد → تقدر تحسبه → زي الطول والوزن
| Qualitative (Categorical/Nominal) | Quantitative (Measurable/Countable) |
|---|---|
|
|
Question 11: Listed below are the commissions earned last month by a sample of 15 brokers at Salomon Smith Barney's Oakland, California, office.
$2287 $1940 $2311 $2054 $2406 $1471 $1460
Locate the first quartile (Q1) and the third quartile (Q3) for the commissions earned.
الـ Quartiles بتقسم البيانات لـ 4 أجزاء متساوية:
- Q1 (First Quartile) = 25% من البيانات أقل منه
- Q2 (Median) = 50% (النص)
- Q3 (Third Quartile) = 75% من البيانات أقل منه
Therefore, Q1 = $1,721
Therefore, Q3 = $2,205
Q3 (Third Quartile) = $2,205
لو عدد صحيح → خد متوسط القيمة دي واللي بعدها.
1️⃣ رتّب الأرقام تصاعدياً.
2️⃣ احسب الـ (L) عشان تعرف مكان الرقم فين.
3️⃣ طلّع القيمة من المكان اللي حسبته.
⚠️ ركز جداً في قاعدة الـ (L):
- لو L طلع كسر (مثال: L = 3.2): قربه للرقم الصحيح الأكبر دايماً (Ceiling) يعني تاخد القيمة الـ 4.
- لو L طلع رقم صحيح (مثال: L = 3): بتاخد القيمة دي واللي بعدها وتجيب متوسطهم.. يعني (القيمة الـ 3 + القيمة الـ 4) ÷ 2.
Question 12: The following data represent the number of hours spent studying per week by 20 students:
6 8 10 12 14 16 18 20 22 24
Required:
- (a) Construct a frequency distribution table using 4 classes of equal width.
- (b) Calculate the frequency and relative frequency for each class.
- (c) Draw the histogram for the data.
| 5 | 7 | 9 | 11 | 13 | 15 | 17 | 19 | 21 | 23 |
| 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 |
- Class 1: 5 – 9 (5 أرقام: 5,6,7,8,9)
- Class 2: 10 – 14 (5 أرقام: 10,11,12,13,14)
- Class 3: 15 – 19 (5 أرقام: 15,16,17,18,19)
- Class 4: 20 – 24 (5 أرقام: 20,21,22,23,24)
| Class Interval | Data Values | Frequency (f) | Relative Frequency |
|---|---|---|---|
| 5 – 9 | 5, 6, 7, 8, 9 | 5 | 5/20 = 0.25 = 25% |
| 10 – 14 | 10, 11, 12, 13, 14 | 5 | 5/20 = 0.25 = 25% |
| 15 – 19 | 15, 16, 17, 18, 19 | 5 | 5/20 = 0.25 = 25% |
| 20 – 24 | 20, 21, 22, 23, 24 | 5 | 5/20 = 0.25 = 25% |
| Total | — | 20 | 1.00 = 100% |
1️⃣ الخطوات الحسابية: احسب الـ Range والـ Class Width وحدد الـ Classes زي ما عملنا.
2️⃣ الجدول: ارسم الجدول وحط فيه البيانات، الـ Frequency، والـ Relative Frequency.
3️⃣ الرسمة: ارسم الـ Histogram، وتأكد إن العمدان (Bars) متلاصقة، ومكتوب تحتها فترات الـ Classes.