From 2d5201824510d5179faa80fd3232241358ef2c3d Mon Sep 17 00:00:00 2001 From: Pedro Date: Sun, 6 Sep 2020 00:50:21 -0300 Subject: [PATCH 1/7] Add generate checkerboard function --- src/sklearn.jl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/sklearn.jl b/src/sklearn.jl index d740d06..3148865 100644 --- a/src/sklearn.jl +++ b/src/sklearn.jl @@ -238,4 +238,24 @@ function generate_classification(; n_samples::Int = 100, random_state = random_state) return convert(features, labels) +end + +function generate_checkerboard(shape::Tuple{Int, Int}, + n_clusters::Union{Int, Tuple{Int, Int}}; + noise::Float64 = 0.0, + minval::Int = 3, + maxval::Int = 100, + shuffle::Bool = true, + random_state::Union{Nothing, Int} = nothing) + + + (features, rows, columns) = datasets.make_checkerboard(shape = shape, + n_clusters = n_clusters, + noise = noise, + minval = minval, + maxval = maxval, + shuffle = true, + random_state = random_state) + + return convert(features, "feature"), convert(rows, "row"), convert(columns, "column") end \ No newline at end of file From 7746c1cf83db81b9cb7e0403e2c2c0df3a6c0409 Mon Sep 17 00:00:00 2001 From: Pedro Date: Sun, 6 Sep 2020 00:51:05 -0300 Subject: [PATCH 2/7] Add generate checkerboard docstring --- src/sklearn.jl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/sklearn.jl b/src/sklearn.jl index 3148865..c8a1fdb 100644 --- a/src/sklearn.jl +++ b/src/sklearn.jl @@ -240,6 +240,24 @@ function generate_classification(; n_samples::Int = 100, return convert(features, labels) end +""" +function generate_checkerboard(;shape::Tuple{Int, Int}, + n_clusters::Tuple{Int, Int}, + noise::Float64 = 0.0, + minval::Int = 10, + maxval::Int = 100, + shuffle::Bool = true, + random_state::Union{Nothing, Int} = nothing) +Generate an array with block checkerboard structure for biclustering. Sklearn interface to make_checkerboard. +#Arguments +- `shape::Tuple{Int, Int}`: The shape of the result. +- `n_clusters::Tuple{Int, Int}: The number of row and column clusters. +- `noise::Float64 = 0.0`: The standard deviation of the gaussian noise. +- `minval::Int = 10`: Minimum value of a bicluster. +- `maxval::Int = 100`: Maximum value of a bicluster. +- `shuffle::Bool = true`: Shuffle the samples. +- `random_state::Union{Nothing, Int} = nothing`: Determines random number generation for dataset creation. Pass an int for reproducible output across multiple function calls. +""" function generate_checkerboard(shape::Tuple{Int, Int}, n_clusters::Union{Int, Tuple{Int, Int}}; noise::Float64 = 0.0, From f2bb1e7d3e6cf4a90524f18060f11277a6c30d1f Mon Sep 17 00:00:00 2001 From: Pedro Date: Sun, 6 Sep 2020 00:51:34 -0300 Subject: [PATCH 3/7] Add a new convert function --- src/SyntheticDatasets.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/SyntheticDatasets.jl b/src/SyntheticDatasets.jl index f7972f6..d51bc09 100644 --- a/src/SyntheticDatasets.jl +++ b/src/SyntheticDatasets.jl @@ -12,6 +12,21 @@ end include("sklearn.jl") +function convert(matrix::Array{T, 2}, base_name::Union{String, Symbol} = :Column)::DataFrame where {T <: Number} + df = DataFrame() + + for i = 1:size(matrix, 2) + df[!, Symbol(string(base_name) * "_$(i)")] = eltype(matrix)[] + end + + + for i=1:size(matrix, 1) + push!(df, (matrix[i, :]...,)) + end + + return df +end + function convert(features::Array{T, 2}, labels::Array{D, 1})::DataFrame where {T <: Number, D <: Number} df = DataFrame() From 60a88e218a884175074e10ecc9a04a293ffac1cf Mon Sep 17 00:00:00 2001 From: Pedro Date: Sun, 6 Sep 2020 00:51:45 -0300 Subject: [PATCH 4/7] Update readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cb2e34c..a1c5650 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ make_s_curve | Generate an S curve dataset. make_circles | Make a large circle containing a smaller circle in 2d | [link](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_circles.html]) make_regression | Generate a random regression problem. | [link](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_regression.html]) make_classification | Generate a random n-class classification problem. | [link](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_classification.html]) +make_checkerboard | Generate an array with block checkerboard structure for biclustering. | [link](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_checkerboard.html]) **Disclaimer**: SyntheticDatasets.jl borrows code and documentation from [scikit-learn](https://scikit-learn.org/stable/modules/classes.html#samples-generator) in the dataset module, but *it is not an official part @@ -45,4 +46,4 @@ of that project*. It is licensed under [MIT](LICENSE). [codecov-url]: https://codecov.io/gh/ATISLabs/SyntheticDatasets.jl [coverage-img]: https://coveralls.io/repos/github/ATISLabs/SyntheticDatasets.jl/badge.svg?branch=master -[coverage-url]: https://coveralls.io/github/ATISLabs/SyntheticDatasets.jl?branch=master +[coverage-url]: https://coveralls.io/github/ATISLabs/SyntheticDatasets.jl?branch=master \ No newline at end of file From 66dc4e6b6d8ad4abd972ef779686a60e6da155ad Mon Sep 17 00:00:00 2001 From: Pedro Date: Sun, 6 Sep 2020 00:52:03 -0300 Subject: [PATCH 5/7] Add tests for generate checkerboard --- test/runtests.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 13ab66f..5e689c9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -48,4 +48,16 @@ using Test @test size(data)[1] == samples @test size(data)[2] == features + 1 + n_clusters = 3 + samples = 10 + features = 4 + X, rows, cols = SyntheticDatasets.generate_checkerboard((samples, features), n_clusters) + + @test size(X)[1] == samples + @test size(X)[2] == features + + @test size(rows)[2] == samples + + @test size(cols)[2] == features + end \ No newline at end of file From 8b464686c19c6e4738f83b1ad397234c386e2395 Mon Sep 17 00:00:00 2001 From: Pedro Date: Sun, 6 Sep 2020 01:19:19 -0300 Subject: [PATCH 6/7] Fix function and docstring --- src/sklearn.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sklearn.jl b/src/sklearn.jl index c8a1fdb..723baaa 100644 --- a/src/sklearn.jl +++ b/src/sklearn.jl @@ -257,6 +257,7 @@ Generate an array with block checkerboard structure for biclustering. Sklearn in - `maxval::Int = 100`: Maximum value of a bicluster. - `shuffle::Bool = true`: Shuffle the samples. - `random_state::Union{Nothing, Int} = nothing`: Determines random number generation for dataset creation. Pass an int for reproducible output across multiple function calls. +Reference: [link](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_checkerboard.html) """ function generate_checkerboard(shape::Tuple{Int, Int}, n_clusters::Union{Int, Tuple{Int, Int}}; @@ -272,7 +273,7 @@ function generate_checkerboard(shape::Tuple{Int, Int}, noise = noise, minval = minval, maxval = maxval, - shuffle = true, + shuffle = shuffle, random_state = random_state) return convert(features, "feature"), convert(rows, "row"), convert(columns, "column") From 0fae6695afde917083930a120824d8f6205e33f6 Mon Sep 17 00:00:00 2001 From: Pedro Date: Thu, 10 Sep 2020 19:33:00 -0300 Subject: [PATCH 7/7] Change the output type of the generate_checkerboard --- src/sklearn.jl | 2 +- test/runtests.jl | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sklearn.jl b/src/sklearn.jl index e58443b..6b6a3cb 100644 --- a/src/sklearn.jl +++ b/src/sklearn.jl @@ -276,7 +276,7 @@ function generate_checkerboard(shape::Tuple{Int, Int}, shuffle = shuffle, random_state = random_state) - return convert(features, "feature"), convert(rows, "row"), convert(columns, "column") + return (X = convert(features, "feature"), rows = convert(rows, "row"), columns = convert(columns, "column")) end """ diff --git a/test/runtests.jl b/test/runtests.jl index 46b9075..413ad6e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -82,12 +82,12 @@ using Test n_clusters = 3 samples = 10 features = 4 - X, rows, cols = SyntheticDatasets.generate_checkerboard((samples, features), n_clusters) + data = SyntheticDatasets.generate_checkerboard((samples, features), n_clusters) - @test size(X)[1] == samples - @test size(X)[2] == features + @test size(data.X)[1] == samples + @test size(data.X)[2] == features - @test size(rows)[2] == samples + @test size(data.rows)[2] == samples - @test size(cols)[2] == features + @test size(data.cols)[2] == features end