Skip to content

Commit 9cc59ba

Browse files
Merge branch 'Codecademy:main' into 6426-tensor-op
2 parents bd562d0 + da0cdc2 commit 9cc59ba

File tree

15 files changed

+328
-3
lines changed

15 files changed

+328
-3
lines changed

content/c-sharp/concepts/data-types/data-types.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ Value types are data types that are built-in to C#. The available types and thei
2424
| --------- | ----------------------- | ------------ |
2525
| `bool` | Boolean | 1 byte |
2626
| `byte` | Byte | 1 byte |
27-
| `sbyte` | Short Byte | 1 byte |
27+
| `sbyte` | Signed Byte | 1 byte |
2828
| `char` | Character | 2 bytes |
2929
| `decimal` | Decimal | 16 bytes |
3030
| `double` | Double | 8 bytes |
3131
| `float` | Float | 4 bytes |
3232
| `int` | Integer | 4 bytes |
3333
| `uint` | Unsigned Integer | 4 bytes |
3434
| `nint` | Native Integer | 4 or 8 bytes |
35-
| `unint` | Unsigned Native Integer | 4 or 8 bytes |
35+
| `nuint` | Unsigned Native Integer | 4 or 8 bytes |
3636
| `long` | Long | 8 bytes |
3737
| `ulong` | Unsigned Long | 8 bytes |
3838
| `short` | Short | 2 bytes |
@@ -51,7 +51,7 @@ float heightOfGiraffe = 908.32f;
5151
int seaLevel = -24;
5252
uint year = 2023u;
5353
nint pagesInBook = 412;
54-
unint milesToNewYork = 2597;
54+
nuint milesToNewYork = 2597;
5555
long circumferenceOfEarth = 25000l;
5656
ulong depthOfOcean = 28000ul;
5757
short tableHeight = 4;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
Title: 'Chi-Square Distribution'
3+
Description: 'The chi-square distribution is a continuous probability distribution used primarily in hypothesis testing and confidence interval estimation.'
4+
Subjects:
5+
- 'Data Science'
6+
- 'AI'
7+
Tags:
8+
- 'Data Distributions'
9+
- 'Chi-Square'
10+
- 'Statistics'
11+
CatalogContent:
12+
- 'learn-data-science'
13+
- 'paths/data-science'
14+
---
15+
16+
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.
17+
18+
## Example
19+
20+
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:
21+
22+
```py
23+
import numpy as np
24+
import matplotlib.pyplot as plt
25+
from scipy.stats import chi2
26+
27+
# Set the degrees of freedom
28+
df = 4
29+
30+
# Generate 1,000 random samples from the chi-square distribution
31+
data = chi2.rvs(df, size=1000)
32+
33+
# Plot the histogram
34+
plt.hist(data, bins=30, density=True, alpha=0.6, color='skyblue', edgecolor='black')
35+
plt.title(f"Chi-Square Distribution (df={df})")
36+
plt.xlabel("Value")
37+
plt.ylabel("Density")
38+
plt.show()
39+
```
40+
41+
The above code generates a histogram illustrating the chi-square distribution:
42+
43+
![The output for the above example](https://raw.githubusercontent.com/Codecademy/docs/main/media/chi-square-distribution.png)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
Title: 'Exponential Distribution'
3+
Description: 'The exponential distribution is a probability distribution often used to model the time between events in a Poisson process.'
4+
Subjects:
5+
- 'Data Science'
6+
- 'Statistics'
7+
Tags:
8+
- 'Data Distributions'
9+
- 'Exponential'
10+
CatalogContent:
11+
- 'learn-data-science'
12+
- 'paths/data-science'
13+
---
14+
15+
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.
16+
17+
The exponential distribution formula is given by:
18+
19+
$$f(x|λ) = λ e^{-λ x}$$
20+
21+
- `λ`: The rate parameter that represents the number of events per unit time.
22+
- `x`: A random variable that represents the time between events.
23+
24+
## Example
25+
26+
The example below demonstrates how to generate random samples from an exponential distribution using NumPy and visualize the results with a histogram using Matplotlib:
27+
28+
```python
29+
import numpy as np
30+
import matplotlib.pyplot as plt
31+
32+
# Set the rate parameter (lambda)
33+
rate = 1.5 # Events per unit time
34+
35+
# Generate 1,000 random samples from the exponential distribution
36+
data = np.random.exponential(scale=1/rate, size=1000)
37+
38+
# Plot the histogram of the generated data
39+
plt.hist(data, bins=30, density=True, alpha=0.6, color='teal', edgecolor='black')
40+
plt.title(f"Exponential Distribution (rate = {rate})")
41+
plt.xlabel("Time Between Events")
42+
plt.ylabel("Density")
43+
plt.show()
44+
```
45+
46+
The above code produces the following output:
47+
48+
![The output for the above example](https://raw.githubusercontent.com/Codecademy/docs/main/media/exponential-distribution.png)
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
---
2+
Title: 'Normal Distribution'
3+
Description: 'A kind of continuous probability distribution characterized by a bell-shaped curve that is symmetric around its mean.'
4+
Subjects:
5+
- 'Data Science'
6+
- 'Data Visualization'
7+
- 'Machine Learning'
8+
Tags:
9+
- 'Data Science'
10+
- 'Deep Learning'
11+
CatalogContent:
12+
- 'learn-python-3'
13+
- 'paths/data-science'
14+
---
15+
16+
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:
17+
18+
- **Mean (μ)**: The central value of the distribution.
19+
- **Standard Deviation (σ)**: Computes the amount of variation or dispersion in the data.
20+
21+
Mathematically, the probability density function (PDF) used for the normal distribution is:
22+
23+
![Normal distribution formula](https://raw.githubusercontent.com/Codecademy/docs/main/media/normal-distribution-formula.png)
24+
25+
Where:
26+
27+
- `x` is the random variable
28+
- `μ` is the mean
29+
- `σ` is the standard deviation
30+
- `e` is Euler's number (approximately 2.71828)
31+
- `π` is Pi (approximately 3.14159)
32+
33+
### Key Properties
34+
35+
1. **Bell-shaped and Symmetric**: The distribution is perfectly symmetrical around its mean.
36+
2. **Mean, Median, and Mode are Equal**: All three measures of central tendency have the same value.
37+
3. **Empirical Rule (68-95-99.7 Rule)**:
38+
- Approximately 68% of the given data falls within 1 standard deviation of the mean
39+
- Approximately 95% falls within 2 standard deviations
40+
- Approximately 99.7% falls within 3 standard deviations
41+
4. **Standardized Form**: Any normal distribution can be converted to a standard normal distribution (`μ=0`, `σ=1`) using the formula `z = (x-μ)/σ`.
42+
43+
### Applications
44+
45+
The normal distribution is broadly used in various fields:
46+
47+
- **Finance**: Modeling stock returns
48+
- **Natural Sciences**: Measurement errors
49+
- **Social Sciences**: IQ scores, heights, and other human characteristics
50+
- **Machine Learning**: Assumptions in many algorithms
51+
- **Quality Control**: Manufacturing processes
52+
53+
## Example
54+
55+
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:
56+
57+
```py
58+
import numpy as np
59+
import matplotlib.pyplot as plt
60+
from scipy import stats
61+
import seaborn as sns
62+
63+
# Set seed for reproducibility
64+
np.random.seed(42)
65+
66+
# Generate random data from a normal distribution
67+
# Parameters: mean=70, standard deviation=10, size=1000
68+
data = np.random.normal(70, 10, 1000)
69+
70+
# Create visualizations
71+
plt.figure(figsize=(12, 8))
72+
73+
# Histogram with density curve
74+
plt.subplot(2, 2, 1)
75+
sns.histplot(data, kde=True, stat="density")
76+
plt.title('Histogram with Density Curve')
77+
plt.xlabel('Value')
78+
plt.ylabel('Density')
79+
80+
# Q-Q plot to check normality
81+
plt.subplot(2, 2, 2)
82+
stats.probplot(data, plot=plt)
83+
plt.title('Q-Q Plot')
84+
85+
# Box plot
86+
plt.subplot(2, 2, 3)
87+
sns.boxplot(x=data)
88+
plt.title('Box Plot')
89+
plt.xlabel('Value')
90+
91+
# Verify the empirical rule
92+
plt.subplot(2, 2, 4)
93+
mean = np.mean(data)
94+
std = np.std(data)
95+
within_1_std = np.sum((mean - std <= data) & (data <= mean + std)) / len(data) * 100
96+
within_2_std = np.sum((mean - 2*std <= data) & (data <= mean + 2*std)) / len(data) * 100
97+
within_3_std = np.sum((mean - 3*std <= data) & (data <= mean + 3*std)) / len(data) * 100
98+
99+
bars = plt.bar(['', '', ''], [within_1_std, within_2_std, within_3_std])
100+
plt.axhline(y=68, color='r', linestyle='-', label='68% (theoretical)')
101+
plt.axhline(y=95, color='g', linestyle='-', label='95% (theoretical)')
102+
plt.axhline(y=99.7, color='b', linestyle='-', label='99.7% (theoretical)')
103+
plt.title('Empirical Rule Verification')
104+
plt.xlabel('Standard Deviation Range')
105+
plt.ylabel('Percentage of Data (%)')
106+
plt.legend()
107+
108+
plt.tight_layout()
109+
plt.show()
110+
111+
# Statistical summary
112+
print("Statistical Summary:")
113+
print(f"Mean: {np.mean(data):.2f}")
114+
print(f"Median: {np.median(data):.2f}")
115+
print(f"Standard Deviation: {np.std(data):.2f}")
116+
print(f"Skewness: {stats.skew(data):.4f}")
117+
print(f"Kurtosis: {stats.kurtosis(data):.4f}")
118+
print("\nEmpirical Rule Verification:")
119+
print(f"Data within 1 standard deviation: {within_1_std:.2f}% (theoretical: 68%)")
120+
print(f"Data within 2 standard deviations: {within_2_std:.2f}% (theoretical: 95%)")
121+
print(f"Data within 3 standard deviations: {within_3_std:.2f}% (theoretical: 99.7%)")
122+
```
123+
124+
The output of the above code will be:
125+
126+
```shell
127+
Statistical Summary:
128+
Mean: 70.19
129+
Median: 70.25
130+
Standard Deviation: 9.79
131+
Skewness: 0.1168
132+
Kurtosis: 0.0662
133+
134+
Empirical Rule Verification:
135+
Data within 1 standard deviation: 68.60% (theoretical: 68%)
136+
Data within 2 standard deviations: 95.60% (theoretical: 95%)
137+
Data within 3 standard deviations: 99.70% (theoretical: 99.7%)
138+
```
139+
140+
The histogram with density curve shows the bell-shaped curve characteristic of normal distributions:
141+
142+
![Bell-shaped curve](https://raw.githubusercontent.com/Codecademy/docs/main/media/normal-distribution-histogram.png)
143+
144+
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):
145+
146+
![Q-Q plot](https://raw.githubusercontent.com/Codecademy/docs/main/media/normal-distribution-q-plot.png)
147+
148+
Box plot visualizes the central tendency and spread of the data:
149+
150+
![Box plot](https://raw.githubusercontent.com/Codecademy/docs/main/media/normal-distribution-box-plot.png)
151+
152+
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:
153+
154+
![Bar plot](https://raw.githubusercontent.com/Codecademy/docs/main/media/normal-distribution-empirical-rule.png)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
Title: 'Weibull Distribution'
3+
Description: 'The Weibull distribution is a continuous probability distribution frequently used in reliability and survival analysis to model time-to-failure data.'
4+
Subjects:
5+
- 'Data Science'
6+
- 'AI'
7+
Tags:
8+
- 'Statistics'
9+
- 'Weibull'
10+
CatalogContent:
11+
- 'learn-python-3'
12+
- 'paths/data-science'
13+
---
14+
15+
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.
16+
17+
## Example
18+
19+
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.
20+
21+
```py
22+
import numpy as np
23+
import matplotlib.pyplot as plt
24+
25+
# Set the shape parameter for the Weibull distribution
26+
shape = 2.0
27+
28+
# Generate 1,000 random samples from the Weibull distribution
29+
data = np.random.weibull(shape, 1000)
30+
31+
# Plot the histogram of the generated data
32+
plt.hist(data, bins=30, density=True, alpha=0.6, color='purple', edgecolor='black')
33+
plt.title(f"Weibull Distribution (shape={shape})")
34+
plt.xlabel("Value")
35+
plt.ylabel("Density")
36+
plt.show()
37+
```
38+
39+
The above code will generate a histogram representing the Weibull distribution:
40+
41+
![The output for the above example](https://raw.githubusercontent.com/Codecademy/docs/main/media/weibull-distribution.png)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
Title: '.resizeTo()'
3+
Description: 'Resizes the browser window to the width and height specified in pixels.'
4+
Subjects:
5+
- 'Web Development'
6+
- 'Computer Science'
7+
Tags:
8+
- 'Arguments'
9+
- 'Functions'
10+
- 'Parameters'
11+
CatalogContent:
12+
- 'introduction-to-javascript'
13+
- 'paths/front-end-engineer-career-path'
14+
---
15+
16+
The **`.resizeTo()`** function in JavaScript modifies the browser window’s dimensions based on the specified width and height values in pixels.
17+
18+
## Syntax
19+
20+
```pseudo
21+
window.resizeTo(width, height);
22+
```
23+
24+
- `width`: Defines the new width of the window in pixels.
25+
- `height`: Defines the new height of the window in pixels.
26+
27+
## Example
28+
29+
The example below demonstrates the use of the `.resizeTo()` function:
30+
31+
```js
32+
window.resizeTo(450, 300);
33+
```
34+
35+
The above example will resize the window to a width of _450_ pixels and height of _300_ pixels.

documentation/tags.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Calendar
5555
Catch
5656
Characters
5757
Charts
58+
Chi-Square
5859
Chatbots
5960
Cryptocurrency
6061
Classes
@@ -89,6 +90,7 @@ D3
8990
Deployment
9091
Dart
9192
Data
93+
Data Distributions
9294
Data Parallelism
9395
Data Structures
9496
Data Types
@@ -393,10 +395,12 @@ Visibility
393395
VR
394396
Vue
395397
Web3
398+
Exponential
396399
WebRTC
397400
Weight & Bias
398401
While
399402
Whiteboarding
403+
Weibull
400404
Window Functions
401405
WordPress
402406
World Wide Web

media/chi-square-distribution.png

179 KB
Loading

media/exponential-distribution.png

137 KB
Loading
9.35 KB
Loading
29.9 KB
Loading

media/normal-distribution-formula.png

3.03 KB
Loading
30.1 KB
Loading

media/normal-distribution-q-plot.png

31.4 KB
Loading

media/weibull-distribution.png

169 KB
Loading

0 commit comments

Comments
 (0)