Public
Edited
Jul 4, 2023
Insert cell
Insert cell
Insert cell
complaints@15.db
SELECT * FROM metadata
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
gamma_mat.filter(d => d.topic == 0)
Insert cell
Array.from(new Set(gamma_mat.map(d => d.topic))).map(t => calc_relative_change(gamma_mat, t))
Insert cell
Insert cell
Insert cell
complaints@15.db
SELECT *
FROM beta
WHERE (model_index = ${model_index[0].model_index} AND level = ${form['sel_lvl']} )
Insert cell
Insert cell
complaints@15.db
SELECT *
FROM gamma
WHERE (model_index = ${model_index[0].model_index} AND level = ${form['sel_lvl']})
Insert cell
Insert cell
resdb
SELECT date_pub::DATE as date_pub, compound, airline, ratings::STRING as ratings, text, country
FROM raw_dat
WHERE (date_pub < '2023-01-01')
ORDER BY date_pub
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
single_airline = raw_dat.filter(d => d.airline == sel_airline)
Insert cell
import {Plot} from "@mkfreeman/plot-tooltip"
Insert cell
complaints@15.db
SELECT model_index FROM metadata WHERE (sent_fname = ${form['sel_sent_fname']} AND agg = ${form['sel_agg']})
Insert cell
complaints@15.db
SELECT *
FROM beta
WHERE (model_index = ${model_index[0].model_index} AND level = ${form['sel_lvl']})
Insert cell
model_index[0].model_index
Insert cell
resdb = DuckDBClient.of({raw_dat: FileAttachment("airline_reviews_original_six_en@3.parquet")})
Insert cell
function calc_relative_change(gamma_mat, topic) {
const topic_mu = d3.rollup(gamma_mat, v => d3.mean(v, d => d.score), d => d.topic)
return gamma_mat.filter(d => d.topic == topic)
.map(d => ((d.score - topic_mu.get(topic)) / topic_mu.get(topic) * 100).toFixed(3))
}
Insert cell
function plot_bars(gamma_mat, beta_mat) {
const beta_by_topic = d3.group(beta_mat, d => d.topic, d => d.word)

return Plot.plot({
height: 350,
width: 1200,
x: {
axis: null,
domain: gamma_mat.title
},
y: {
grid: true,
},
color: {
domain: gamma_mat.title,
scheme: "viridis",
legend: true
},
fx: {
domain: d3.groupSort(gamma_mat, v => d3.sum(v, d => -d.score), d => d.topic),
label: null,
tickSize: 6
},
facet: { data: gamma_mat, x: "topic" },
marks: [
Plot.barY(gamma_mat, {x: "title", y: "score", fill: "title",
title: d => `Top words topic ${d.topic}\n${Array.from(beta_by_topic.get(d.topic).keys()).join('\n')}`}),
Plot.ruleY([0])
]
})
}

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