diff --git a/README.md b/README.md index ee2555e..98083c5 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ make_regression | Generate a random regression problem. make_classification | Generate a random n-class classification problem. | [link](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_classification.html) make_low_rank_matrix | Generate a mostly low rank matrix with bell-shaped singular values. | [link](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_low_rank_matrix.html) make_swiss_roll | Generate a swiss roll dataset. | [link](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_swiss_roll.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 @@ -52,4 +53,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 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() diff --git a/src/sklearn.jl b/src/sklearn.jl index d85bf2a..6b6a3cb 100644 --- a/src/sklearn.jl +++ b/src/sklearn.jl @@ -240,6 +240,45 @@ 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. +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}}; + 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 = shuffle, + random_state = random_state) + + return (X = convert(features, "feature"), rows = convert(rows, "row"), columns = convert(columns, "column")) +end + """ function generate_friedman1(; n_samples::Int = 100, n_features::Int = 10, diff --git a/test/runtests.jl b/test/runtests.jl index 7850d32..413ad6e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -78,4 +78,16 @@ using Test @test size(data)[1] == samples @test size(data)[2] == 4 + + n_clusters = 3 + samples = 10 + features = 4 + data = SyntheticDatasets.generate_checkerboard((samples, features), n_clusters) + + @test size(data.X)[1] == samples + @test size(data.X)[2] == features + + @test size(data.rows)[2] == samples + + @test size(data.cols)[2] == features end