Public
Edited
Nov 9, 2024
Insert cell
Insert cell
pyodide.runPython(`
import sys

f"Hello, from Python version: {sys.version}!"
`)
Insert cell
Insert cell
performPCA([
[-1, -1],
[-2, -1],
[-3, -2],
[1, 1],
[2, 1],
[3, 2]
])
Insert cell
async function performPCA(data) {
await pyodide.loadPackage("scikit-learn");
pyodide.globals.set("data", data);

const transformedData = pyodide.runPython(`
import numpy as np
from sklearn.decomposition import PCA

X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
pca = PCA(n_components=2)
pca.fit(X)
pca.transform(X)
`);

return transformedData.toJs();
}
Insert cell
Insert cell
pyodide = {
let pyodide = await import(
"https://cdn.jsdelivr.net/pyodide/v0.26.3/full/pyodide.js"
);
return globalThis.loadPyodide();
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more