Skip to content

Commit 0f47429

Browse files
committed
Add code snippet for random projection
1 parent 87cfd9e commit 0f47429

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
+++
2+
title = "Gaussian Random Projection"
3+
+++
4+
```rust
5+
// Assume we get some training data like MNIST: 60000 samples of 28*28 images (ie dim 784)
6+
let dataset = Dataset::from(Array::<f64, _>::random((60000, 28 * 28), Standard));
7+
8+
// We can work in a reduced dimension using a Gaussian Random Projection
9+
let reduced_dim = 100;
10+
let proj = GaussianRandomProjection::<f32>::params()
11+
.target_dim(reduced_dim)
12+
.fit(&dataset)?;
13+
let reduced_ds = proj.transform(&dataset);
14+
15+
println!("New dataset shape: {:?}", reduced_ds.records().shape());
16+
// -> New dataset shape: [60000, 100]
17+
```

0 commit comments

Comments
 (0)