-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Codecademy:main' into 6426-tensor-op
- Loading branch information
Showing
15 changed files
with
328 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...pts/data-distributions/terms/chi-square-distribution/chi-square-distribution.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
Title: 'Chi-Square Distribution' | ||
Description: 'The chi-square distribution is a continuous probability distribution used primarily in hypothesis testing and confidence interval estimation.' | ||
Subjects: | ||
- 'Data Science' | ||
- 'AI' | ||
Tags: | ||
- 'Data Distributions' | ||
- 'Chi-Square' | ||
- 'Statistics' | ||
CatalogContent: | ||
- 'learn-data-science' | ||
- 'paths/data-science' | ||
--- | ||
|
||
The **chi-square distribution** is derived from the sum of squared standard normal variables. It plays a crucial role in statistical tests, such as the chi-square test for independence and goodness of fit. The shape of the distribution varies with its degrees of freedom; for lower degrees of freedom, it is skewed, while higher degrees of freedom result in a more symmetric shape. | ||
|
||
## Example | ||
|
||
The example below demonstrates how to generate random samples from a chi-square distribution and visualize them with a [histogram](https://www.codecademy.com/learn/statistics-histograms). In this demonstration, [SciPy](https://www.codecademy.com/resources/docs/scipy) is used to generate the samples and [Matplotlib](https://www.codecademy.com/resources/docs/matplotlib) is used for plotting: | ||
|
||
```py | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from scipy.stats import chi2 | ||
|
||
# Set the degrees of freedom | ||
df = 4 | ||
|
||
# Generate 1,000 random samples from the chi-square distribution | ||
data = chi2.rvs(df, size=1000) | ||
|
||
# Plot the histogram | ||
plt.hist(data, bins=30, density=True, alpha=0.6, color='skyblue', edgecolor='black') | ||
plt.title(f"Chi-Square Distribution (df={df})") | ||
plt.xlabel("Value") | ||
plt.ylabel("Density") | ||
plt.show() | ||
``` | ||
|
||
The above code generates a histogram illustrating the chi-square distribution: | ||
|
||
 |
48 changes: 48 additions & 0 deletions
48
...s/data-distributions/terms/exponential-distribution/exponential-distribution.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
Title: 'Exponential Distribution' | ||
Description: 'The exponential distribution is a probability distribution often used to model the time between events in a Poisson process.' | ||
Subjects: | ||
- 'Data Science' | ||
- 'Statistics' | ||
Tags: | ||
- 'Data Distributions' | ||
- 'Exponential' | ||
CatalogContent: | ||
- 'learn-data-science' | ||
- 'paths/data-science' | ||
--- | ||
|
||
The **exponential distribution** models the time between independent events that occur at a fixed average rate. It is frequently used in reliability analysis, queuing theory, and survival analysis. The distribution is defined by a single parameter, the rate λ which determines how quickly events occur. | ||
|
||
The exponential distribution formula is given by: | ||
|
||
$$f(x|λ) = λ e^{-λ x}$$ | ||
|
||
- `λ`: The rate parameter that represents the number of events per unit time. | ||
- `x`: A random variable that represents the time between events. | ||
|
||
## Example | ||
|
||
The example below demonstrates how to generate random samples from an exponential distribution using NumPy and visualize the results with a histogram using Matplotlib: | ||
|
||
```python | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
# Set the rate parameter (lambda) | ||
rate = 1.5 # Events per unit time | ||
|
||
# Generate 1,000 random samples from the exponential distribution | ||
data = np.random.exponential(scale=1/rate, size=1000) | ||
|
||
# Plot the histogram of the generated data | ||
plt.hist(data, bins=30, density=True, alpha=0.6, color='teal', edgecolor='black') | ||
plt.title(f"Exponential Distribution (rate = {rate})") | ||
plt.xlabel("Time Between Events") | ||
plt.ylabel("Density") | ||
plt.show() | ||
``` | ||
|
||
The above code produces the following output: | ||
|
||
 |
154 changes: 154 additions & 0 deletions
154
...ce/concepts/data-distributions/terms/normal-distribution/normal-distribution.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
--- | ||
Title: 'Normal Distribution' | ||
Description: 'A kind of continuous probability distribution characterized by a bell-shaped curve that is symmetric around its mean.' | ||
Subjects: | ||
- 'Data Science' | ||
- 'Data Visualization' | ||
- 'Machine Learning' | ||
Tags: | ||
- 'Data Science' | ||
- 'Deep Learning' | ||
CatalogContent: | ||
- 'learn-python-3' | ||
- 'paths/data-science' | ||
--- | ||
|
||
The **normal distribution**, otherwise known as the Gaussian distribution, is one of the most signifcant probability distributions used for continuous data. It is defined by two parameters: | ||
|
||
- **Mean (μ)**: The central value of the distribution. | ||
- **Standard Deviation (σ)**: Computes the amount of variation or dispersion in the data. | ||
|
||
Mathematically, the probability density function (PDF) used for the normal distribution is: | ||
|
||
 | ||
|
||
Where: | ||
|
||
- `x` is the random variable | ||
- `μ` is the mean | ||
- `σ` is the standard deviation | ||
- `e` is Euler's number (approximately 2.71828) | ||
- `π` is Pi (approximately 3.14159) | ||
|
||
### Key Properties | ||
|
||
1. **Bell-shaped and Symmetric**: The distribution is perfectly symmetrical around its mean. | ||
2. **Mean, Median, and Mode are Equal**: All three measures of central tendency have the same value. | ||
3. **Empirical Rule (68-95-99.7 Rule)**: | ||
- Approximately 68% of the given data falls within 1 standard deviation of the mean | ||
- Approximately 95% falls within 2 standard deviations | ||
- Approximately 99.7% falls within 3 standard deviations | ||
4. **Standardized Form**: Any normal distribution can be converted to a standard normal distribution (`μ=0`, `σ=1`) using the formula `z = (x-μ)/σ`. | ||
|
||
### Applications | ||
|
||
The normal distribution is broadly used in various fields: | ||
|
||
- **Finance**: Modeling stock returns | ||
- **Natural Sciences**: Measurement errors | ||
- **Social Sciences**: IQ scores, heights, and other human characteristics | ||
- **Machine Learning**: Assumptions in many algorithms | ||
- **Quality Control**: Manufacturing processes | ||
|
||
## Example | ||
|
||
The following code creates a sample of 1,000 normally distributed data points with a mean of `70` and a standard deviation of `10`, and displays this data in a 2×2 grid of plots for analysis: | ||
|
||
```py | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from scipy import stats | ||
import seaborn as sns | ||
|
||
# Set seed for reproducibility | ||
np.random.seed(42) | ||
|
||
# Generate random data from a normal distribution | ||
# Parameters: mean=70, standard deviation=10, size=1000 | ||
data = np.random.normal(70, 10, 1000) | ||
|
||
# Create visualizations | ||
plt.figure(figsize=(12, 8)) | ||
|
||
# Histogram with density curve | ||
plt.subplot(2, 2, 1) | ||
sns.histplot(data, kde=True, stat="density") | ||
plt.title('Histogram with Density Curve') | ||
plt.xlabel('Value') | ||
plt.ylabel('Density') | ||
|
||
# Q-Q plot to check normality | ||
plt.subplot(2, 2, 2) | ||
stats.probplot(data, plot=plt) | ||
plt.title('Q-Q Plot') | ||
|
||
# Box plot | ||
plt.subplot(2, 2, 3) | ||
sns.boxplot(x=data) | ||
plt.title('Box Plot') | ||
plt.xlabel('Value') | ||
|
||
# Verify the empirical rule | ||
plt.subplot(2, 2, 4) | ||
mean = np.mean(data) | ||
std = np.std(data) | ||
within_1_std = np.sum((mean - std <= data) & (data <= mean + std)) / len(data) * 100 | ||
within_2_std = np.sum((mean - 2*std <= data) & (data <= mean + 2*std)) / len(data) * 100 | ||
within_3_std = np.sum((mean - 3*std <= data) & (data <= mean + 3*std)) / len(data) * 100 | ||
|
||
bars = plt.bar(['1σ', '2σ', '3σ'], [within_1_std, within_2_std, within_3_std]) | ||
plt.axhline(y=68, color='r', linestyle='-', label='68% (theoretical)') | ||
plt.axhline(y=95, color='g', linestyle='-', label='95% (theoretical)') | ||
plt.axhline(y=99.7, color='b', linestyle='-', label='99.7% (theoretical)') | ||
plt.title('Empirical Rule Verification') | ||
plt.xlabel('Standard Deviation Range') | ||
plt.ylabel('Percentage of Data (%)') | ||
plt.legend() | ||
|
||
plt.tight_layout() | ||
plt.show() | ||
|
||
# Statistical summary | ||
print("Statistical Summary:") | ||
print(f"Mean: {np.mean(data):.2f}") | ||
print(f"Median: {np.median(data):.2f}") | ||
print(f"Standard Deviation: {np.std(data):.2f}") | ||
print(f"Skewness: {stats.skew(data):.4f}") | ||
print(f"Kurtosis: {stats.kurtosis(data):.4f}") | ||
print("\nEmpirical Rule Verification:") | ||
print(f"Data within 1 standard deviation: {within_1_std:.2f}% (theoretical: 68%)") | ||
print(f"Data within 2 standard deviations: {within_2_std:.2f}% (theoretical: 95%)") | ||
print(f"Data within 3 standard deviations: {within_3_std:.2f}% (theoretical: 99.7%)") | ||
``` | ||
|
||
The output of the above code will be: | ||
|
||
```shell | ||
Statistical Summary: | ||
Mean: 70.19 | ||
Median: 70.25 | ||
Standard Deviation: 9.79 | ||
Skewness: 0.1168 | ||
Kurtosis: 0.0662 | ||
|
||
Empirical Rule Verification: | ||
Data within 1 standard deviation: 68.60% (theoretical: 68%) | ||
Data within 2 standard deviations: 95.60% (theoretical: 95%) | ||
Data within 3 standard deviations: 99.70% (theoretical: 99.7%) | ||
``` | ||
|
||
The histogram with density curve shows the bell-shaped curve characteristic of normal distributions: | ||
|
||
 | ||
|
||
Q-Q plot compares the data quantiles against theoretical normal distribution quantiles to check if the data follows a normal distribution (points following the diagonal line indicate normality): | ||
|
||
 | ||
|
||
Box plot visualizes the central tendency and spread of the data: | ||
|
||
 | ||
|
||
Bar chart tests whether the data follows the 68-95-99.7 rule by calculating the percentage of data points that fall within 1, 2, and 3 standard deviations: | ||
|
||
 |
41 changes: 41 additions & 0 deletions
41
.../concepts/data-distributions/terms/weibull-distribution/weibull-distribution.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
Title: 'Weibull Distribution' | ||
Description: 'The Weibull distribution is a continuous probability distribution frequently used in reliability and survival analysis to model time-to-failure data.' | ||
Subjects: | ||
- 'Data Science' | ||
- 'AI' | ||
Tags: | ||
- 'Statistics' | ||
- 'Weibull' | ||
CatalogContent: | ||
- 'learn-python-3' | ||
- 'paths/data-science' | ||
--- | ||
|
||
The **Weibull distribution** is a flexible continuous probability distribution commonly used to model the time until an event occurs, such as equipment failure or life expectancy. The shape of the distribution is controlled by its parameters, allowing it to represent different types of failure rates. It is widely applied in reliability engineering, survival analysis, and risk assessment. | ||
|
||
## Example | ||
|
||
The example below generates random samples from a Weibull distribution using NumPy and visualizes the results with a histogram. This demonstration illustrates how the data conforms to the Weibull distribution's characteristics. | ||
|
||
```py | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
# Set the shape parameter for the Weibull distribution | ||
shape = 2.0 | ||
|
||
# Generate 1,000 random samples from the Weibull distribution | ||
data = np.random.weibull(shape, 1000) | ||
|
||
# Plot the histogram of the generated data | ||
plt.hist(data, bins=30, density=True, alpha=0.6, color='purple', edgecolor='black') | ||
plt.title(f"Weibull Distribution (shape={shape})") | ||
plt.xlabel("Value") | ||
plt.ylabel("Density") | ||
plt.show() | ||
``` | ||
|
||
The above code will generate a histogram representing the Weibull distribution: | ||
|
||
 |
35 changes: 35 additions & 0 deletions
35
content/javascript/concepts/window/terms/resizeTo/resizeTo.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
Title: '.resizeTo()' | ||
Description: 'Resizes the browser window to the width and height specified in pixels.' | ||
Subjects: | ||
- 'Web Development' | ||
- 'Computer Science' | ||
Tags: | ||
- 'Arguments' | ||
- 'Functions' | ||
- 'Parameters' | ||
CatalogContent: | ||
- 'introduction-to-javascript' | ||
- 'paths/front-end-engineer-career-path' | ||
--- | ||
|
||
The **`.resizeTo()`** function in JavaScript modifies the browser window’s dimensions based on the specified width and height values in pixels. | ||
|
||
## Syntax | ||
|
||
```pseudo | ||
window.resizeTo(width, height); | ||
``` | ||
|
||
- `width`: Defines the new width of the window in pixels. | ||
- `height`: Defines the new height of the window in pixels. | ||
|
||
## Example | ||
|
||
The example below demonstrates the use of the `.resizeTo()` function: | ||
|
||
```js | ||
window.resizeTo(450, 300); | ||
``` | ||
|
||
The above example will resize the window to a width of _450_ pixels and height of _300_ pixels. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.