From 584f6698f3598da79b616c3de2c8a7016dbd42b1 Mon Sep 17 00:00:00 2001 From: Thibaut Lienart Date: Wed, 20 Nov 2019 19:07:02 +0100 Subject: [PATCH] need using Pyplot in ISL2 --- assets/literate/ISL-lab-2-mpg.svg | 42 ++++++++++----------- assets/literate/ISL-lab-2.md | 2 + assets/literate/ISL-lab-2_script.jl | 2 + assets/pages/isl/lab-2/code/ex21.jl | 2 + assets/pages/isl/lab-2/code/output/ex10.out | 2 +- assets/pages/isl/lab-2/code/output/ex10.res | 2 +- assets/pages/isl/lab-2/code/output/ex16.res | 8 +--- assets/pages/isl/lab-2/code/output/ex17.res | 14 +------ pub/isl/lab-2.html | 28 +++----------- scripts/ISL-lab-2.jl | 2 + 10 files changed, 39 insertions(+), 65 deletions(-) diff --git a/assets/literate/ISL-lab-2-mpg.svg b/assets/literate/ISL-lab-2-mpg.svg index d9ddecd0..709d3efb 100644 --- a/assets/literate/ISL-lab-2-mpg.svg +++ b/assets/literate/ISL-lab-2-mpg.svg @@ -32,10 +32,10 @@ z +" id="mfd0cdb710f" style="stroke:#000000;stroke-width:0.8;"/> - + @@ -71,7 +71,7 @@ z - + @@ -111,7 +111,7 @@ z - + @@ -141,7 +141,7 @@ z - + @@ -156,7 +156,7 @@ z - + @@ -197,7 +197,7 @@ z - + @@ -212,7 +212,7 @@ z - + @@ -261,7 +261,7 @@ z - + @@ -276,7 +276,7 @@ z - + @@ -314,10 +314,10 @@ z +" id="m3d1310ddbb" style="stroke:#000000;stroke-width:0.8;"/> - + @@ -331,7 +331,7 @@ L -3.5 0 - + @@ -345,7 +345,7 @@ L -3.5 0 - + @@ -359,7 +359,7 @@ L -3.5 0 - + @@ -373,7 +373,7 @@ L -3.5 0 - + @@ -387,7 +387,7 @@ L -3.5 0 - + @@ -401,7 +401,7 @@ L -3.5 0 - + @@ -415,7 +415,7 @@ L -3.5 0 - + @@ -428,7 +428,7 @@ L -3.5 0 - + diff --git a/assets/literate/ISL-lab-2.md b/assets/literate/ISL-lab-2.md index 66eb2887..0237cdea 100644 --- a/assets/literate/ISL-lab-2.md +++ b/assets/literate/ISL-lab-2.md @@ -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) diff --git a/assets/literate/ISL-lab-2_script.jl b/assets/literate/ISL-lab-2_script.jl index 100785e3..f0446c47 100644 --- a/assets/literate/ISL-lab-2_script.jl +++ b/assets/literate/ISL-lab-2_script.jl @@ -58,6 +58,8 @@ mpg |> mean @show nrow(auto) @show ncol(auto) +using PyPlot + figure(figsize=(8,6)) plot(mpg) diff --git a/assets/pages/isl/lab-2/code/ex21.jl b/assets/pages/isl/lab-2/code/ex21.jl index db47ebe7..7ff0873d 100644 --- a/assets/pages/isl/lab-2/code/ex21.jl +++ b/assets/pages/isl/lab-2/code/ex21.jl @@ -1,4 +1,6 @@ # This file was generated, do not modify it. # hide +using PyPlot + figure(figsize=(8,6)) plot(mpg) diff --git a/assets/pages/isl/lab-2/code/output/ex10.out b/assets/pages/isl/lab-2/code/output/ex10.out index e67bb609..0adf5cfa 100644 --- a/assets/pages/isl/lab-2/code/output/ex10.out +++ b/assets/pages/isl/lab-2/code/output/ex10.out @@ -1 +1 @@ -(μ, σ) = (-0.003429405251489602, 1.0011574237294552) +(μ, σ) = (0.028927854346407975, 1.0322439340512704) diff --git a/assets/pages/isl/lab-2/code/output/ex10.res b/assets/pages/isl/lab-2/code/output/ex10.res index 41426c56..681a643f 100644 --- a/assets/pages/isl/lab-2/code/output/ex10.res +++ b/assets/pages/isl/lab-2/code/output/ex10.res @@ -1 +1 @@ -(-0.003429405251489602, 1.0011574237294552) \ No newline at end of file +(0.028927854346407975, 1.0322439340512704) \ No newline at end of file diff --git a/assets/pages/isl/lab-2/code/output/ex16.res b/assets/pages/isl/lab-2/code/output/ex16.res index 4a521ea6..ea8c99fc 100644 --- a/assets/pages/isl/lab-2/code/output/ex16.res +++ b/assets/pages/isl/lab-2/code/output/ex16.res @@ -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 │ \ No newline at end of file +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])) \ No newline at end of file diff --git a/assets/pages/isl/lab-2/code/output/ex17.res b/assets/pages/isl/lab-2/code/output/ex17.res index d6c49438..24bc2d2b 100644 --- a/assets/pages/isl/lab-2/code/output/ex17.res +++ b/assets/pages/isl/lab-2/code/output/ex17.res @@ -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 │ │ │ │ \ No newline at end of file +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])) \ No newline at end of file diff --git a/pub/isl/lab-2.html b/pub/isl/lab-2.html index 097fa8c5..20f6bc2b 100644 --- a/pub/isl/lab-2.html +++ b/pub/isl/lab-2.html @@ -27,7 +27,7 @@
x = randn(1_000) # 1_000 points iid from a N(0, 1)
 μ = mean(x)
 σ = std(x)
-@show (μ, σ)
(μ, σ) = (-0.003429405251489602, 1.0011574237294552)
+@show (μ, σ)
(μ, σ) = (0.028927854346407975, 1.0322439340512704)
 

Indexing data starts at 1, use : to indicate the full range

X = [1 2; 3 4; 5 6]
@@ -50,27 +50,9 @@ 

Loa
using DataFrames

Let's load some data from RDatasets (the full list of datasets is available here).

auto = dataset("ISLR", "Auto")
-first(auto, 3)
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        │
+first(auto, 3)

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]))

The describe function allows to get an idea for the data:

-
describe(auto, :mean, :median, :std)
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         │         │        │          │
+
describe(auto, :mean, :median, :std)
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]))

To retrieve column names, you can use names:

names(auto)