Swiftpack.co - StarlangSoftware/Sampling-Swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by StarlangSoftware.
StarlangSoftware/Sampling-Swift 1.0.7
Data sampling library
⭐️ 0
🕓 1 year ago
.package(url: "https://github.com/StarlangSoftware/Sampling-Swift.git", from: "1.0.7")

Sampling Strategies

K-Fold cross-validation

In K-fold cross-validation, the aim is to generate K training/validation set pair, where training and validation sets on fold i do no overlap. First, we divide the dataset X into K parts as X1; X2; ... ; XK. Then for each fold i, we use Xi as the validation set and the remaining as the training set.

Possible values of K are 10 or 30. One extreme case of K-fold cross-validation is leave-one-out, where K = N and each validation set has only one instance. If we have more computation power, we can have multiple runs of K-fold cross-validation, such as 10 x 10 cross-validation or 5 x 2 cross-validation.

Bootstrapping

If we have very small datasets, we do not insist on the non-overlap of training and validation sets. In bootstrapping, we generate K multiple training sets, where each training set contains N examples (like the original dataset). To get N examples, we draw examples with replacement. For the validation set, we use the original dataset. The drawback of bootstrapping is that the bootstrap samples overlap more than the cross-validation sample, hence they are more dependent.

Video Lectures

For Developers

You can also see Java, Python, Cython, C++, C, Js, or C# repository.

Requirements

  • Xcode Editor
  • Git

Git

Install the latest version of Git.

Download Code

In order to work on code, create a fork from GitHub page. Use Git for cloning the code to your local or below line for Ubuntu:

git clone <your-fork-git-link>

A directory called Sampling-Swift will be created. Or you can use below link for exploring the code:

git clone https://github.com/starlangsoftware/Sampling-Swift.git

Open project with XCode

To import projects from Git with version control:

  • XCode IDE, select Clone an Existing Project.

  • In the Import window, paste github URL.

  • Click Clone.

Result: The imported project is listed in the Project Explorer view and files are loaded.

Compile

From IDE

After being done with the downloading and opening project, select Build option from Product menu. After compilation process, user can run Sampling-Swift.

Detailed Description

CrossValidation

k. eğitim kümesini elde etmek için

func getTrainFold(k: Int) -> [T]

k. test kümesini elde etmek için

func getTestFold(k: Int) -> [T]

Bootstrap

Bootstrap için BootStrap sınıfı

init(instanceList: [T], seed: Int)

Örneğin elimizdeki veriler a adlı dizide olsun. Bu veriler üstünden bir bootstrap örneklemi tanımlamak için (5 burada rasgelelik getiren seed'i göstermektedir. 5 değiştirilerek farklı samplelar elde edilebilir)

bootstrap = = Bootstrap(instanceList: a, seed: 5)

ardından üretilen sample'ı çekmek için ise

sample = bootstrap.getSample();

yazılır.

KFoldCrossValidation

K kat çapraz geçerleme için KFoldCrossValidation sınıfı

init(instanceList: [T], K: Int, seed: Int)

Örneğin elimizdeki veriler a adlı dizide olsun. Bu veriler üstünden 10 kat çapraz geçerleme yapmak için (2 burada rasgelelik getiren seed'i göstermektedir. 2 değiştirilerek farklı samplelar elde edilebilir)

kfold = KFoldCrossValidation(instanceList: a, K: 10, seed: 2)

ardından yukarıda belirtilen getTrainFold ve getTestFold metodları ile sırasıyla i. eğitim ve test kümeleri elde edilebilir.

StratifiedKFoldCrossValidation

Stratified K kat çapraz geçerleme için StratifiedKFoldCrossValidation sınıfı

init(instanceLists: [[T]], K: Int, seed: Int)

Örneğin elimizdeki veriler a adlı dizide olsun. Stratified bir çapraz geçerlemede sınıflara ait veriler o sınıfın oranında temsil edildikleri için her bir sınıfa ait verilerin ayrı ayrı dizilerde olmaları gerekmektedir. Bu veriler üstünden 30 kat çapraz geçerleme yapmak için (4 burada rasgelelik getiren seed'i göstermektedir. 4 değiştirilerek farklı samplelar elde edilebilir)

stratified = StratifiedKFoldCrossValidation<String>(instanceLists: a, K: 30, seed: 4)

ardından yukarıda belirtilen getTrainFold ve getTestFold metodları ile sırasıyla i. eğitim ve test kümeleri elde edilebilir.

GitHub

link
Stars: 0
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Updated Util dependency.
1 year ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics