From 4fbf5dc04a15cbaf8029446a6811552f86af3f1e Mon Sep 17 00:00:00 2001 From: math4mad Date: Fri, 3 Nov 2023 14:55:54 +0800 Subject: [PATCH] minor modify minor modify --- .../execute-results/html.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/_freeze/category/classification/3-recognizing-handwriting-digits/execute-results/html.json b/_freeze/category/classification/3-recognizing-handwriting-digits/execute-results/html.json index 811fd78..ab3b3ba 100644 --- a/_freeze/category/classification/3-recognizing-handwriting-digits/execute-results/html.json +++ b/_freeze/category/classification/3-recognizing-handwriting-digits/execute-results/html.json @@ -1,9 +1,9 @@ { - "hash": "dc5c07a1d428acb02815231925667cd2", + "hash": "a8aec3f8fdaf1a1001a57c9bec312be3", "result": { - "markdown": "---\ntitle: \"2-recognizing-handwriting-digits\"\ncode-fold: false\n---\n\n:::{.callout-note title=\"info\"}\n1. ref:scikit-learn-docs/auto_examples/classification/plot_digits_classification.html#sphx-glr-auto-examples-classification-plot-digits-classification-py\n2. data-processing:load-scikit-digits.jl ->csv\n:::\n\n\n## 1. load package\n\n::: {.cell execution_count=1}\n``` {.julia .cell-code}\n import MLJ:fit!,predict\n using CSV,DataFrames,GLMakie,Random\n using MLJ\n Random.seed!(34343)\n```\n\n::: {.cell-output .cell-output-display execution_count=8}\n```\nTaskLocalRNG()\n```\n:::\n:::\n\n\n## 2. load data\n\n::: {.cell execution_count=2}\n``` {.julia .cell-code}\n load_csv(str::AbstractString) =\n str |> d -> CSV.File(\"./data/$str.csv\") |> DataFrame |> dropmissing\n\n digits = load_csv(\"scikit_digits\")\n digits = coerce(digits, :target => Multiclass)\n y, X = unpack(digits, ==(:target); rng = 123);\n (Xtrain, Xtest), (ytrain, ytest) = partition((X, y), 0.6, multi=true, rng=123)\n```\n\n::: {.cell-output .cell-output-display execution_count=9}\n\n::: {.ansi-escaped-output}\n```{=html}\n
((1078×64 DataFrame\n  Row  x1       x2       x3       x4       x5       x6       x7       x8      ⋯\n      │ Float64  Float64  Float64  Float64  Float64  Float64  Float64  Float64 ⋯\n──────┼─────────────────────────────────────────────────────────────────────────\n    1 │     0.0      0.0     10.0     15.0      1.0      0.0      0.0      0.0 ⋯\n    2 │     0.0      0.0      4.0     12.0     16.0     14.0      7.0      0.0\n    3 │     0.0      0.0      2.0     10.0     15.0      1.0      0.0      0.0\n    4 │     0.0      0.0     11.0     16.0     16.0     12.0      0.0      0.0\n    5 │     0.0      0.0      5.0     15.0     12.0      4.0      0.0      0.0 ⋯\n    6 │     0.0      1.0     11.0     15.0     16.0      9.0      0.0      0.0\n    7 │     0.0      1.0     10.0     15.0     15.0      3.0      0.0      0.0\n    8 │     0.0      0.0      8.0     14.0      1.0      0.0      0.0      0.0\n    9 │     0.0      3.0     15.0     16.0     14.0      1.0      0.0      0.0 ⋯\n   10 │     0.0      0.0      2.0     12.0     14.0      4.0      0.0      0.0\n   11 │     0.0      0.0      3.0     14.0      9.0      3.0      0.0      0.0\n  ⋮   │    ⋮        ⋮        ⋮        ⋮        ⋮        ⋮        ⋮        ⋮    ⋱\n 1069 │     0.0      0.0      7.0     16.0     15.0      4.0      0.0      0.0\n 1070 │     0.0      0.0      0.0      9.0     16.0      9.0      0.0      0.0 ⋯\n 1071 │     0.0      0.0      0.0      3.0     16.0      3.0      0.0      0.0\n 1072 │     0.0      0.0      5.0      8.0     11.0      5.0      0.0      0.0\n 1073 │     0.0      2.0      9.0     15.0     14.0      9.0      3.0      0.0\n 1074 │     0.0      1.0     12.0     16.0     13.0      7.0      0.0      0.0 ⋯\n 1075 │     0.0      0.0      0.0      2.0     16.0      3.0      0.0      0.0\n 1076 │     0.0      0.0     14.0     16.0     15.0      3.0      0.0      0.0\n 1077 │     0.0      0.0      2.0     11.0     15.0      2.0      0.0      0.0\n 1078 │     0.0      0.0      0.0      4.0     15.0      6.0      0.0      0.0 ⋯\n                                                56 columns and 1057 rows omitted, 719×64 DataFrame\n Row  x1       x2       x3       x4       x5       x6       x7       x8       ⋯\n     │ Float64  Float64  Float64  Float64  Float64  Float64  Float64  Float64  ⋯\n─────┼──────────────────────────────────────────────────────────────────────────\n   1 │     0.0      0.0      3.0     12.0      3.0      0.0      0.0      0.0  ⋯\n   2 │     0.0      0.0      1.0     12.0     14.0      3.0      0.0      0.0\n   3 │     0.0      0.0      8.0     13.0     11.0      1.0      0.0      0.0\n   4 │     0.0      0.0      2.0     13.0      0.0      0.0      0.0      0.0\n   5 │     0.0      1.0     13.0     16.0     16.0     12.0      1.0      0.0  ⋯\n   6 │     0.0      0.0      7.0     16.0     13.0      2.0      0.0      0.0\n   7 │     0.0      0.0     11.0     16.0      9.0      8.0      0.0      0.0\n   8 │     0.0      0.0      0.0      1.0      9.0     14.0      7.0      0.0\n   9 │     0.0      0.0      7.0     15.0     16.0     16.0      1.0      0.0  ⋯\n  10 │     0.0      0.0      5.0     10.0     14.0     16.0     11.0      0.0\n  11 │     0.0      0.0      7.0     16.0     16.0     16.0      6.0      0.0\n  ⋮  │    ⋮        ⋮        ⋮        ⋮        ⋮        ⋮        ⋮        ⋮     ⋱\n 710 │     0.0      1.0      9.0     16.0     16.0     15.0      3.0      0.0\n 711 │     0.0      0.0      1.0     15.0      7.0      0.0      0.0      0.0  ⋯\n 712 │     0.0      0.0      6.0     14.0     13.0      4.0      0.0      0.0\n 713 │     0.0      0.0      2.0     13.0     14.0      6.0      0.0      0.0\n 714 │     0.0      0.0      2.0     12.0     10.0      0.0      0.0      0.0\n 715 │     0.0      0.0      2.0     14.0     15.0      4.0      0.0      0.0  ⋯\n 716 │     0.0      0.0      3.0     10.0     14.0      3.0      0.0      0.0\n 717 │     0.0      0.0      7.0     16.0     15.0      4.0      0.0      0.0\n 718 │     0.0      0.0      6.0     15.0     14.0      2.0      0.0      0.0\n 719 │     0.0      0.0      5.0     16.0     12.0      2.0      0.0      0.0  ⋯\n                                                 56 columns and 698 rows omitted), (CategoricalArrays.CategoricalValue{Int64, UInt32}[1, 3, 0, 9, 0, 3, 9, 1, 2, 0  …  5, 8, 4, 0, 3, 3, 4, 3, 0, 4], CategoricalArrays.CategoricalValue{Int64, UInt32}[6, 0, 3, 6, 3, 2, 8, 9, 5, 5  …  5, 4, 8, 8, 2, 1, 9, 0, 3, 0]))
\n```\n:::\n\n:::\n:::\n\n\n## 3. MLJ workflow\n\n::: {.cell execution_count=3}\n``` {.julia .cell-code}\nSVC = @load SVC pkg=LIBSVM\n model=SVC()\n mach = machine(model, Xtrain, ytrain)|>fit!\n yhat = predict(mach, Xtest)\n @info \"accuracy\"=>accuracy(ytest,yhat)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nimport MLJLIBSVMInterface ✔\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\n[ Info: For silent loading, specify `verbosity=0`. \n[ Info: Training machine(SVC(kernel = RadialBasis, …), …).\n[ Info: \"accuracy\" => 0.9860917941585535\n```\n:::\n:::\n\n\n## 4. plot results\n\n:::{.callout-tip title=\"makie plot image\"}\n 1. reshape to image matrix `img=Xtest[pick,:]|>Vector|>d->reshape(d,8,8)`\n 2. sometimes need rotl `load(patharr[num])|>rotl90`\n 3. sometimes need yreversed=true `local ax = Axis(fig[i, j],yreversed=true)`\n \n:::\n\n::: {.cell execution_count=4}\n``` {.julia .cell-code}\n function plot_res()\n fig=Figure()\n #rand pick 15 origin picture of digits\n picks=rand(1:length(Vector(ytest)),15)\n for (idx,pick) in enumerate(picks)\n \n ax=Axis(fig[fldmod1(idx,5)...];title=\"pred:$(yhat[pick])\",yreversed=true)\n img=Xtest[pick,:]|>Vector|>d->reshape(d,8,8)\n image!(ax,img)\n hidedecorations!(ax)\n end\n fig\n end\n\n fig=plot_res()\n```\n\n::: {.cell-output .cell-output-display execution_count=11}\n![](3-recognizing-handwriting-digits_files/figure-html/cell-5-output-1.png){}\n:::\n:::\n\n\n", + "markdown": "---\ntitle: \"2-recognizing-handwriting-digits\"\ncode-fold: false\n---\n\n:::{.callout-note title=\"info\"}\n1. ref:scikit-learn-docs/auto_examples/classification/plot_digits_classification.html#sphx-glr-auto-examples-classification-plot-digits-classification-py\n2. data-processing:load-scikit-digits.jl ->csv\n:::\n\n\n## 1. load package\n\n::: {.cell execution_count=1}\n``` {.julia .cell-code}\n import MLJ:fit!,predict\n using CSV,DataFrames,GLMakie,Random\n using MLJ\n Random.seed!(34343)\n```\n\n::: {.cell-output .cell-output-display execution_count=2}\n```\nTaskLocalRNG()\n```\n:::\n:::\n\n\n## 2. load data\n\n::: {.cell execution_count=2}\n``` {.julia .cell-code}\n load_csv(str::AbstractString) =\n str |> d -> CSV.File(\"./data/$str.csv\") |> DataFrame |> dropmissing\n\n digits = load_csv(\"scikit_digits\")\n digits = coerce(digits, :target => Multiclass)\n y, X = unpack(digits, ==(:target); rng = 123);\n (Xtrain, Xtest), (ytrain, ytest) = partition((X, y), 0.6, multi=true, rng=123)\n```\n\n::: {.cell-output .cell-output-display execution_count=3}\n\n::: {.ansi-escaped-output}\n```{=html}\n
((1078×64 DataFrame\n  Row  x1       x2       x3       x4       x5       x6       x7       x8      ⋯\n      │ Float64  Float64  Float64  Float64  Float64  Float64  Float64  Float64 ⋯\n──────┼─────────────────────────────────────────────────────────────────────────\n    1 │     0.0      0.0     10.0     15.0      1.0      0.0      0.0      0.0 ⋯\n    2 │     0.0      0.0      4.0     12.0     16.0     14.0      7.0      0.0\n    3 │     0.0      0.0      2.0     10.0     15.0      1.0      0.0      0.0\n    4 │     0.0      0.0     11.0     16.0     16.0     12.0      0.0      0.0\n    5 │     0.0      0.0      5.0     15.0     12.0      4.0      0.0      0.0 ⋯\n    6 │     0.0      1.0     11.0     15.0     16.0      9.0      0.0      0.0\n    7 │     0.0      1.0     10.0     15.0     15.0      3.0      0.0      0.0\n    8 │     0.0      0.0      8.0     14.0      1.0      0.0      0.0      0.0\n    9 │     0.0      3.0     15.0     16.0     14.0      1.0      0.0      0.0 ⋯\n   10 │     0.0      0.0      2.0     12.0     14.0      4.0      0.0      0.0\n   11 │     0.0      0.0      3.0     14.0      9.0      3.0      0.0      0.0\n  ⋮   │    ⋮        ⋮        ⋮        ⋮        ⋮        ⋮        ⋮        ⋮    ⋱\n 1069 │     0.0      0.0      7.0     16.0     15.0      4.0      0.0      0.0\n 1070 │     0.0      0.0      0.0      9.0     16.0      9.0      0.0      0.0 ⋯\n 1071 │     0.0      0.0      0.0      3.0     16.0      3.0      0.0      0.0\n 1072 │     0.0      0.0      5.0      8.0     11.0      5.0      0.0      0.0\n 1073 │     0.0      2.0      9.0     15.0     14.0      9.0      3.0      0.0\n 1074 │     0.0      1.0     12.0     16.0     13.0      7.0      0.0      0.0 ⋯\n 1075 │     0.0      0.0      0.0      2.0     16.0      3.0      0.0      0.0\n 1076 │     0.0      0.0     14.0     16.0     15.0      3.0      0.0      0.0\n 1077 │     0.0      0.0      2.0     11.0     15.0      2.0      0.0      0.0\n 1078 │     0.0      0.0      0.0      4.0     15.0      6.0      0.0      0.0 ⋯\n                                                56 columns and 1057 rows omitted, 719×64 DataFrame\n Row  x1       x2       x3       x4       x5       x6       x7       x8       ⋯\n     │ Float64  Float64  Float64  Float64  Float64  Float64  Float64  Float64  ⋯\n─────┼──────────────────────────────────────────────────────────────────────────\n   1 │     0.0      0.0      3.0     12.0      3.0      0.0      0.0      0.0  ⋯\n   2 │     0.0      0.0      1.0     12.0     14.0      3.0      0.0      0.0\n   3 │     0.0      0.0      8.0     13.0     11.0      1.0      0.0      0.0\n   4 │     0.0      0.0      2.0     13.0      0.0      0.0      0.0      0.0\n   5 │     0.0      1.0     13.0     16.0     16.0     12.0      1.0      0.0  ⋯\n   6 │     0.0      0.0      7.0     16.0     13.0      2.0      0.0      0.0\n   7 │     0.0      0.0     11.0     16.0      9.0      8.0      0.0      0.0\n   8 │     0.0      0.0      0.0      1.0      9.0     14.0      7.0      0.0\n   9 │     0.0      0.0      7.0     15.0     16.0     16.0      1.0      0.0  ⋯\n  10 │     0.0      0.0      5.0     10.0     14.0     16.0     11.0      0.0\n  11 │     0.0      0.0      7.0     16.0     16.0     16.0      6.0      0.0\n  ⋮  │    ⋮        ⋮        ⋮        ⋮        ⋮        ⋮        ⋮        ⋮     ⋱\n 710 │     0.0      1.0      9.0     16.0     16.0     15.0      3.0      0.0\n 711 │     0.0      0.0      1.0     15.0      7.0      0.0      0.0      0.0  ⋯\n 712 │     0.0      0.0      6.0     14.0     13.0      4.0      0.0      0.0\n 713 │     0.0      0.0      2.0     13.0     14.0      6.0      0.0      0.0\n 714 │     0.0      0.0      2.0     12.0     10.0      0.0      0.0      0.0\n 715 │     0.0      0.0      2.0     14.0     15.0      4.0      0.0      0.0  ⋯\n 716 │     0.0      0.0      3.0     10.0     14.0      3.0      0.0      0.0\n 717 │     0.0      0.0      7.0     16.0     15.0      4.0      0.0      0.0\n 718 │     0.0      0.0      6.0     15.0     14.0      2.0      0.0      0.0\n 719 │     0.0      0.0      5.0     16.0     12.0      2.0      0.0      0.0  ⋯\n                                                 56 columns and 698 rows omitted), (CategoricalArrays.CategoricalValue{Int64, UInt32}[1, 3, 0, 9, 0, 3, 9, 1, 2, 0  …  5, 8, 4, 0, 3, 3, 4, 3, 0, 4], CategoricalArrays.CategoricalValue{Int64, UInt32}[6, 0, 3, 6, 3, 2, 8, 9, 5, 5  …  5, 4, 8, 8, 2, 1, 9, 0, 3, 0]))
\n```\n:::\n\n:::\n:::\n\n\n## 3. MLJ workflow\n\n::: {.cell execution_count=3}\n``` {.julia .cell-code}\nSVC = @load SVC pkg=LIBSVM\n model=SVC()\n mach = machine(model, Xtrain, ytrain)|>fit!\n yhat = predict(mach, Xtest)\n @info \"accuracy\"=>accuracy(ytest,yhat)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\n[ Info: For silent loading, specify `verbosity=0`. \n[ Info: Training machine(SVC(kernel = RadialBasis, …), …).\n[ Info: \"accuracy\" => 0.9860917941585535\n```\n:::\n\n::: {.cell-output .cell-output-stdout}\n```\nimport MLJLIBSVMInterface ✔\n```\n:::\n:::\n\n\n## 4. plot results\n\n:::{.callout-tip title=\"makie plot image\"}\n 1. reshape to image matrix `img=Xtest[pick,:]|>Vector|>d->reshape(d,8,8)`\n 2. sometimes need rotl `load(patharr[num])|>rotl90`\n 3. sometimes need reverse y axis `local ax = Axis(fig[i, j],yreversed=true)`\n \n:::\n\n::: {.cell execution_count=4}\n``` {.julia .cell-code}\n function plot_res()\n fig=Figure()\n #rand pick 15 origin picture of digits\n picks=rand(1:length(Vector(ytest)),15)\n for (idx,pick) in enumerate(picks)\n \n ax=Axis(fig[fldmod1(idx,5)...];title=\"pred:$(yhat[pick])\",yreversed=true)\n img=Xtest[pick,:]|>Vector|>d->reshape(d,8,8)\n image!(ax,img)\n hidedecorations!(ax)\n end\n fig\n end\n\n fig=plot_res()\n```\n\n::: {.cell-output .cell-output-display execution_count=5}\n![](3-recognizing-handwriting-digits_files/figure-html/cell-5-output-1.png){}\n:::\n:::\n\n\n", "supporting": [ - "3-recognizing-handwriting-digits_files" + "3-recognizing-handwriting-digits_files/figure-html" ], "filters": [], "includes": {}