Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
15 changes: 15 additions & 0 deletions src/SyntheticDatasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
39 changes: 39 additions & 0 deletions src/sklearn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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