If you already know what you're here for, feel free to delete all of this and start fresh. Otherwise keep reading.
You're looking at a Clojure namespace. The editor is on the left, the rendered notebook is on the right. Comment lines like this one become prose, and the value of each piece of code shows up right below it.
This notebook is being rendered on a real JVM, running on your very own sprite with the full Noj data science stack available — sample datasets, columnar data processing, plotting, statistics, and more.
The REPL is already connected and Calva power tools are pre-installed, so there are a couple of ways to see your code run:
Ctrl+Shift+Space, then a, then a. The form is evaluated in the REPL and Clay renders just that result in the panel on the right. This is a typical Clojure workflow: edit a form, run it, look at the result, repeat. (Ctrl+Shift+Space, a, c renders the smaller form right at the cursor instead of the whole top-level one.)Ctrl+Shift+Space, a, f, or save the file (Cmd/Ctrl+S) to re-render the whole notebook.Clojure has a comprehensive data science ecosystem that offers a lot of benefits that solve many of the common pain points that come up when working with data:
Clojure's data science community has tried to solve many of the problems with computational notebooks by taking a different approach to live programming. There are no cells with ambiguous execution order. This file is your notebook and an ordinary Clojure source file at the same time, and it loads top to bottom, in the same order every time. You still develop interactively by sending forms to the REPL, or by re-evaluating the whole namespace as you go. Here, it re-renders automatically every time you save.
We use Clay to render this namespace. Comments become prose, forms become code blocks, and each form is followed by its result in a relevant format. Strings render as text, datasets as tables, plots as charts, and so on. This idea -- values "knowing" how to present themselves -- is the kindly convention. Clay implements it, and so can any other rendering library, which is how one renderer handles everything below without any special type handling.
Here we load some of the most common tools in Clojure's data science toolkit:
(ns notebook
(:require [scicloj.metamorph.ml.rdatasets :as rdatasets]
[tablecloth.api :as tc]
[tablecloth.column.api :as tcc]
[scicloj.tableplot.v1.plotly :as plotly]
[scicloj.plotje.api :as pj]
[fastmath.ml.regression :as reg]))If you're new to Clojure or working with a REPL, the idea is that you evaluate tiny pieces of your program as you develop it, which makes for a very tight feedback loop and the ability to iterate toward working software very smooth and fast.
Here is one very tiny example to run. Put your cursor inside the form below and press Ctrl+Shift+Space, a, a. The result (2) is evaluated by the running REPL, re-rendered by Clay, and shows up on the right. Every code block below runs the same way, so try them as you go.
(+ 1 1)2
In the Clojure world you'll hear people say things like "data is just data" a lot. What they mean is that there are no special objects or wrappers or layers to navigate in order to access and manipulate your data. It is fundamentally just made of the same ordinary language-level data structures as everything else (including the Clojure language itself). Even specialized types, like tablecloth datasets, are not parochial objects with special access patterns. They behave just like familiar Clojure data structures in many ways. For example let's load the class iris-ds measurement dataset -- Edgar Anderson's measurements of 150 flowers across three species. rdatasets is included in noj and ships the R datasets collection, so there's nothing to download in a separate step.
(def iris-ds
(rdatasets/datasets-iris))Conceptually, you can think of a tablecloth dataset as a map of column names to values in that column. We can access a column the same way we'd access a value from any other map:
(:petal-length iris-ds)#tech.v3.dataset.column<float64>[150]
:petal-length
[1.400, 1.400, 1.300, 1.500, 1.400, 1.700, 1.400, 1.500, 1.400, 1.500, 1.500, 1.600, 1.400, 1.100, 1.200, 1.500, 1.300, 1.400, 1.700, 1.500...]
You'll notice that the tablecloth column is a specialized type, but we can still treat it like plain data using the entire Clojure standard library:
(take 15 (sort (:petal-length iris-ds)))(1.0 1.1 1.2 1.2 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.4 1.4 1.4 1.4)
The specialized type (in this case a tablecloth column) is there as an optimization to make column-wise operations efficient, but it does not add friction if you just want to access your data like you would any other Clojure data structure.
A Tablecloth dataset renders as a table because Clay knows its kind:
(tc/head iris-ds)https://vincentarelbundock.github.io/Rdatasets/csv/datasets/iris.csv [5 6]:
| :rownames | :sepal-length | :sepal-width | :petal-length | :petal-width | :species |
|---|---|---|---|---|---|
| 1 | 5.1 | 3.5 | 1.4 | 0.2 | setosa |
| 2 | 4.9 | 3.0 | 1.4 | 0.2 | setosa |
| 3 | 4.7 | 3.2 | 1.3 | 0.2 | setosa |
| 4 | 4.6 | 3.1 | 1.5 | 0.2 | setosa |
| 5 | 5.0 | 3.6 | 1.4 | 0.2 | setosa |
Its shape and column names are just functions that return plain data:
(tc/shape iris-ds)[150 6]
(tc/column-names iris-ds)(:rownames
:sepal-length
:sepal-width
:petal-length
:petal-width
:species)
Because Clojure data structures are immutable, any operation on a dataset returns a new value — the original is never changed in place, because it can't be. Here we add a column of sepal lengths in millimetres:
(def iris-ds-mm
(tc/map-columns iris-ds :sepal-length-mm [:sepal-length]
(fn [cm] (* 10 cm))))The new dataset has the extra column:
(tc/column-names iris-ds-mm)(:rownames
:sepal-length
:sepal-width
:petal-length
:petal-width
:species
:sepal-length-mm)
...but the original is untouched. There's no ambiguity about what state your dataset is in, because nothing can mutate it:
(tc/column-names iris-ds)(:rownames
:sepal-length
:sepal-width
:petal-length
:petal-width
:species)
Wrangling data in Clojure is typically done as a pipeline you read top to bottom, starting with -> (the "thread first" macro). It works like a Unix pipe, passing the result of each step as the first argument to the next. Tablecloth is the main data wrangling library — a collection of functions for transforming datasets that compose cleanly. It also includes the column operators (imported here as tcc) for fast column-wise work on large datasets.
Let's group the flowers by species and summarise each group:
(-> iris-ds
(tc/group-by [:species])
(tc/aggregate {:n tc/row-count
:mean-petal-len #(tcc/mean (:petal-length %))
:sd-petal-len #(tcc/standard-deviation (:petal-length %))
:mean-petal-wid #(tcc/mean (:petal-width %))})
(tc/order-by [:mean-petal-len] :desc))_unnamed [3 5]:
| :species | :n | :mean-petal-len | :sd-petal-len | :mean-petal-wid |
|---|---|---|---|---|
| virginica | 50 | 5.552 | 0.55189470 | 2.026 |
| versicolor | 50 | 4.260 | 0.46991098 | 1.326 |
| setosa | 50 | 1.462 | 0.17366400 | 0.246 |
We can already see some information emerging from this dataset -- setosa petals are tiny, virginica petals are large.
Plotje is Clojure's take on the grammar of graphics. The vocabulary is small and composable, and it threads together the same way the data pipelines do. It's also opinionated: when you don't give it many details, it makes a reasonable guess about how to plot your data. A simple scatter plot is one function call:
(pj/lay-point iris-ds :sepal-length :sepal-width)To split the points by group, map a column to :color and Plotje will colour them for you:
(pj/lay-point iris-ds :sepal-length :sepal-width {:color :species})You can also build a plot up incrementally with pj/pose. A "pose" is the description of a plot as plain data — which columns become colour, which become axes, what kind of marks to use — before it's turned into a graphic. Here we map petal length and width and group by species:
(-> iris-ds
(pj/pose :petal-length :petal-width {:color :species})
pj/lay-point)Different kinds of layers can sit on the same pose. We can add a linear regression to each group above by laying a stat layer on top:
(-> iris-ds
(pj/pose :petal-length :petal-width {:color :species})
pj/lay-point
(pj/lay-smooth {:stat :linear-model}))pj/options customises titles, labels, and dimensions — all, of course, just plain Clojure data:
(-> iris-ds
(pj/pose :petal-length :petal-width {:color :species})
pj/lay-point
(pj/lay-smooth {:stat :linear-model})
(pj/options {:width 560 :height 380
:title "Iris-ds petals separate cleanly by species"
:x-label "Petal length (cm)"
:y-label "Petal width (cm)"}))And pj/arrange lays out a little dashboard from a vector of plots:
(pj/arrange
[(pj/lay-point iris-ds :sepal-length :sepal-width {:color :species})
(pj/lay-histogram iris-ds :sepal-length {:color :species})]
{:cols 2})There are many more details and examples in the Plotje docs.
Plotje isn't your only option, though. Tableplot builds plots from datasets with a layered grammar to but uses Plotly under the hood so it can render them as interactive charts. Below you can hover over a point to read its values, drag to zoom, and double-click to reset:
(-> iris-ds
(plotly/layer-point {:=x :petal-length
:=y :petal-width
:=color :species
:=mark-size 9
:=mark-opacity 0.7}))The three species fall into clean clusters — the reason iris-ds is the "hello, world" of classification.
The trend lines back in section 4 are backed by linear regression run on the JVM, not the browser. We can fit one manually with fastmath and see the full summary with coefficients, standard errors, p-values, and R². We'll predict petal width from petal length:
(reg/lm (:petal-width iris-ds) ; what we're predicting
(:petal-length iris-ds) ; the predictor, one feature per row
{:names ["petal-length"]}){:model :ols,
:intercept? true,
:offset? false,
:transformer nil,
:xtxinv
#object[org.apache.commons.math3.linear.BlockRealMatrix 0x6331f50e "BlockRealMatrix{{0.037081897,-0.008093462},{-0.008093462,0.0021536621}}"],
:intercept -0.36307552131903165,
:beta [0.41575541635241225],
:coefficients
[{:estimate -0.36307552131903165,
:stderr 0.03976198987309645,
:t-value -9.131221110357306,
:p-value 4.699798316295743E-16,
:confidence-interval [-0.44165008388735494 -0.28450095875070835]}
{:estimate 0.41575541635241225,
:stderr 0.00958243579076628,
:t-value 43.38723738206916,
:p-value 0.0,
:confidence-interval [0.396819349445259 0.4346914832595655]}],
:offset
(0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0),
:weights
(1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0),
:residuals
{:weighted
(-0.01898206157434551
-0.01898206157434551
0.022593480060895732
-0.06055760320958675
-0.01898206157434551
0.056291313519930886
0.08101793842565447
-0.06055760320958675
-0.01898206157434551
-0.16055760320958676
-0.06055760320958675
-0.102133144844828
-0.11898206157434552
0.005744563331378155
0.06416902169613697
0.13944239679041326
0.22259348006089574
0.08101793842565447
-0.04370868648006915
0.039442396790413226
-0.14370868648006913
0.13944239679041326
0.1473201049666194
0.15629131351993086
-0.2268597697505516
-0.102133144844828
0.09786685515517202
-0.06055760320958675
-0.01898206157434551
-0.102133144844828
-0.102133144844828
0.13944239679041326
-0.16055760320958676
-0.01898206157434551
-0.06055760320958675
0.06416902169613697
0.022593480060895732
-0.11898206157434552
0.022593480060895732
-0.06055760320958675
0.12259348006089571
0.12259348006089571
0.022593480060895732
0.297866855155172
-0.0268597697505516
0.08101793842565447
-0.102133144844828
-0.01898206157434551
-0.06055760320958675
-0.01898206157434551
-0.19097493553730605
-0.007823852266823472
-0.17412601880778844
5.3855909382560796E-5
-0.04939939390206449
-0.20782385226682343
0.009025064462694132
-0.008917352643928567
-0.24939939390206445
0.1416293975446239
-0.09206843591441105
0.11690277263890003
-0.2999461440906175
-0.19097493553730605
0.16635602245034753
-0.06624831063158254
-0.007823852266823472
-0.3415216857258585
-0.007823852266823472
-0.15837060245537593
0.16744952282745307
5.3855909382560796E-5
-0.17412601880778844
-0.390974935537306
-0.12467276899634094
-0.06624831063158254
-0.23255047717254707
-0.015701560443029505
-0.007823852266823472
-0.09206843591441105
-0.11679506082013491
-0.17521951918489398
-0.058370602455376064
-0.1572771020782704
-0.007823852266823472
0.09217614773317662
-0.09097493553730596
-0.1662483106315824
-0.04152168572585846
5.3855909382560796E-5
-0.2662483106315825
-0.14939939390206458
-0.09994614409061753
-0.008917352643928567
-0.08309722736109992
-0.1830972273611
-0.08309722736109992
-0.12467276899634094
0.21580927226179492
-0.04152168572585846
0.3685430232045581
0.14272289792172943
0.010118564839799227
-0.16515481025447687
0.15169410647504078
-0.2809102266068888
0.19217614773317648
-0.45618360170116534
-0.24830589352495935
0.3269674815693171
0.24272289792172952
0.059571814651246946
0.17642073138076464
0.28429843955697054
0.6427228979217294
0.45957181465124686
-0.1235792686192354
-0.22248576824213018
-0.20563685151261302
-0.21570156044302946
0.29326964811028144
0.32587398119221156
-0.42248576824213036
0.1258739811922116
0.09326964811028171
-0.33145697679544184
0.16744952282745307
0.1258739811922116
0.13484518974552318
-0.4483058935249593
-0.273032518430683
-0.29775914333640685
0.23484518974552326
-0.2572771020782705
-0.565154810254477
0.12696748156931692
0.434845189745523
-0.1235792686192354
0.16744952282745307
0.21799627301600566
0.434845189745523
0.5427228979217293
0.14272289792172943
0.21011856483979896
0.4932696481102816
0.5011473562864879
0.18429843955697045
0.20114735628648805
0.4179962730160054
0.04272289792172956),
:raw
(-0.01898206157434551
-0.01898206157434551
0.022593480060895732
-0.06055760320958675
-0.01898206157434551
0.056291313519930886
0.08101793842565447
-0.06055760320958675
-0.01898206157434551
-0.16055760320958676
-0.06055760320958675
-0.102133144844828
-0.11898206157434552
0.005744563331378155
0.06416902169613697
0.13944239679041326
0.22259348006089574
0.08101793842565447
-0.04370868648006915
0.039442396790413226
-0.14370868648006913
0.13944239679041326
0.1473201049666194
0.15629131351993086
-0.2268597697505516
-0.102133144844828
0.09786685515517202
-0.06055760320958675
-0.01898206157434551
-0.102133144844828
-0.102133144844828
0.13944239679041326
-0.16055760320958676
-0.01898206157434551
-0.06055760320958675
0.06416902169613697
0.022593480060895732
-0.11898206157434552
0.022593480060895732
-0.06055760320958675
0.12259348006089571
0.12259348006089571
0.022593480060895732
0.297866855155172
-0.0268597697505516
0.08101793842565447
-0.102133144844828
-0.01898206157434551
-0.06055760320958675
-0.01898206157434551
-0.19097493553730605
-0.007823852266823472
-0.17412601880778844
5.3855909382560796E-5
-0.04939939390206449
-0.20782385226682343
0.009025064462694132
-0.008917352643928567
-0.24939939390206445
0.1416293975446239
-0.09206843591441105
0.11690277263890003
-0.2999461440906175
-0.19097493553730605
0.16635602245034753
-0.06624831063158254
-0.007823852266823472
-0.3415216857258585
-0.007823852266823472
-0.15837060245537593
0.16744952282745307
5.3855909382560796E-5
-0.17412601880778844
-0.390974935537306
-0.12467276899634094
-0.06624831063158254
-0.23255047717254707
-0.015701560443029505
-0.007823852266823472
-0.09206843591441105
-0.11679506082013491
-0.17521951918489398
-0.058370602455376064
-0.1572771020782704
-0.007823852266823472
0.09217614773317662
-0.09097493553730596
-0.1662483106315824
-0.04152168572585846
5.3855909382560796E-5
-0.2662483106315825
-0.14939939390206458
-0.09994614409061753
-0.008917352643928567
-0.08309722736109992
-0.1830972273611
-0.08309722736109992
-0.12467276899634094
0.21580927226179492
-0.04152168572585846
0.3685430232045581
0.14272289792172943
0.010118564839799227
-0.16515481025447687
0.15169410647504078
-0.2809102266068888
0.19217614773317648
-0.45618360170116534
-0.24830589352495935
0.3269674815693171
0.24272289792172952
0.059571814651246946
0.17642073138076464
0.28429843955697054
0.6427228979217294
0.45957181465124686
-0.1235792686192354
-0.22248576824213018
-0.20563685151261302
-0.21570156044302946
0.29326964811028144
0.32587398119221156
-0.42248576824213036
0.1258739811922116
0.09326964811028171
-0.33145697679544184
0.16744952282745307
0.1258739811922116
0.13484518974552318
-0.4483058935249593
-0.273032518430683
-0.29775914333640685
0.23484518974552326
-0.2572771020782705
-0.565154810254477
0.12696748156931692
0.434845189745523
-0.1235792686192354
0.16744952282745307
0.21799627301600566
0.434845189745523
0.5427228979217293
0.14272289792172943
0.21011856483979896
0.4932696481102816
0.5011473562864879
0.18429843955697045
0.20114735628648805
0.4179962730160054
0.04272289792172956),
:loocv
(-0.019342635002015957
-0.019342635002015957
0.02304701264913051
-0.061645476375954564
-0.019342635002015957
0.057194309253591334
0.08255691329656169
-0.061645476375954564
-0.019342635002015957
-0.16344190342839707
-0.061645476375954564
-0.10386733393744621
-0.12124218330059364
0.005873079295423722
0.06552933610818945
0.14194737772893048
0.22706173359528295
0.08255691329656169
-0.04440983830878656
0.040150950676487926
-0.1460139858711644
0.14194737772893048
0.15079574095982914
0.15879845681596916
-0.23010458059267655
-0.10386733393744621
0.09952860397331331
-0.061645476375954564
-0.019342635002015957
-0.10386733393744621
-0.10386733393744621
0.14194737772893048
-0.16344190342839707
-0.019342635002015957
-0.061645476375954564
0.06552933610818945
0.02304701264913051
-0.12124218330059364
0.02304701264913051
-0.061645476375954564
0.12505437312220669
0.12505437312220669
0.02304701264913051
0.3029245418840728
-0.027243949246984138
0.08255691329656169
-0.10386733393744621
-0.019342635002015957
-0.061645476375954564
-0.019342635002015957
-0.19262724365537773
-0.007885774486664728
-0.17579171477830022
5.422424348381287E-5
-0.04980749336910415
-0.2094686832055277
0.009103148988476924
-0.008981285271416612
-0.2514597382037218
0.1425861639809275
-0.09269972316388253
0.11773722517966038
-0.30199755116319804
-0.19262724365537773
0.16748157073775144
-0.06675258157021262
-0.007885774486664728
-0.343900987957542
-0.007885774486664728
-0.15944046280607568
0.1689711136887245
5.422424348381287E-5
-0.17579171477830022
-0.39435763629923215
-0.12558948875346782
-0.06675258157021262
-0.23466363148242633
-0.015859983089956474
-0.007885774486664728
-0.09269972316388253
-0.11757936997772064
-0.1763967756697437
-0.058764920543741356
-0.15895331798868073
-0.007885774486664728
0.09290567987276686
-0.0917620473334504
-0.16751376466125673
-0.04181095766272193
5.422424348381287E-5
-0.26827494775230104
-0.1506336157864131
-0.10062970089207689
-0.008981285271416612
-0.08369037576071742
-0.18440417623090644
-0.08369037576071742
-0.12558948875346782
0.21752863673925443
-0.04181095766272193
0.37510441981280074
0.14424399914444408
0.010288824528519614
-0.16749538481969142
0.1541053824865041
-0.2878360565248486
0.19369713423219823
-0.4657706154139815
-0.2522528764267652
0.33312341084354885
0.2453097715221525
0.06028239743754654
0.17878101479281638
0.28716690040041604
0.6495728610329857
0.46505366579967095
-0.12523260094312164
-0.22826249760997244
-0.2115448706908932
-0.21787790541687138
0.2976718909896074
0.3289913038133971
-0.433455395486978
0.1270780963767182
0.09466970995403692
-0.3373581078612627
0.1689711136887245
0.1270780963767182
0.1367562162598196
-0.45543200588339977
-0.27817299559666175
-0.30436370830377546
0.23817341661965669
-0.26001909036638915
-0.5731641862590395
0.12935794203014517
0.4410078173393304
-0.12523260094312164
0.1689711136887245
0.22074974927326185
0.4410078173393304
0.5485070886552773
0.14424399914444408
0.21365411775766793
0.5006740720251783
0.5067955491140291
0.18615793923695845
0.20341439220078458
0.4232759174679389
0.04317822676673588)},
:fitted
(0.21898206157434552
0.21898206157434552
0.17740651993910428
0.26055760320958676
0.21898206157434552
0.34370868648006914
0.21898206157434552
0.26055760320958676
0.21898206157434552
0.26055760320958676
0.26055760320958676
0.302133144844828
0.21898206157434552
0.09425543666862185
0.13583097830386304
0.26055760320958676
0.17740651993910428
0.21898206157434552
0.34370868648006914
0.26055760320958676
0.34370868648006914
0.26055760320958676
0.05267989503338061
0.34370868648006914
0.4268597697505516
0.302133144844828
0.302133144844828
0.26055760320958676
0.21898206157434552
0.302133144844828
0.302133144844828
0.26055760320958676
0.26055760320958676
0.21898206157434552
0.26055760320958676
0.13583097830386304
0.17740651993910428
0.21898206157434552
0.17740651993910428
0.26055760320958676
0.17740651993910428
0.17740651993910428
0.17740651993910428
0.302133144844828
0.4268597697505516
0.21898206157434552
0.302133144844828
0.21898206157434552
0.26055760320958676
0.21898206157434552
1.590974935537306
1.5078238522668235
1.6741260188077884
1.2999461440906175
1.5493993939020645
1.5078238522668235
1.590974935537306
1.0089173526439286
1.5493993939020645
1.258370602455376
1.092068435914411
1.3830972273611
1.2999461440906175
1.590974935537306
1.1336439775496525
1.4662483106315825
1.5078238522668235
1.3415216857258585
1.5078238522668235
1.258370602455376
1.632550477172547
1.2999461440906175
1.6741260188077884
1.590974935537306
1.424672768996341
1.4662483106315825
1.632550477172547
1.7157015604430295
1.5078238522668235
1.092068435914411
1.216795060820135
1.175219519184894
1.258370602455376
1.7572771020782705
1.5078238522668235
1.5078238522668235
1.590974935537306
1.4662483106315825
1.3415216857258585
1.2999461440906175
1.4662483106315825
1.5493993939020645
1.2999461440906175
1.0089173526439286
1.3830972273611
1.3830972273611
1.3830972273611
1.424672768996341
0.8841907277382052
1.3415216857258585
2.131456976795442
1.7572771020782705
2.089881435160201
1.965154810254477
2.0483058935249594
2.380910226606889
1.5078238522668235
2.2561836017011654
2.0483058935249594
2.173032518430683
1.7572771020782705
1.840428185348753
1.9235792686192354
1.7157015604430295
1.7572771020782705
1.840428185348753
1.9235792686192354
2.4224857682421304
2.505636851512613
1.7157015604430295
2.0067303518897184
1.6741260188077884
2.4224857682421304
1.6741260188077884
2.0067303518897184
2.131456976795442
1.632550477172547
1.6741260188077884
1.965154810254477
2.0483058935249594
2.173032518430683
2.297759143336407
1.965154810254477
1.7572771020782705
1.965154810254477
2.173032518430683
1.965154810254477
1.9235792686192354
1.632550477172547
1.8820037269839944
1.965154810254477
1.7572771020782705
1.7572771020782705
2.089881435160201
2.0067303518897184
1.798852643713512
1.7157015604430295
1.798852643713512
1.8820037269839944
1.7572771020782705),
:df {:residual 148, :model 1, :intercept 1},
:observations 150,
:names ["Intercept" "petal-length"],
:cv 0.20792225211347873,
:r-squared 0.9271098389904927,
:adjusted-r-squared 0.9266173379025906,
:sigma2 0.04263578634627687,
:sigma 0.20648434891360865,
:tss 86.56993333333328,
:rss 6.310096379248977,
:regss 80.2598369540843,
:msreg 80.2598369540843,
:qt 1.9761224933435244,
:f-statistic 1882.4523676480267,
:p-value 0.0,
:ll
{:log-likelihood 24.795545790110168,
:aic -43.591091580220315,
:bic -34.55918569793152,
:aic-rss -471.2726515416222,
:bic-rss -465.25138095342965},
:analysis #<Delay@2039a990: :not-delivered>,
:decomposition :cholesky,
:augmentation nil,
:hat
(0.01864138095108893
0.01864138095108893
0.01967858460180458
0.017647250541682064
0.01864138095108893
0.01578820944679471
0.01864138095108893
0.017647250541682064
0.01864138095108893
0.017647250541682064
0.017647250541682064
0.016696193373583995
0.01864138095108893
0.021882211627162248
0.02075886149382902
0.017647250541682064
0.01967858460180458
0.01864138095108893
0.01578820944679471
0.017647250541682064
0.01578820944679471
0.017647250541682064
0.023048635001804273
0.01578820944679471
0.014101461317142513
0.016696193373583995
0.016696193373583995
0.017647250541682064
0.01864138095108893
0.016696193373583995
0.016696193373583995
0.017647250541682064
0.017647250541682064
0.01864138095108893
0.017647250541682064
0.02075886149382902
0.01967858460180458
0.01864138095108893
0.01967858460180458
0.017647250541682064
0.01967858460180458
0.01967858460180458
0.01967858460180458
0.016696193373583995
0.014101461317142513
0.01864138095108893
0.016696193373583995
0.01864138095108893
0.017647250541682064
0.01864138095108893
0.008577748851703279
0.007852395468063269
0.009475395200578447
0.006792793731867065
0.008193535539228879
0.007852395468063269
0.008577748851703279
0.007118427436161534
0.008193535539228879
0.006710093108554191
0.006810023028390594
0.007087414702419181
0.006792793731867065
0.008577748851703279
0.00672043068646831
0.0075543286382064485
0.007852395468063269
0.006918567596488729
0.007852395468063269
0.006710093108554191
0.009005035405486467
0.006792793731867065
0.009475395200578447
0.008577748851703279
0.007299335049658416
0.0075543286382064485
0.009005035405486467
0.009988828236979214
0.007852395468063269
0.006810023028390594
0.006670465726550107
0.006673911585854819
0.006710093108554191
0.01054533451468876
0.007852395468063269
0.007852395468063269
0.008577748851703279
0.0075543286382064485
0.006918567596488729
0.006792793731867065
0.0075543286382064485
0.008193535539228879
0.006792793731867065
0.007118427436161534
0.007087414702419181
0.007087414702419181
0.007087414702419181
0.007299335049658416
0.007904083357633858
0.006918567596488729
0.017492186872970286
0.01054533451468876
0.016548021423481638
0.013973964522868379
0.01564692921530176
0.024061717637386834
0.007852395468063269
0.020583122669289015
0.01564692921530176
0.01847942556376774
0.01054533451468876
0.011787566794034244
0.013202092038614888
0.009988828236979214
0.01054533451468876
0.011787566794034244
0.013202092038614888
0.02530739577603703
0.027927971777263777
0.009988828236979214
0.014788910248430678
0.009475395200578447
0.02530739577603703
0.009475395200578447
0.014788910248430678
0.017492186872970286
0.009005035405486467
0.009475395200578447
0.013973964522868379
0.01564692921530176
0.01847942556376774
0.02169958108401284
0.013973964522868379
0.01054533451468876
0.013973964522868379
0.01847942556376774
0.013973964522868379
0.013202092038614888
0.009005035405486467
0.012473292795670176
0.013973964522868379
0.01054533451468876
0.01054533451468876
0.016548021423481638
0.014788910248430678
0.011144914033707112
0.009988828236979214
0.011144914033707112
0.012473292795670176
0.01054533451468876),
:effective-dimension 2.0000000000000098}
In the summary, we can see R² is around 0.93, meaning petal length explains most of the variation in petal width .
This was a tiny demonstration of how you'd approach a typical data workflow, load → wrangle → visualise → model, all in one place.
To learn more you can:
(rdatasets/datasets-mtcars) or (rdatasets/datasets-titanic) are popular demo ones that are already available here.