.. _module5_assignment: Module 5: Assignment Questions =============================== .. note:: These assignments integrate **NumPy**, **Pandas**, **Matplotlib**, and **Flask**. Build real-world projects that showcase your data science and web development skills! Focus on creating functional, well-styled applications with proper visualizations. ๐Ÿš€โœจ -------------- NumPy Assignments ----------------- **1. Daily Motivation Levels Tracker** ๐Ÿ“Š Create a NumPy-based motivation tracking system for a week (7 days): - Generate a random motivation array (1-10 scale) for 7 days - Calculate: average motivation, standard deviation, maximum motivation day, minimum motivation day - Create a "motivation forecast" for next week by adding random noise to this week's average - Identify "crisis days" (motivation < 4) and "peak days" (motivation > 8) - Calculate how many days you were "barely surviving" (< 5) vs "thriving" (> 7) *Hint:* Use ``np.random.randint(1, 11, 7)`` for random data. Use ``np.mean()``, ``np.std()``, ``np.max()``, ``np.argmax()`` for statistics. Boolean indexing: ``array[array < 4]``. **2. Grade Analysis System** ๐ŸŽ“ Create a grade analyzer for a class of 30 students across 5 subjects: - Generate random grades (0-100) using NumPy: ``np.random.randint(0, 101, (30, 5))`` - Calculate each student's average (use ``axis=1``) - Find top 5 students and bottom 5 students - Calculate class average for each subject (use ``axis=0``) - Identify students at risk (average < 50) - Calculate standard deviation per subject to find hardest/easiest subject - Create a "normalized" grade array (scale all grades to 0-1 range using min-max normalization) *Hint:* Use ``np.mean(array, axis=0)`` for column-wise mean. Use ``np.argsort()`` to find top/bottom students. Min-max normalization: ``(x - min) / (max - min)``. **3. Expense Tracker with Budget Analysis** ๐Ÿ’ฐ Create an expense tracking system for a month: - Generate 30 days of random expenses across 4 categories: Food, Transport, Entertainment, Others - Each category has different spending ranges (Food: 50-200, Transport: 20-100, etc.) - Calculate total spent, average daily spending, spending per category - Find the most expensive day and category - Calculate how much over/under budget (assume budget = 4000) - Create a "spending pattern" array showing percentage distribution across categories - Identify days where total spending exceeded 200 (danger zone!) *Hint:* Use ``np.random.randint()`` with different ranges for each category. Stack category arrays: ``np.column_stack()``. Use ``np.sum(axis=1)`` for daily totals. **4. Time Series Analysis: Sleep Tracker** ๐Ÿ˜ด Build a sleep pattern analyzer: - Generate 30 days of sleep data: hours slept (4-12 range, floats) - Calculate average sleep, sleep debt (assuming 8 hours needed per night) - Find longest sleep, shortest sleep, and their dates - Create a "sleep quality" array: Good (โ‰ฅ8h), Okay (6-8h), Poor (<6h) - Count number of days in each quality category - Calculate rolling 7-day average sleep (hint: use array slicing in a loop) - Identify "insomnia weeks" where average < 6 hours *Hint:* Use ``np.random.uniform(4, 12, 30)`` for float data. For rolling average: ``np.mean(array[i:i+7])`` in a loop. Use ``np.where()`` for conditional categorization. **5. Matrix Operations: Social Network** ๐ŸŒ Create a simple social network adjacency matrix: - Generate a 10x10 matrix representing friend connections (0 or 1) - Make it symmetric (if A is friend with B, B is friend with A) - Set diagonal to 0 (no self-friendship!) - Calculate: number of friends per person (row sum), most popular person, least popular person - Find mutual friends: people who have โ‰ฅ5 common friends - Create a "friend recommendation" system: suggest people who are friends-of-friends but not direct friends *Hint:* Generate with ``np.random.randint(0, 2, (10, 10))``. Make symmetric: ``matrix = (matrix + matrix.T) > 0``. Diagonal: ``np.fill_diagonal(matrix, 0)``. Matrix multiplication for friends-of-friends! -------------- Pandas Assignments ------------------ **6. Life Choices Tracker Dashboard** ๐ŸŽฏ Create a life decisions analyzer using Pandas: - Create DataFrame with columns: Date, Decision, Category, Regret_Level (1-10), Impact (Positive/Negative/Neutral), Lessons_Learned - Add at least 20 life decisions (use past month dates) - Categories: Academic, Career, Social, Health, Finance - Analyze: - Average regret level by category - Count of positive/negative/neutral impacts - Most regrettable category - Filter decisions with regret > 7 (major mistakes!) - Group by category and calculate mean regret - Find correlation between regret and impact type *Hint:* Use ``pd.DataFrame()``. ``df.groupby('Category')['Regret_Level'].mean()`` for group analysis. ``df[df['Regret_Level'] > 7]`` for filtering. **7. COVID-Style Study Hours Analysis** ๐Ÿ“š Build a study pattern analyzer: - Create DataFrame: Date, Subject, Hours_Studied, Distractions (count), Productivity (1-10), Mood (Happy/Neutral/Sad) - 30 rows of data across 5 subjects - Analysis tasks: - Total hours per subject - Average productivity by mood - Correlation between distractions and productivity - Best/worst study day (highest/lowest total hours) - Subject with highest average productivity - Create "efficiency score": Hours * Productivity / (Distractions + 1) - Filter days where productivity < 4 (crisis days!) *Hint:* Use ``pd.to_datetime()`` for date column. ``df.groupby(['Subject', 'Mood']).agg({'Hours_Studied': 'sum', 'Productivity': 'mean'})``. Use ``df.corr()`` for correlation. **8. Movie Binge Tracker** ๐ŸŽฌ Create a movie watching analysis system: - DataFrame columns: Date, Title, Genre, Duration_Minutes, Rating (1-5), Platform, Watched_With, Mood_After - Add 25+ movie entries - Analysis: - Total hours binged - Average rating by genre - Most binged genre - Platform with highest average rating - Correlation between duration and rating - Filter movies watched alone vs with friends, compare ratings - Create "binge score": (Duration/60) * Rating *Hint:* Use ``pd.cut()`` to categorize duration into Short/Medium/Long. ``df.groupby('Genre')['Rating'].agg(['mean', 'count'])``. **9. Food Delivery Analysis** ๐Ÿ• Build a food ordering pattern analyzer: - DataFrame: Date, Restaurant, Cuisine, Cost, Delivery_Time, Rating, Day_of_Week, Meal_Type (Breakfast/Lunch/Dinner) - 40+ orders across different restaurants - Analysis tasks: - Total spent - Average cost by cuisine - Most ordered cuisine - Average rating by restaurant - Correlation between delivery time and rating - Filter: expensive orders (cost > 300), poor ratings (< 3) - Group by day of week: which day you order most? - Create "value score": Rating / (Cost/100) *Hint:* Extract day: ``df['Date'].dt.day_name()``. Pivot table: ``df.pivot_table(values='Cost', index='Day_of_Week', columns='Cuisine', aggfunc='sum')``. **10. Fitness Challenge Tracker** ๐Ÿ’ช Create a fitness progress analyzer: - DataFrame: Date, Exercise, Duration_Minutes, Calories_Burned, Difficulty (Easy/Medium/Hard), Completed (Yes/No), Mood_Before, Mood_After - 30 days of workout data - Analysis: - Total calories burned - Average duration by difficulty - Completion rate (percentage) - Correlation between duration and calories - Compare mood before vs after (create mood improvement column) - Filter: incomplete workouts, analyze why - Group by exercise type: which burns most calories per minute? *Hint:* Create calculated column: ``df['Mood_Improvement'] = df['Mood_After'] - df['Mood_Before']``. Use ``df['Completed'].value_counts(normalize=True)`` for completion percentage. -------------- Matplotlib Assignments ---------------------- **11. Emotional Journey Visualization** ๐Ÿ˜Š๐Ÿ˜ข Create a multi-chart emotional tracking dashboard: - Generate 30 days of emotion data: Happiness, Stress, Energy (all 0-10 scales) - Create 4 subplots: - Line plot: All three emotions over time - Bar plot: Average of each emotion - Scatter plot: Happiness vs Stress (show negative correlation?) - Pie chart: Days categorized as Good (H>7), Okay (4-7), Bad (<4) - Use different colors, labels, titles, legends - Add annotations for peak stress and lowest energy days *Hint:* Use ``plt.subplots(2, 2, figsize=(15, 10))``. Use ``ax.annotate()`` for annotations. Color maps: ``plt.cm.rainbow()``. **12. Academic Performance Dashboard** ๐Ÿ“Š Create a comprehensive grade visualization: - 5 subjects, 6 exams each (30 data points) - Visualizations: - Line plot: Grade trends per subject across exams - Bar plot: Average grade per subject (sorted) - Horizontal bar: Improvement from Exam 1 to Exam 6 per subject - Histogram: Distribution of all grades - Add grid, custom colors, legends - Use emojis in titles! ๐ŸŽ“๐Ÿ“ˆ *Hint:* Use ``plt.subplots(2, 2)``. For improvement: ``final_grades - initial_grades``. Histogram: ``plt.hist(all_grades, bins=10, edgecolor='black')``. **13. Budget Breakdown Pie Chart** ๐Ÿ’ฐ Create a beautiful expense breakdown visualization: - Categories: Food, Rent, Transport, Entertainment, Shopping, Bills, Savings - Create: - Pie chart with percentages, explode largest expense - Donut chart (same as pie but with circle in center) - Bar plot: Expense comparison - Use custom color palette - Add shadow, startangle for better look - Display actual amounts in legend *Hint:* Explode: ``explode = (0.1, 0, 0, 0, 0, 0, 0)`` for first slice. Donut: ``plt.pie(...); plt.Circle((0,0), 0.70, color='white'); plt.gca().add_artist(circle)``. **14. Time Series: Social Media Usage** ๐Ÿ“ฑ Visualize social media addiction patterns: - 30 days, 4 platforms: Instagram, Twitter, YouTube, WhatsApp (hours per day) - Create: - Stacked area plot: Cumulative usage across platforms - Line plot with multiple lines (one per platform) - Scatter plot: Total daily usage vs day number (trend?) - Box plot: Usage distribution per platform - Add horizontal line at y=5 (danger zone!) - Color code platforms: Instagram (purple), Twitter (blue), YouTube (red), WhatsApp (green) *Hint:* Stacked area: ``plt.stackplot(x, y1, y2, y3, y4, labels=[...], alpha=0.7)``. Box plot: ``plt.boxplot([data1, data2, data3, data4], labels=[...])``. **15. Advanced: Interactive Dashboard (Multiple Plots)** ๐ŸŽจ Create a 3x2 subplot dashboard combining all skills: - Top row: Line plot (motivation), Bar plot (category comparison), Pie chart (distribution) - Bottom row: Scatter plot (correlation), Histogram (distribution), Box plot (outliers) - Use tight_layout, shared x-axis where appropriate - Custom color scheme throughout - Add overall title with ``plt.suptitle()`` *Hint:* Use ``fig, axes = plt.subplots(2, 3, figsize=(18, 10))``. Access subplots: ``axes[0, 0]``, ``axes[0, 1]``, etc. Use ``plt.tight_layout()``. -------------- Flask Web Development Assignments ---------------------------------- **16. Rate My Life Choices (CRUD App)** ๐ŸŽฏ Build a complete life decision tracker web app: Features: - Home page: List all decisions with ratings - Add decision: Form with fields (date, decision, category, rating 1-5, consequences, regret level) - View decision details: Individual page showing full info - Edit decision: Update any field - Delete decision: With confirmation and farewell message - Statistics page: Show counts by category, average rating, most regrettable category Styling requirements: - Use gradient backgrounds - Color-code categories - Add emojis for ratings (โญ for stars) - Responsive design with CSS *Hint:* Use list of dictionaries for storage. Implement all CRUD routes. Use ``render_template()`` with data. Add CSS in ``