Skip to content

Commit

Permalink
need using Pyplot in ISL2
Browse files Browse the repository at this point in the history
  • Loading branch information
tlienart committed Nov 20, 2019
1 parent 5c5d08f commit 584f669
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 65 deletions.
42 changes: 21 additions & 21 deletions assets/literate/ISL-lab-2-mpg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions assets/literate/ISL-lab-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ There are multiple libraries that can be used to plot things in Julia:
In these tutorials we use `PyPlot` but you could use another package of course.

```julia:ex21
using PyPlot
figure(figsize=(8,6))
plot(mpg)
Expand Down
2 changes: 2 additions & 0 deletions assets/literate/ISL-lab-2_script.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ mpg |> mean
@show nrow(auto)
@show ncol(auto)

using PyPlot

figure(figsize=(8,6))
plot(mpg)

Expand Down
2 changes: 2 additions & 0 deletions assets/pages/isl/lab-2/code/ex21.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# This file was generated, do not modify it. # hide
using PyPlot

figure(figsize=(8,6))
plot(mpg)

Expand Down
2 changes: 1 addition & 1 deletion assets/pages/isl/lab-2/code/output/ex10.out
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(μ, σ) = (-0.003429405251489602, 1.0011574237294552)
(μ, σ) = (0.028927854346407975, 1.0322439340512704)
2 changes: 1 addition & 1 deletion assets/pages/isl/lab-2/code/output/ex10.res
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(-0.003429405251489602, 1.0011574237294552)
(0.028927854346407975, 1.0322439340512704)
8 changes: 1 addition & 7 deletions assets/pages/isl/lab-2/code/output/ex16.res
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
3×9 DataFrame
│ Row │ MPG │ Cylinders │ Displacement │ Horsepower │ Weight │ Acceleration │ Year │ Origin │ Name │
│ │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │ String │
├─────┼─────────┼───────────┼──────────────┼────────────┼─────────┼──────────────┼─────────┼─────────┼───────────────────────────┤
│ 1 │ 18.0 │ 8.0 │ 307.0 │ 130.0 │ 3504.0 │ 12.0 │ 70.0 │ 1.0 │ chevrolet chevelle malibu │
│ 2 │ 15.0 │ 8.0 │ 350.0 │ 165.0 │ 3693.0 │ 11.5 │ 70.0 │ 1.0 │ buick skylark 320 │
│ 3 │ 18.0 │ 8.0 │ 318.0 │ 150.0 │ 3436.0 │ 11.0 │ 70.0 │ 1.0 │ plymouth satellite │
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]))
14 changes: 1 addition & 13 deletions assets/pages/isl/lab-2/code/output/ex17.res
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
9×4 DataFrame
│ Row │ variable │ mean │ median │ std │
│ │ Symbol │ Union… │ Union… │ Union… │
├─────┼──────────────┼─────────┼────────┼──────────┤
│ 1 │ MPG │ 23.4459 │ 22.75 │ 7.80501 │
│ 2 │ Cylinders │ 5.47194 │ 4.0 │ 1.70578 │
│ 3 │ Displacement │ 194.412 │ 151.0 │ 104.644 │
│ 4 │ Horsepower │ 104.469 │ 93.5 │ 38.4912 │
│ 5 │ Weight │ 2977.58 │ 2803.5 │ 849.403 │
│ 6 │ Acceleration │ 15.5413 │ 15.5 │ 2.75886 │
│ 7 │ Year │ 75.9796 │ 76.0 │ 3.68374 │
│ 8 │ Origin │ 1.57653 │ 1.0 │ 0.805518 │
│ 9 │ Name │ │ │ │
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]))
28 changes: 6 additions & 22 deletions pub/isl/lab-2.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<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>
μ = mean(x)
σ = std(x)
<span class=hljs-meta >@show</span> (μ, σ)</code></pre><div class=code_output ><pre><code class="plaintext hljs">(μ, σ) = (-0.003429405251489602, 1.0011574237294552)
<span class=hljs-meta >@show</span> (μ, σ)</code></pre><div class=code_output ><pre><code class="plaintext hljs">(μ, σ) = (0.028927854346407975, 1.0322439340512704)
</code></pre></div>
<p>Indexing data starts at 1, use <code>:</code> to indicate the full range</p>
<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>]
Expand All @@ -50,27 +50,9 @@ <h2 id=loading_data ><a href="/MLJTutorials/pub/isl/lab-2.html#loading_data">Loa
<pre><code class="julia hljs"><span class=hljs-keyword >using</span> DataFrames</code></pre>
<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>
<pre><code class="julia hljs">auto = dataset(<span class=hljs-string >"ISLR"</span>, <span class=hljs-string >"Auto"</span>)
first(auto, <span class=hljs-number >3</span>)</code></pre><div class=code_output ><pre><code class="plaintext hljs">3×9 DataFrame
│ Row │ MPG │ Cylinders │ Displacement │ Horsepower │ Weight │ Acceleration │ Year │ Origin │ Name │
│ │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │ Float64 │ String │
├─────┼─────────┼───────────┼──────────────┼────────────┼─────────┼──────────────┼─────────┼─────────┼───────────────────────────┤
│ 1 │ 18.0 │ 8.0 │ 307.0 │ 130.0 │ 3504.0 │ 12.0 │ 70.0 │ 1.0 │ chevrolet chevelle malibu │
│ 2 │ 15.0 │ 8.0 │ 350.0 │ 165.0 │ 3693.0 │ 11.5 │ 70.0 │ 1.0 │ buick skylark 320 │
│ 3 │ 18.0 │ 8.0 │ 318.0 │ 150.0 │ 3436.0 │ 11.0 │ 70.0 │ 1.0 │ plymouth satellite │</code></pre></div>
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>
<p>The <code>describe</code> function allows to get an idea for the data:</p>
<pre><code class="julia hljs">describe(auto, :mean, :median, :std)</code></pre><div class=code_output ><pre><code class="plaintext hljs">9×4 DataFrame
│ Row │ variable │ mean │ median │ std │
│ │ Symbol │ Union… │ Union… │ Union… │
├─────┼──────────────┼─────────┼────────┼──────────┤
│ 1 │ MPG │ 23.4459 │ 22.75 │ 7.80501 │
│ 2 │ Cylinders │ 5.47194 │ 4.0 │ 1.70578 │
│ 3 │ Displacement │ 194.412 │ 151.0 │ 104.644 │
│ 4 │ Horsepower │ 104.469 │ 93.5 │ 38.4912 │
│ 5 │ Weight │ 2977.58 │ 2803.5 │ 849.403 │
│ 6 │ Acceleration │ 15.5413 │ 15.5 │ 2.75886 │
│ 7 │ Year │ 75.9796 │ 76.0 │ 3.68374 │
│ 8 │ Origin │ 1.57653 │ 1.0 │ 0.805518 │
│ 9 │ Name │ │ │ │</code></pre></div>
<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>
<p>To retrieve column names, you can use <code>names</code>:</p>
<pre><code class="julia hljs">names(auto)</code></pre><div class=code_output ><pre><code class="plaintext hljs">9-element Array{Symbol,1}:
:MPG
Expand Down Expand Up @@ -118,7 +100,9 @@ <h2 id=plotting_data ><a href="/MLJTutorials/pub/isl/lab-2.html#plotting_data">P

</ul>
<p>In these tutorials we use <code>PyPlot</code> but you could use another package of course.</p>
<pre><code class="julia hljs">figure(figsize=(<span class=hljs-number >8</span>,<span class=hljs-number >6</span>))
<pre><code class="julia hljs"><span class=hljs-keyword >using</span> PyPlot

figure(figsize=(<span class=hljs-number >8</span>,<span class=hljs-number >6</span>))
plot(mpg)
</code></pre>
<p><img src="/MLJTutorials/assets/literate/ISL-lab-2-mpg.svg" alt="" />
Expand Down
2 changes: 2 additions & 0 deletions scripts/ISL-lab-2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ mpg |> mean
#
# In these tutorials we use `PyPlot` but you could use another package of course.

using PyPlot

figure(figsize=(8,6))
plot(mpg)

Expand Down

0 comments on commit 584f669

Please sign in to comment.