Generates a synthetic two-dimensional dataset and labels each point by
whether it lies above or below a piecewise linear boundary. The boundary
coordinates can be supplied directly as a matrix/data frame or indirectly via
a JSON file containing an array of coordinate pairs, such as the one
downloaded from sillysplines().
Usage
create_data(
coord_filepath = NULL,
coord = NULL,
n_samples = 10000,
type = c("uniform", "normal", "grid"),
seed = 1835,
gap = 0,
r = 0,
xlim = NULL,
ylim = NULL
)Arguments
- coord_filepath
A character string specifying a file path to a JSON file containing a list/array of coordinate pairs. Optional if
coordis supplied.- coord
A matrix or data frame with two columns (x and y) specifying the boundary coordinates. Optional if
coord_filepathis supplied.- n_samples
Integer; number of synthetic 2D points to generate. For
type = "grid"the result hasfloor(sqrt(n_samples))^2points, and a positivegapremoves points, so the result can have fewer rows thann_samples.- type
String; How should the points be generated. Can be either 'uniform' (default), 'normal', or 'grid'.
- seed
Integer; Random seed to be used for generating dataset.
- gap
Numeric; Value close to 0 defining gap at the boundary, between 0 and 0.2. Points whose vertical distance from the boundary is less than
gapare removed.- r
Numeric; Correlation for generating normal sample, between (-0.9, 0.9), default 0.
- xlim, ylim
Numeric vectors of length 2 giving the range the points are generated in. Default to the range of the boundary coordinates. Supply these when the boundary does not span the region you want to sample, e.g.
xlim = c(-1, 1), ylim = c(-1, 1)for the fullsillysplines()canvas.
Value
A data frame with three columns:
- x
x-coordinate
- y
y-coordinate
- class
Binary class label ("Above" or "Below")
Details
Points are labelled using classify_boundary(): a point is "Above" if its
y-coordinate is greater than the boundary's y-value at the point's
x-coordinate, and "Below" otherwise. Outside the x-range of the boundary
coordinates the boundary is held flat at the nearest endpoint.
Examples
coords <- matrix(c(0.2, 0.3,
0.4, 0.5,
0.6, 0.7), ncol = 2, byrow = TRUE)
df <- create_data(coord = coords, n_samples = 500, seed = 717)
head(df)
#> x y class
#> 1 0.5675952 0.5485005 Below
#> 2 0.4260448 0.3920975 Below
#> 3 0.4958921 0.3064470 Below
#> 4 0.3227430 0.6808239 Above
#> 5 0.3820237 0.5811095 Above
#> 6 0.2340915 0.4497553 Above