added PyCall.jl examples

This commit is contained in:
Bogumił Kamiński 2022-03-01 11:30:57 +01:00
parent 386ffad128
commit 3cd454c8e4
4 changed files with 46 additions and 1 deletions

View File

@ -753,6 +753,12 @@ uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
deps = ["Printf"]
uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"
[[deps.PyCall]]
deps = ["Conda", "Dates", "Libdl", "LinearAlgebra", "MacroTools", "Serialization", "VersionParsing"]
git-tree-sha1 = "71fd4022ecd0c6d20180e23ff1b3e05a143959c2"
uuid = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
version = "1.93.0"
[[deps.Qt5Base_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Fontconfig_jll", "Glib_jll", "JLLWrappers", "Libdl", "Libglvnd_jll", "OpenSSL_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libxcb_jll", "Xorg_xcb_util_image_jll", "Xorg_xcb_util_keysyms_jll", "Xorg_xcb_util_renderutil_jll", "Xorg_xcb_util_wm_jll", "Zlib_jll", "xkbcommon_jll"]
git-tree-sha1 = "ad368663a5e20dbb8d6dc2fddeefe4dae0781ae8"

View File

@ -3,6 +3,7 @@ BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
CodecBzip2 = "523fee87-0ab8-5b00-afb7-3ecf72e48cfd"
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DataFramesMeta = "1313f7d8-7da2-5740-9ea0-a2ca25f37964"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
@ -17,6 +18,7 @@ Loess = "4345ca2d-374a-55d4-8d30-97f9976e7612"
Missings = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PooledArrays = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
RCall = "6f49c342-dc21-5d91-9882-a32aef131414"
ROCAnalysis = "f535d66d-59bb-5153-8d2b-ef0a426c6aff"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

11
appB.jl
View File

@ -82,6 +82,17 @@ plot(scatter(data.set1.x, data.set1.y; legend=false),
parse.(Int, ["1", "2", "3"])
# Code for exercise 5.2
Random.seed!(1234);
data5bis = [randn(100, 5) .- 0.4; randn(100, 5) .+ 0.4];
tsne = manifold.TSNE(n_components=2, init="random",
learning_rate="auto", random_state=1234);
data2bis = tsne.fit_transform(data5bis);
scatter(data2bis[:, 1], data2bis[:, 2];
color=[fill("black", 100); fill("gold", 100)],
legend=false)
# Code for exercise 6.1
years_table = freqtable(years)

28
ch05.jl
View File

@ -57,7 +57,7 @@ in(4, [1, 2, 3])
in([1, 3, 5, 7, 9], [1, 2, 3, 4])
in([1, 3, 5, 7, 9], [1, 2, 3, 4, ([1, 3, 5, 7, 9]])
in([1, 3, 5, 7, 9], [1, 2, 3, 4, [1, 3, 5, 7, 9]])
in.([1, 3, 5, 7, 9], [1, 2, 3, 4])
@ -159,3 +159,29 @@ x = Any[1, 2, 3]
identity.(x)
y = Any[1, 2.0]
identity.(y)
# Code for section 5.3
using Random
Random.seed!(1234);
cluster1 = randn(100, 5) .- 1
cluster2 = randn(100, 5) .+ 1
data5 = vcat(cluster1, cluster2)
using PyCall
manifold = pyimport("sklearn.manifold")
# Optional code to run if the pyimport("sklearn.manifold") fails
# There is no need to run it if the above operation worked
using Conda
Conda.add("scikit-learn")
tsne = manifold.TSNE(n_components=2, init="random",
learning_rate="auto", random_state=1234)
data2 = tsne.fit_transform(data5)
using Plots
scatter(data2[:, 1], data2[:, 2];
color=[fill("black", 100); fill("gold", 100)],
legend=false)