Skip to content

Commit

Permalink
Merge branch 'Codecademy:main' into 6426-tensor-op
Browse files Browse the repository at this point in the history
  • Loading branch information
karishma-battina authored Mar 5, 2025
2 parents bd562d0 + da0cdc2 commit 9cc59ba
Show file tree
Hide file tree
Showing 15 changed files with 328 additions and 3 deletions.
6 changes: 3 additions & 3 deletions content/c-sharp/concepts/data-types/data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ Value types are data types that are built-in to C#. The available types and thei
| --------- | ----------------------- | ------------ |
| `bool` | Boolean | 1 byte |
| `byte` | Byte | 1 byte |
| `sbyte` | Short Byte | 1 byte |
| `sbyte` | Signed Byte | 1 byte |
| `char` | Character | 2 bytes |
| `decimal` | Decimal | 16 bytes |
| `double` | Double | 8 bytes |
| `float` | Float | 4 bytes |
| `int` | Integer | 4 bytes |
| `uint` | Unsigned Integer | 4 bytes |
| `nint` | Native Integer | 4 or 8 bytes |
| `unint` | Unsigned Native Integer | 4 or 8 bytes |
| `nuint` | Unsigned Native Integer | 4 or 8 bytes |
| `long` | Long | 8 bytes |
| `ulong` | Unsigned Long | 8 bytes |
| `short` | Short | 2 bytes |
Expand All @@ -51,7 +51,7 @@ float heightOfGiraffe = 908.32f;
int seaLevel = -24;
uint year = 2023u;
nint pagesInBook = 412;
unint milesToNewYork = 2597;
nuint milesToNewYork = 2597;
long circumferenceOfEarth = 25000l;
ulong depthOfOcean = 28000ul;
short tableHeight = 4;
Expand Down
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:

![The output for the above example](https://raw.githubusercontent.com/Codecademy/docs/main/media/chi-square-distribution.png)
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:

![The output for the above example](https://raw.githubusercontent.com/Codecademy/docs/main/media/exponential-distribution.png)
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:

![Normal distribution formula](https://raw.githubusercontent.com/Codecademy/docs/main/media/normal-distribution-formula.png)

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(['', '', ''], [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:

![Bell-shaped curve](https://raw.githubusercontent.com/Codecademy/docs/main/media/normal-distribution-histogram.png)

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):

![Q-Q plot](https://raw.githubusercontent.com/Codecademy/docs/main/media/normal-distribution-q-plot.png)

Box plot visualizes the central tendency and spread of the data:

![Box plot](https://raw.githubusercontent.com/Codecademy/docs/main/media/normal-distribution-box-plot.png)

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:

![Bar plot](https://raw.githubusercontent.com/Codecademy/docs/main/media/normal-distribution-empirical-rule.png)
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:

![The output for the above example](https://raw.githubusercontent.com/Codecademy/docs/main/media/weibull-distribution.png)
35 changes: 35 additions & 0 deletions content/javascript/concepts/window/terms/resizeTo/resizeTo.md
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.
4 changes: 4 additions & 0 deletions documentation/tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Calendar
Catch
Characters
Charts
Chi-Square
Chatbots
Cryptocurrency
Classes
Expand Down Expand Up @@ -89,6 +90,7 @@ D3
Deployment
Dart
Data
Data Distributions
Data Parallelism
Data Structures
Data Types
Expand Down Expand Up @@ -393,10 +395,12 @@ Visibility
VR
Vue
Web3
Exponential
WebRTC
Weight & Bias
While
Whiteboarding
Weibull
Window Functions
WordPress
World Wide Web
Expand Down
Binary file added media/chi-square-distribution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/exponential-distribution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/normal-distribution-box-plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/normal-distribution-empirical-rule.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/normal-distribution-formula.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/normal-distribution-histogram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/normal-distribution-q-plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/weibull-distribution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9cc59ba

Please sign in to comment.