Skip to content

[#1] - Feature/adding generate s curve function #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 1, 2020
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Dataset | Title
----------------|------------------------------------------------------------------------|--------------------------------------------------
make_blobs | Generate isotropic Gaussian blobs for clustering. | [link](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_moons.html)
make_moons | Make two interleaving half circles | [link](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_blobs.html)

make_s_curve | Generate an S curve dataset. | [link](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_s_curve.html)

[travis-img]: https://travis-ci.com/ATISLabs/SyntheticDatasets.jl.svg?branch=master
[travis-url]: https://travis-ci.com/ATISLabs/SyntheticDatasets.jl
Expand Down
24 changes: 23 additions & 1 deletion src/SyntheticDatasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,29 @@ function generate_blobs(;n_samples::Union{Int, Array{Int, 1}} = 100,
return convert(features, labels)
end

function convert(features::Array{T, 2}, labels::Array{Int, 1})::DataFrame where T <: Number
"""
generate_s_curve(; n_samples::Int = 100,
noise = nothing,
random_state = nothing)::DataFrame
Generate an S curve dataset. Sklearn interface to make_s_curve.
# Arguments
- `n_samples::Int = 100`: The number of sample points on the S curve.
- `noise::Union{Nothing, Float64} = nothing`: Standard deviation of Gaussian noise added to the data.
- `random_state::Union{Int, Nothing} = 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_s_curve.html)
"""
function generate_s_curve(; n_samples::Int = 100,
noise::Float64 = 0.0,
random_state::Union{Int, Nothing} = nothing)::DataFrame

(features, labels) = datasets.make_s_curve( n_samples = n_samples,
noise = noise,
random_state = random_state)

return convert(features, labels)
end

function convert(features::Array{T, 2}, labels::Array{D, 1})::DataFrame where {T <: Number, D <: Number}
df = DataFrame()

for i = 1:size(features)[2]
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ using Test

@test size(data)[1] == samples
@test size(data)[2] == 3

data = SyntheticDatasets.generate_s_curve(n_samples = samples,
noise = 2.2,
random_state = 5)

@test size(data)[1] == samples
@test size(data)[2] == 4

end