Public
Edited
Jul 25, 2023
3 stars
Insert cell
Insert cell
Insert cell
data
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
selectedData.tipChannels
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
iris = ({
data: irisData,
zFeature: "species",
scale: false
})
Insert cell
Insert cell
wine = ({
data: wineData,
zFeature: "Wine",
scale: true
})
Insert cell
import { data as hawkerData } from "@yizhe-ang/sg-hawker-food-nutrition"
Insert cell
hawker = ({
data: hawkerData,
zFeature: "type",
scale: true,
toDrop: "food"
})
Insert cell
happinessData = whr_2023
Insert cell
whr_2023.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
happiness = ({
data: happinessData,
// zFeature: "Ladder score",
zFeature: null,
scale: true,
toDrop: "Country name",
tipChannels: { Country: "Country name" }
})
Insert cell
data = selectedData.data
Insert cell
Insert cell
Insert cell
df = new dfd.DataFrame(data)
Insert cell
Insert cell
Insert cell
Insert cell
correlations = d3.cross(corrFeatures, corrFeatures).map(([a, b]) => ({
a,
b,
correlation: corr(Plot.valueof(data, a), Plot.valueof(data, b))
}))
Insert cell
scaledDf = {
const dfCopy = df.copy();
const dfToScale = dfCopy.drop({ columns: featuresToDrop });
const dfNotToScale = dfCopy.loc({ columns: featuresToDrop });

const scaler = new dfd.StandardScaler();
scaler.fit(dfToScale);
const scaledDf = scaler.transform(dfToScale);

return dfd.concat({ dfList: [dfNotToScale, scaledDf], axis: 1 });
}
Insert cell
scaledData = {
// const scaler = new dfd.StandardScaler();
// scaler.fit(dataForPca);

// return scaler.transform(dataForPca);
return dfd.toJSON(scaledDf);
}
Insert cell
scaledDataSample = {
const sample = await scaledDf.sample(20, { seed: 5 });

return dfd.toJSON(sample);
}
Insert cell
feature1Weight = featureScale * Math.sin((featureDirection * Math.PI) / 180)
Insert cell
feature2Weight = featureScale * Math.cos((featureDirection * Math.PI) / 180)
Insert cell
feature1WeightAlt = Math.sin((featureDirectionAlt * Math.PI) / 180)
Insert cell
feature2WeightAlt = Math.cos((featureDirectionAlt * Math.PI) / 180)
Insert cell
Insert cell
Insert cell
dfForPca = df.drop({ columns: featuresToDrop })
Insert cell
featuresForPca = dfForPca.columns
Insert cell
// dataForPca = df.loc({ columns: featuresForPca }).values
dataForPca = dfForPca.values
Insert cell
// Scaling is important!
pca = new ML.PCA(dataForPca, { scale: selectedData.scale })
Insert cell
pcaData = pca.predict(dataForPca).data
Insert cell
// biplotVectors = pca.getLoadings().transpose().data
biplotVectors = pca.getEigenvectors().data
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
ML = require("https://www.lactame.com/lib/ml/6.0.0/ml.min.js")
Insert cell
Insert cell
Insert cell
import { PlotMatrix } with { data } from "@observablehq/autoplot-matrix"
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