Skip to content

Commit 584f669

Browse files
committed
need using Pyplot in ISL2
1 parent 5c5d08f commit 584f669

File tree

10 files changed

+39
-65
lines changed

10 files changed

+39
-65
lines changed

assets/literate/ISL-lab-2-mpg.svg

+21-21
Loading

assets/literate/ISL-lab-2.md

+2
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ There are multiple libraries that can be used to plot things in Julia:
165165
In these tutorials we use `PyPlot` but you could use another package of course.
166166

167167
```julia:ex21
168+
using PyPlot
169+
168170
figure(figsize=(8,6))
169171
plot(mpg)
170172

assets/literate/ISL-lab-2_script.jl

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ mpg |> mean
5858
@show nrow(auto)
5959
@show ncol(auto)
6060

61+
using PyPlot
62+
6163
figure(figsize=(8,6))
6264
plot(mpg)
6365

assets/pages/isl/lab-2/code/ex21.jl

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# This file was generated, do not modify it. # hide
2+
using PyPlot
3+
24
figure(figsize=(8,6))
35
plot(mpg)
46

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
(μ, σ) = (-0.003429405251489602, 1.0011574237294552)
1+
(μ, σ) = (0.028927854346407975, 1.0322439340512704)
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
(-0.003429405251489602, 1.0011574237294552)
1+
(0.028927854346407975, 1.0322439340512704)
+1-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
3×9 DataFrame
2-
│ Row │ MPG │ Cylinders │ Displacement │ Horsepower │ Weight │ Acceleration │ Year │ Origin │ Name │
3-
│ │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │ String │
4-
├─────┼─────────┼───────────┼──────────────┼────────────┼─────────┼──────────────┼─────────┼─────────┼───────────────────────────┤
5-
│ 1 │ 18.0 │ 8.0 │ 307.0 │ 130.0 │ 3504.0 │ 12.0 │ 70.0 │ 1.0 │ chevrolet chevelle malibu │
6-
│ 2 │ 15.0 │ 8.0 │ 350.0 │ 165.0 │ 3693.0 │ 11.5 │ 70.0 │ 1.0 │ buick skylark 320 │
7-
│ 3 │ 18.0 │ 8.0 │ 318.0 │ 150.0 │ 3436.0 │ 11.0 │ 70.0 │ 1.0 │ plymouth satellite │
1+
DataFrames.DataFrame(AbstractArray{T,1} where T[[18.0, 15.0, 18.0], [8.0, 8.0, 8.0], [307.0, 350.0, 318.0], [130.0, 165.0, 150.0], [3504.0, 3693.0, 3436.0], [12.0, 11.5, 11.0], [70.0, 70.0, 70.0], [1.0, 1.0, 1.0], ["chevrolet chevelle malibu", "buick skylark 320", "plymouth satellite"]], DataFrames.Index(Dict(:Cylinders => 2,:Horsepower => 4,:MPG => 1,:Displacement => 3,:Origin => 8,:Year => 7,:Acceleration => 6,:Weight => 5,:Name => 9), [:MPG, :Cylinders, :Displacement, :Horsepower, :Weight, :Acceleration, :Year, :Origin, :Name]))
+1-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1 @@
1-
9×4 DataFrame
2-
│ Row │ variable │ mean │ median │ std │
3-
│ │ Symbol │ Union… │ Union… │ Union… │
4-
├─────┼──────────────┼─────────┼────────┼──────────┤
5-
│ 1 │ MPG │ 23.4459 │ 22.75 │ 7.80501 │
6-
│ 2 │ Cylinders │ 5.47194 │ 4.0 │ 1.70578 │
7-
│ 3 │ Displacement │ 194.412 │ 151.0 │ 104.644 │
8-
│ 4 │ Horsepower │ 104.469 │ 93.5 │ 38.4912 │
9-
│ 5 │ Weight │ 2977.58 │ 2803.5 │ 849.403 │
10-
│ 6 │ Acceleration │ 15.5413 │ 15.5 │ 2.75886 │
11-
│ 7 │ Year │ 75.9796 │ 76.0 │ 3.68374 │
12-
│ 8 │ Origin │ 1.57653 │ 1.0 │ 0.805518 │
13-
│ 9 │ Name │ │ │ │
1+
DataFrames.DataFrame(AbstractArray{T,1} where T[[:MPG, :Cylinders, :Displacement, :Horsepower, :Weight, :Acceleration, :Year, :Origin, :Name], Union{Nothing, Float64}[23.44591836734694, 5.471938775510204, 194.41198979591837, 104.46938775510205, 2977.5841836734694, 15.541326530612247, 75.9795918367347, 1.5765306122448979, nothing], Union{Nothing, Float64}[22.75, 4.0, 151.0, 93.5, 2803.5, 15.5, 76.0, 1.0, nothing], Union{Nothing, Float64}[7.8050074865717995, 1.7057832474527845, 104.64400390890465, 38.49115993282848, 849.4025600429493, 2.758864119188082, 3.6837365435778295, 0.8055181834183056, nothing]], DataFrames.Index(Dict(:std => 4,:variable => 1,:mean => 2,:median => 3), [:variable, :mean, :median, :std]))

pub/isl/lab-2.html

+6-22
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<pre><code class="julia hljs">x = randn(<span class=hljs-number >1_000</span>) <span class=hljs-comment ># 1_000 points iid from a N(0, 1)</span>
2828
μ = mean(x)
2929
σ = std(x)
30-
<span class=hljs-meta >@show</span> (μ, σ)</code></pre><div class=code_output ><pre><code class="plaintext hljs">(μ, σ) = (-0.003429405251489602, 1.0011574237294552)
30+
<span class=hljs-meta >@show</span> (μ, σ)</code></pre><div class=code_output ><pre><code class="plaintext hljs">(μ, σ) = (0.028927854346407975, 1.0322439340512704)
3131
</code></pre></div>
3232
<p>Indexing data starts at 1, use <code>:</code> to indicate the full range</p>
3333
<pre><code class="julia hljs">X = [<span class=hljs-number >1</span> <span class=hljs-number >2</span>; <span class=hljs-number >3</span> <span class=hljs-number >4</span>; <span class=hljs-number >5</span> <span class=hljs-number >6</span>]
@@ -50,27 +50,9 @@ <h2 id=loading_data ><a href="/MLJTutorials/pub/isl/lab-2.html#loading_data">Loa
5050
<pre><code class="julia hljs"><span class=hljs-keyword >using</span> DataFrames</code></pre>
5151
<p>Let&#39;s load some data from RDatasets &#40;the full list of datasets is available <a href="http://vincentarelbundock.github.io/Rdatasets/datasets.html">here</a>&#41;.</p>
5252
<pre><code class="julia hljs">auto = dataset(<span class=hljs-string >"ISLR"</span>, <span class=hljs-string >"Auto"</span>)
53-
first(auto, <span class=hljs-number >3</span>)</code></pre><div class=code_output ><pre><code class="plaintext hljs">3×9 DataFrame
54-
│ Row │ MPG │ Cylinders │ Displacement │ Horsepower │ Weight │ Acceleration │ Year │ Origin │ Name │
55-
│ │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │ String │
56-
├─────┼─────────┼───────────┼──────────────┼────────────┼─────────┼──────────────┼─────────┼─────────┼───────────────────────────┤
57-
│ 1 │ 18.0 │ 8.0 │ 307.0 │ 130.0 │ 3504.0 │ 12.0 │ 70.0 │ 1.0 │ chevrolet chevelle malibu │
58-
│ 2 │ 15.0 │ 8.0 │ 350.0 │ 165.0 │ 3693.0 │ 11.5 │ 70.0 │ 1.0 │ buick skylark 320 │
59-
│ 3 │ 18.0 │ 8.0 │ 318.0 │ 150.0 │ 3436.0 │ 11.0 │ 70.0 │ 1.0 │ plymouth satellite │</code></pre></div>
53+
first(auto, <span class=hljs-number >3</span>)</code></pre><div class=code_output ><pre><code class="plaintext hljs">DataFrames.DataFrame(AbstractArray{T,1} where T[[18.0, 15.0, 18.0], [8.0, 8.0, 8.0], [307.0, 350.0, 318.0], [130.0, 165.0, 150.0], [3504.0, 3693.0, 3436.0], [12.0, 11.5, 11.0], [70.0, 70.0, 70.0], [1.0, 1.0, 1.0], ["chevrolet chevelle malibu", "buick skylark 320", "plymouth satellite"]], DataFrames.Index(Dict(:Cylinders =&gt; 2,:Horsepower =&gt; 4,:MPG =&gt; 1,:Displacement =&gt; 3,:Origin =&gt; 8,:Year =&gt; 7,:Acceleration =&gt; 6,:Weight =&gt; 5,:Name =&gt; 9), [:MPG, :Cylinders, :Displacement, :Horsepower, :Weight, :Acceleration, :Year, :Origin, :Name]))</code></pre></div>
6054
<p>The <code>describe</code> function allows to get an idea for the data:</p>
61-
<pre><code class="julia hljs">describe(auto, :mean, :median, :std)</code></pre><div class=code_output ><pre><code class="plaintext hljs">9×4 DataFrame
62-
│ Row │ variable │ mean │ median │ std │
63-
│ │ Symbol │ Union… │ Union… │ Union… │
64-
├─────┼──────────────┼─────────┼────────┼──────────┤
65-
│ 1 │ MPG │ 23.4459 │ 22.75 │ 7.80501 │
66-
│ 2 │ Cylinders │ 5.47194 │ 4.0 │ 1.70578 │
67-
│ 3 │ Displacement │ 194.412 │ 151.0 │ 104.644 │
68-
│ 4 │ Horsepower │ 104.469 │ 93.5 │ 38.4912 │
69-
│ 5 │ Weight │ 2977.58 │ 2803.5 │ 849.403 │
70-
│ 6 │ Acceleration │ 15.5413 │ 15.5 │ 2.75886 │
71-
│ 7 │ Year │ 75.9796 │ 76.0 │ 3.68374 │
72-
│ 8 │ Origin │ 1.57653 │ 1.0 │ 0.805518 │
73-
│ 9 │ Name │ │ │ │</code></pre></div>
55+
<pre><code class="julia hljs">describe(auto, :mean, :median, :std)</code></pre><div class=code_output ><pre><code class="plaintext hljs">DataFrames.DataFrame(AbstractArray{T,1} where T[[:MPG, :Cylinders, :Displacement, :Horsepower, :Weight, :Acceleration, :Year, :Origin, :Name], Union{Nothing, Float64}[23.44591836734694, 5.471938775510204, 194.41198979591837, 104.46938775510205, 2977.5841836734694, 15.541326530612247, 75.9795918367347, 1.5765306122448979, nothing], Union{Nothing, Float64}[22.75, 4.0, 151.0, 93.5, 2803.5, 15.5, 76.0, 1.0, nothing], Union{Nothing, Float64}[7.8050074865717995, 1.7057832474527845, 104.64400390890465, 38.49115993282848, 849.4025600429493, 2.758864119188082, 3.6837365435778295, 0.8055181834183056, nothing]], DataFrames.Index(Dict(:std =&gt; 4,:variable =&gt; 1,:mean =&gt; 2,:median =&gt; 3), [:variable, :mean, :median, :std]))</code></pre></div>
7456
<p>To retrieve column names, you can use <code>names</code>:</p>
7557
<pre><code class="julia hljs">names(auto)</code></pre><div class=code_output ><pre><code class="plaintext hljs">9-element Array{Symbol,1}:
7658
:MPG
@@ -118,7 +100,9 @@ <h2 id=plotting_data ><a href="/MLJTutorials/pub/isl/lab-2.html#plotting_data">P
118100

119101
</ul>
120102
<p>In these tutorials we use <code>PyPlot</code> but you could use another package of course.</p>
121-
<pre><code class="julia hljs">figure(figsize=(<span class=hljs-number >8</span>,<span class=hljs-number >6</span>))
103+
<pre><code class="julia hljs"><span class=hljs-keyword >using</span> PyPlot
104+
105+
figure(figsize=(<span class=hljs-number >8</span>,<span class=hljs-number >6</span>))
122106
plot(mpg)
123107
</code></pre>
124108
<p><img src="/MLJTutorials/assets/literate/ISL-lab-2-mpg.svg" alt="" />

scripts/ISL-lab-2.jl

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ mpg |> mean
124124
#
125125
# In these tutorials we use `PyPlot` but you could use another package of course.
126126

127+
using PyPlot
128+
127129
figure(figsize=(8,6))
128130
plot(mpg)
129131

0 commit comments

Comments
 (0)