Spaces:
Sleeping
Sleeping
pages added
Browse files
pages/1_Introduction_to_Numpy_Pandas_Matplotlib.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
st.markdown(
|
| 5 |
+
"""
|
| 6 |
+
# High-Level Overview of Python Notebook
|
| 7 |
+
|
| 8 |
+
## Executive Summary
|
| 9 |
+
The notebook encompasses a broad range of operations primarily focused on data manipulation, statistical analysis, and visualization using Python libraries such as NumPy, Pandas, Matplotlib, and Seaborn. It demonstrates proficiency in handling arrays, series, data frames, and producing graphical representations of data, which are essential skills in data science and analytics.
|
| 10 |
+
|
| 11 |
+
## Situation/Motivation/Question
|
| 12 |
+
The code in the notebook seems designed to showcase various techniques in data manipulation and visualization, particularly in the context of statistical analysis and data exploration. It aims to answer several implicit questions:
|
| 13 |
+
- How can numerical data be manipulated and transformed using NumPy?
|
| 14 |
+
- What insights can be derived from data using Pandas operations like grouping and aggregation?
|
| 15 |
+
- How can data be visualized effectively to communicate information clearly and efficiently?
|
| 16 |
+
|
| 17 |
+
## High-Level Overview of the Code
|
| 18 |
+
1. **Data Manipulation with NumPy**: The notebook performs array operations, random number generation, arithmetic operations, and linear spacing with NumPy. These operations are foundational for any numerical computation in Python.
|
| 19 |
+
2. **Statistical Analysis with Pandas**: Utilizing Pandas, the notebook explores data involving countries, animal characteristics, and economic indicators. It demonstrates data grouping, descriptive statistics, and condition-based filtering, which are crucial for summarizing and understanding large datasets.
|
| 20 |
+
3. **Data Visualization**: Using Matplotlib and Seaborn, the notebook creates various plots (scatter plots, line plots, categorical plots) to visualize relationships and distributions within the data. This section highlights the importance of visual tools in data analysis to uncover patterns and insights.
|
| 21 |
+
4. **Interactive Components**: Some cells contain annotations suggesting interactive or hidden solutions, which could be part of a teaching module or interactive session, indicating a pedagogical use of the notebook.
|
| 22 |
+
|
| 23 |
+
## Future Outlook and Extensions
|
| 24 |
+
- **Machine Learning Integration**: The next steps could involve integrating machine learning models to predict outcomes based on the data explored. For example, using regression models to predict tips based on total bills or classification models to categorize animals based on their attributes.
|
| 25 |
+
- **Advanced Data Visualization**: Enhancing the visualization section with more complex graphical representations like heatmaps, advanced scatter plots, and 3D plots could provide deeper insights into the data.
|
| 26 |
+
- **Interactive Dashboards**: Transforming the notebook into an interactive dashboard using libraries like Dash or Streamlit could make the analyses more user-friendly and accessible to non-technical stakeholders.
|
| 27 |
+
- **Real-time Data Analysis**: Incorporating APIs to fetch real-time data for analysis would make the notebook more dynamic and applicable to current events or live data feeds.
|
| 28 |
+
|
| 29 |
+
This markdown document outlines the purpose, content, and potential expansions of the notebook, providing a roadmap for further development and utilization in various data analysis scenarios.
|
| 30 |
+
|
| 31 |
+
"""
|
| 32 |
+
)
|
pages/1_Introduction_to_Python.py
CHANGED
|
@@ -3,49 +3,37 @@ import streamlit as st
|
|
| 3 |
|
| 4 |
st.markdown(
|
| 5 |
"""
|
| 6 |
-
#
|
| 7 |
|
| 8 |
## Executive Summary
|
| 9 |
-
|
| 10 |
-
This notebook demonstrates the application of Monte Carlo methods to estimate the value of Pi. Through a sequence of randomized experiments, it visualizes how increasing the number of points sampled within a unit square (and assessing whether they fall inside a unit circle) converges to a mathematical estimation of Pi.
|
| 11 |
-
|
| 12 |
-
[Link](https://huggingface.co/spaces/eagle0504/AI-Decoded/blob/main/docs/notebooks/ex0%20-%20intro%20to%20python%20-%20creating%20pi.ipynb)
|
| 13 |
|
| 14 |
## Situation/Motivation/Question
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
2. **
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
- Visualizations are generated for each sample size showing:
|
| 29 |
-
- A scatter plot of the points with different colors indicating inside or outside the circle.
|
| 30 |
-
- A line plot showing the convergence of the estimated value of Pi towards the actual value over the sequence of experiments.
|
| 31 |
-
|
| 32 |
-
3. **Output**:
|
| 33 |
-
- Each plot is saved as an individual image.
|
| 34 |
-
- Finally, these images are compiled into an animated GIF that illustrates the change in the estimate with increasing sample size.
|
| 35 |
-
|
| 36 |
-
4. **Cleanup**: Closes each plot to free memory, ensuring the notebook runs efficiently.
|
| 37 |
|
| 38 |
## Future Outlook
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
- **Increasing Efficiency**: Implement parallel processing or use more efficient data structures to handle larger sample sizes or to speed up the simulation.
|
| 43 |
-
- **Interactive Visualizations**: Integrate interactive components, such as sliders to change parameters like the sample size in real-time, which would make the demonstration more engaging.
|
| 44 |
-
- **Statistical Analysis**: Extend the notebook to include statistical measures that analyze the variance and convergence rate of the estimates.
|
| 45 |
-
- **Educational Tool**: Develop this notebook into a more comprehensive educational tool that includes explanations of the Monte Carlo method, its mathematical basis, and its applications in other areas.
|
| 46 |
-
- **Advanced Techniques**: Incorporate more sophisticated Monte Carlo methods, such as importance sampling or Markov Chain Monte Carlo, to improve the accuracy of Pi estimations.
|
| 47 |
|
| 48 |
-
This notebook serves not only as a method to approximate Pi but also as a demonstration of how random sampling can address complex mathematical problems and provide insights into the behavior of numerical methods.
|
| 49 |
|
| 50 |
"""
|
| 51 |
)
|
|
|
|
| 3 |
|
| 4 |
st.markdown(
|
| 5 |
"""
|
| 6 |
+
# Python Notebook Overview
|
| 7 |
|
| 8 |
## Executive Summary
|
| 9 |
+
This Python notebook contains a series of basic programming exercises that demonstrate simple Python operations including variable assignments, user input handling, arithmetic calculations, conditional statements, and basic string manipulations. The notebook serves as a primer to Python programming, focusing on various introductory concepts.
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
## Situation/Motivation/Question
|
| 12 |
+
The primary motivation behind this notebook is to introduce new programmers to various fundamental concepts in Python. The notebook addresses the following questions:
|
| 13 |
+
- How do you perform simple print operations in Python?
|
| 14 |
+
- How can user inputs be handled and utilized in calculations?
|
| 15 |
+
- What are the basics of Python syntax for control structures like conditional statements?
|
| 16 |
+
- How can Python be used for simple arithmetic operations to solve everyday problems, such as currency conversion?
|
| 17 |
+
|
| 18 |
+
## High Level Overview of the Code
|
| 19 |
+
The notebook executes a series of independent code blocks that illustrate basic Python functionalities:
|
| 20 |
+
1. **Printing Statements**: The notebook starts with simple print statements that output text such as "Hello World!" and other introductory phrases to the console.
|
| 21 |
+
2. **Variable Assignments and Updates**: It demonstrates how to store string and numeric data in variables and how to update these variables.
|
| 22 |
+
3. **Arithmetic Calculations**: The notebook includes an example where arithmetic mean is calculated from judges' scores, demonstrating how to perform arithmetic operations and combine them with print statements for output.
|
| 23 |
+
4. **User Input Handling**: It collects user inputs for names and dollar amounts, and uses these inputs in greeting messages and currency conversion calculations, respectively.
|
| 24 |
+
5. **Conditional Logic**: The notebook shows how to use if-else statements to handle decisions based on user inputs and predefined conditions, such as determining actions based on traffic light colors.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
## Future Outlook
|
| 27 |
+
The notebook can be extended and improved in several ways:
|
| 28 |
+
- **Expanding User Interaction**: Incorporating more complex user interactions, such as looping until a user provides valid input.
|
| 29 |
+
- **Integration with External APIs**: Adding examples that fetch data from external APIs, such as weather data or real-time currency conversion rates.
|
| 30 |
+
- **Graphical User Interfaces (GUIs)**: Introducing Python libraries for creating simple GUIs, which can make the applications more interactive and user-friendly.
|
| 31 |
+
- **Data Visualization**: Demonstrating basic data visualization techniques using libraries like Matplotlib or Seaborn to graph the input data or results.
|
| 32 |
+
- **Error Handling**: Adding robust error handling to improve the reliability of user input operations and other error-prone areas.
|
| 33 |
+
- **Unit Testing**: Introducing basic unit tests to ensure that functions in the notebook work as expected under various conditions.
|
| 34 |
|
| 35 |
+
This extension will make the notebook more applicable to real-world scenarios and help new programmers understand not only the basics but also some intermediate aspects of Python programming.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
|
|
|
| 37 |
|
| 38 |
"""
|
| 39 |
)
|
pages/1_Introduction_to_Python_Creating_Pi.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
st.markdown(
|
| 5 |
+
"""
|
| 6 |
+
# Estimating Pi Using Monte Carlo Simulation
|
| 7 |
+
|
| 8 |
+
## Executive Summary
|
| 9 |
+
|
| 10 |
+
This notebook demonstrates the application of Monte Carlo methods to estimate the value of Pi. Through a sequence of randomized experiments, it visualizes how increasing the number of points sampled within a unit square (and assessing whether they fall inside a unit circle) converges to a mathematical estimation of Pi.
|
| 11 |
+
|
| 12 |
+
[Link](https://huggingface.co/spaces/eagle0504/AI-Decoded/blob/main/docs/notebooks/ex0%20-%20intro%20to%20python%20-%20creating%20pi.ipynb)
|
| 13 |
+
|
| 14 |
+
## Situation/Motivation/Question
|
| 15 |
+
|
| 16 |
+
Estimating the value of Pi (π) is a classic problem in mathematics and computational science. The value of Pi is central to calculations in geometry, physics, engineering, and beyond. While Pi's decimal representation is infinite, computational methods can approximate its value to varying degrees of accuracy. One popular method for this approximation is the Monte Carlo simulation, which uses randomness to solve problems that might be deterministic in principle. This notebook explores how effectively the Monte Carlo method can estimate Pi and visualizes the convergence of this estimate as the number of trials increases.
|
| 17 |
+
|
| 18 |
+
## High-Level Overview of the Code
|
| 19 |
+
|
| 20 |
+
The code performs the following operations:
|
| 21 |
+
|
| 22 |
+
1. **Setup**: Initializes variables and ranges for the simulation. It prepares a range of sample sizes from 100 to 20,000, increasing in steps of 100.
|
| 23 |
+
|
| 24 |
+
2. **Simulation Loop**:
|
| 25 |
+
- For each sample size, it generates two arrays of random coordinates representing points within a unit square (0,1)×(0,1).
|
| 26 |
+
- It then checks if each point lies within the unit circle centered at the origin.
|
| 27 |
+
- It calculates the ratio of points inside the circle to the total points, using this ratio to estimate Pi.
|
| 28 |
+
- Visualizations are generated for each sample size showing:
|
| 29 |
+
- A scatter plot of the points with different colors indicating inside or outside the circle.
|
| 30 |
+
- A line plot showing the convergence of the estimated value of Pi towards the actual value over the sequence of experiments.
|
| 31 |
+
|
| 32 |
+
3. **Output**:
|
| 33 |
+
- Each plot is saved as an individual image.
|
| 34 |
+
- Finally, these images are compiled into an animated GIF that illustrates the change in the estimate with increasing sample size.
|
| 35 |
+
|
| 36 |
+
4. **Cleanup**: Closes each plot to free memory, ensuring the notebook runs efficiently.
|
| 37 |
+
|
| 38 |
+
## Future Outlook
|
| 39 |
+
|
| 40 |
+
The current approach could be extended in several ways:
|
| 41 |
+
|
| 42 |
+
- **Increasing Efficiency**: Implement parallel processing or use more efficient data structures to handle larger sample sizes or to speed up the simulation.
|
| 43 |
+
- **Interactive Visualizations**: Integrate interactive components, such as sliders to change parameters like the sample size in real-time, which would make the demonstration more engaging.
|
| 44 |
+
- **Statistical Analysis**: Extend the notebook to include statistical measures that analyze the variance and convergence rate of the estimates.
|
| 45 |
+
- **Educational Tool**: Develop this notebook into a more comprehensive educational tool that includes explanations of the Monte Carlo method, its mathematical basis, and its applications in other areas.
|
| 46 |
+
- **Advanced Techniques**: Incorporate more sophisticated Monte Carlo methods, such as importance sampling or Markov Chain Monte Carlo, to improve the accuracy of Pi estimations.
|
| 47 |
+
|
| 48 |
+
This notebook serves not only as a method to approximate Pi but also as a demonstration of how random sampling can address complex mathematical problems and provide insights into the behavior of numerical methods.
|
| 49 |
+
|
| 50 |
+
"""
|
| 51 |
+
)
|