Skip to content

[#1] - Feature/generate circles function #12

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 4, 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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ 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)
<<<<<<< HEAD
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])
>>>>>>> master

**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 Down
35 changes: 31 additions & 4 deletions src/sklearn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,37 @@ function generate_s_curve(; n_samples::Int = 100,
return convert(features, labels)
end

"""
function generate_circles(; n_samples::Int = 100,
shuffle::Bool = true,
noise::Float64 = 0.0,
random_state::Union{Int, Nothing} = nothing,
factor::Float64 = 0.8)::DataFrame
Make a large circle containing a smaller circle in 2d. Sklearn interface to make_circles.
# Arguments
- `n_samples::Union{Int, Tuple{Int, Int}} = 100`: If int, it is the total number of points generated. For odd numbers, the inner circle will have one point more than the outer circle. If two-element tuple, number of points in outer circle and inner circle.
- `shuffle::Bool = true`: Whether to shuffle the samples.
- `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 shuffling and noise. Pass an int for reproducible output across multiple function calls.
- `factor::Float64 = 0.8`: Scale factor between inner and outer circle.
Reference: [link](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_circles.html)

"""
function generate_circles(; n_samples::Union{Int, Tuple{Int, Int}} = 100,
shuffle::Bool = true,
noise::Union{Nothing, Float64} = nothing,
random_state::Union{Int, Nothing} = nothing,
factor::Float64 = 0.8)::DataFrame

(features, labels) = datasets.make_circles( n_samples = n_samples,
shuffle = shuffle,
noise = noise,
random_state = random_state,
factor = factor)

return convert(features, labels)
end

"""
generate_regression(; n_samples::Int = 100,
n_features::Int = 100,
Expand Down Expand Up @@ -124,7 +155,6 @@ function generate_regression(; n_samples::Int = 100,
coef::Bool = false,
random_state::Union{Int, Nothing}= nothing)


(features, labels) = datasets.make_regression( n_samples = n_samples,
n_features = n_features,
n_informative = n_informative,
Expand All @@ -136,10 +166,8 @@ function generate_regression(; n_samples::Int = 100,
shuffle = shuffle,
coef = coef,
random_state = random_state)


return convert(features, labels)

end

"""
Expand Down Expand Up @@ -193,7 +221,6 @@ function generate_classification(; n_samples::Int = 100,
shuffle::Bool = true,
random_state::Union{Int, Nothing} = nothing)


(features, labels) = datasets.make_classification( n_samples = n_samples,
n_features = n_features,
n_informative = n_informative,
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ using Test
@test size(data)[1] == samples
@test size(data)[2] == 4

data = SyntheticDatasets.generate_circles(n_samples = samples)

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

data = SyntheticDatasets.generate_regression(n_samples = samples,
n_features = features,
Expand Down