From 3ddddeec99dcffe5ae577747e6c831b2388178c1 Mon Sep 17 00:00:00 2001 From: Andrii Siriak Date: Tue, 12 Mar 2024 10:17:13 +0200 Subject: [PATCH] Remove outdated documentation by fixing documentation_workflow.yml (#121) --- .github/scripts/doc_builder.r | 2 +- .github/workflows/documentation_workflow.yml | 7 +- DIRECTORY.md | 18 +- documentation/ANN.html | 279 ------------ documentation/ANN.md | 98 ----- documentation/ArmstrongNumber.md | 50 --- documentation/EuclideanDistance.html | 219 ---------- documentation/EuclideanDistance.md | 17 - documentation/Factorial.html | 228 ---------- documentation/Factorial.md | 28 -- documentation/Fibonacci.html | 230 ---------- documentation/Fibonacci.md | 30 -- documentation/First_n_Fibonacci.html | 238 ----------- documentation/First_n_Fibonacci.md | 36 -- documentation/HammingDistance.md | 57 --- documentation/K-Means.html | 213 ---------- documentation/K-Means.md | 11 - documentation/KNN.html | 238 ----------- documentation/KNN.md | 44 -- documentation/K_Folds.html | 237 ----------- documentation/K_Folds.md | 34 -- documentation/LightGBM.html | 271 ------------ documentation/LightGBM.md | 85 ---- documentation/OneHotEncode.html | 248 ----------- documentation/OneHotEncode.md | 50 --- documentation/PerfectSquare.html | 218 ---------- documentation/PerfectSquare.md | 16 - documentation/PiMonteCarlo.html | 226 ---------- documentation/PiMonteCarlo.md | 26 -- documentation/Prime.html | 244 ----------- documentation/Prime.md | 46 -- documentation/SVM.html | 238 ----------- documentation/SVM.md | 44 -- documentation/amicable_numbers.html | 243 ----------- documentation/amicable_numbers.md | 36 -- documentation/ann.html | 202 +++++++++ documentation/apriori.html | 336 ++++++--------- documentation/binary_insertion_sort.html | 198 +++++++++ documentation/binary_insertion_sort.md | 52 +++ documentation/binary_search.html | 183 ++++++++ documentation/binary_search.md | 37 ++ documentation/bubble_sort.html | 299 ++++++------- documentation/bucket_sort.html | 201 +++++++++ documentation/bucket_sort.md | 59 +++ documentation/cocktail_sort.html | 212 +++++++++ documentation/cocktail_sort.md | 72 ++++ documentation/comb_sort.html | 299 ++++++------- documentation/counting_sort.html | 179 ++++++++ documentation/cycle_sort.html | 214 ++++++++++ documentation/cycle_sort.md | 68 +++ .../data_normalization_standardization.html | 313 ++++++-------- documentation/data_processing.html | 401 +++++++----------- documentation/dbscan_clustering.html | 312 ++++++-------- documentation/decision_tree.html | 320 ++++++-------- .../dimensionality_reduction_algorithms.html | 314 ++++++-------- documentation/gmm.html | 318 ++++++-------- documentation/heap_sort.html | 299 ++++++------- documentation/heirarchical_clustering.html | 303 ++++++------- documentation/insertion_sort.html | 299 ++++++------- documentation/josephus_problem.html | 236 ----------- documentation/josephus_problem.md | 29 -- documentation/k_folds.html | 182 ++++++++ documentation/k_means.html | 158 +++++++ documentation/kmeans_clustering.html | 303 ++++++------- documentation/kmeans_raw_R.html | 261 ------------ documentation/kmeans_raw_R.md | 58 --- documentation/kmeans_raw_r.html | 206 +++++++++ documentation/knn.html | 174 ++++++++ documentation/lasso.html | 346 ++++++--------- documentation/light_gbm.html | 199 +++++++++ documentation/linearRegressionRawR.html | 221 ---------- documentation/linearRegressionRawR.md | 19 - documentation/linear_regression.html | 338 ++++++--------- documentation/linear_search.html | 174 ++++++++ documentation/linear_search.md | 28 ++ documentation/linearregressionrawr.html | 165 +++++++ documentation/logistic_regression.html | 322 ++++++-------- documentation/logistic_regression2.html | 229 ---------- documentation/logistic_regression2.md | 31 -- documentation/logistic_regression_2.html | 169 ++++++++ documentation/merge_sort.html | 299 ++++++------- documentation/multiple_linear_regression.html | 314 ++++++-------- documentation/naive_bayes.html | 324 ++++++-------- documentation/odd_even_sort.html | 194 +++++++++ documentation/odd_even_sort.md | 48 +++ documentation/pam.html | 298 ++++++------- documentation/pancake_sort.html | 202 +++++++++ documentation/pancake_sort.md | 60 +++ documentation/perfect_number.html | 248 ----------- documentation/perfect_number.md | 42 -- documentation/quick_sort.html | 301 ++++++------- documentation/radix_sort.html | 301 ++++++------- documentation/random_forest.html | 324 ++++++-------- documentation/selection_sort.html | 299 ++++++------- documentation/shell_sort.html | 194 +++++++++ documentation/shell_sort.md | 52 +++ documentation/stooge_sort.html | 323 ++++++-------- documentation/svm.html | 174 ++++++++ documentation/topological_sort.html | 204 +++++++++ documentation/topological_sort.md | 58 +++ documentation/wiggle_sort.html | 179 ++++++++ documentation/wiggle_sort.md | 33 ++ documentation/xgboost.html | 364 +++++++--------- 103 files changed, 7878 insertions(+), 10600 deletions(-) delete mode 100644 documentation/ANN.html delete mode 100644 documentation/ANN.md delete mode 100644 documentation/ArmstrongNumber.md delete mode 100644 documentation/EuclideanDistance.html delete mode 100644 documentation/EuclideanDistance.md delete mode 100644 documentation/Factorial.html delete mode 100644 documentation/Factorial.md delete mode 100644 documentation/Fibonacci.html delete mode 100644 documentation/Fibonacci.md delete mode 100644 documentation/First_n_Fibonacci.html delete mode 100644 documentation/First_n_Fibonacci.md delete mode 100644 documentation/HammingDistance.md delete mode 100644 documentation/K-Means.html delete mode 100644 documentation/K-Means.md delete mode 100644 documentation/KNN.html delete mode 100644 documentation/KNN.md delete mode 100644 documentation/K_Folds.html delete mode 100644 documentation/K_Folds.md delete mode 100644 documentation/LightGBM.html delete mode 100644 documentation/LightGBM.md delete mode 100644 documentation/OneHotEncode.html delete mode 100644 documentation/OneHotEncode.md delete mode 100644 documentation/PerfectSquare.html delete mode 100644 documentation/PerfectSquare.md delete mode 100644 documentation/PiMonteCarlo.html delete mode 100644 documentation/PiMonteCarlo.md delete mode 100644 documentation/Prime.html delete mode 100644 documentation/Prime.md delete mode 100644 documentation/SVM.html delete mode 100644 documentation/SVM.md delete mode 100644 documentation/amicable_numbers.html delete mode 100644 documentation/amicable_numbers.md create mode 100644 documentation/ann.html create mode 100644 documentation/binary_insertion_sort.html create mode 100644 documentation/binary_insertion_sort.md create mode 100644 documentation/binary_search.html create mode 100644 documentation/binary_search.md create mode 100644 documentation/bucket_sort.html create mode 100644 documentation/bucket_sort.md create mode 100644 documentation/cocktail_sort.html create mode 100644 documentation/cocktail_sort.md create mode 100644 documentation/counting_sort.html create mode 100644 documentation/cycle_sort.html create mode 100644 documentation/cycle_sort.md delete mode 100644 documentation/josephus_problem.html delete mode 100644 documentation/josephus_problem.md create mode 100644 documentation/k_folds.html create mode 100644 documentation/k_means.html delete mode 100644 documentation/kmeans_raw_R.html delete mode 100644 documentation/kmeans_raw_R.md create mode 100644 documentation/kmeans_raw_r.html create mode 100644 documentation/knn.html create mode 100644 documentation/light_gbm.html delete mode 100644 documentation/linearRegressionRawR.html delete mode 100644 documentation/linearRegressionRawR.md create mode 100644 documentation/linear_search.html create mode 100644 documentation/linear_search.md create mode 100644 documentation/linearregressionrawr.html delete mode 100644 documentation/logistic_regression2.html delete mode 100644 documentation/logistic_regression2.md create mode 100644 documentation/logistic_regression_2.html create mode 100644 documentation/odd_even_sort.html create mode 100644 documentation/odd_even_sort.md create mode 100644 documentation/pancake_sort.html create mode 100644 documentation/pancake_sort.md delete mode 100644 documentation/perfect_number.html delete mode 100644 documentation/perfect_number.md create mode 100644 documentation/shell_sort.html create mode 100644 documentation/shell_sort.md create mode 100644 documentation/svm.html create mode 100644 documentation/topological_sort.html create mode 100644 documentation/topological_sort.md create mode 100644 documentation/wiggle_sort.html create mode 100644 documentation/wiggle_sort.md diff --git a/.github/scripts/doc_builder.r b/.github/scripts/doc_builder.r index d7bcfd3..0b0d2b3 100644 --- a/.github/scripts/doc_builder.r +++ b/.github/scripts/doc_builder.r @@ -27,6 +27,6 @@ print(unlist(scriptlist)) cat("Compiling documentation from scripts.\n") invisible(lapply(unlist(scriptlist), function(x) tryCatch(knitr::spin(x), - error = function(e) message("Error compiling: ", x)))) + error = function(e) message("Error compiling: ", e)))) cat("R process done.\n") diff --git a/.github/workflows/documentation_workflow.yml b/.github/workflows/documentation_workflow.yml index f61b26b..3762b44 100644 --- a/.github/workflows/documentation_workflow.yml +++ b/.github/workflows/documentation_workflow.yml @@ -14,11 +14,14 @@ jobs: run: | echo "Creating 'Documentation'" mkdir -p documentation - - name: Install knitr dependency + - name: Install dependencies run: | echo "Installing R package dependencies. Scripts might have additional dependencies installed." Rscript -e 'if (!require(knitr)) install.packages("knitr")' - - name: Documentation compilation + Rscript -e 'if (!require(markdown)) install.packages("markdown")' + - name: Remove old documentation + run: 'rm -rf documentation/*' + - name: Generate new documentation run: 'Rscript .github/scripts/doc_builder.r' - name: Commit Documentation run: | diff --git a/DIRECTORY.md b/DIRECTORY.md index 0980007..8f37774 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -59,19 +59,27 @@ * [Logistic Regression 2](https://github.com/TheAlgorithms/R/blob/HEAD/regression_algorithms/logistic_regression_2.r) * [Multiple Linear Regression](https://github.com/TheAlgorithms/R/blob/HEAD/regression_algorithms/multiple_linear_regression.r) +## Searches + * [Binary Search](https://github.com/TheAlgorithms/R/blob/HEAD/searches/binary_search.r) + * [Linear Search](https://github.com/TheAlgorithms/R/blob/HEAD/searches/linear_search.r) + ## Sorting Algorithms + * [Binary Insertion Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/binary_insertion_sort.r) * [Bubble Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/bubble_sort.r) + * [Bucket Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/bucket_sort.r) + * [Cocktail Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/cocktail_sort.r) * [Comb Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/comb_sort.r) * [Counting Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/counting_sort.r) + * [Cycle Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/cycle_sort.r) * [Heap Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/heap_sort.r) * [Insertion Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/insertion_sort.r) * [Merge Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/merge_sort.r) + * [Odd Even Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/odd_even_sort.r) + * [Pancake Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/pancake_sort.r) * [Quick Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/quick_sort.r) * [Radix Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/radix_sort.r) * [Selection Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/selection_sort.r) + * [Shell Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/shell_sort.r) * [Stooge Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/stooge_sort.r) - - -## Searches - * [Linear Search](https://github.com/TheAlgorithms/R/blob/master/searches/linear_search.r) - * [Binary Search](https://github.com/TheAlgorithms/R/blob/master/searches/binary_search.r) \ No newline at end of file + * [Topological Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/topological_sort.r) + * [Wiggle Sort](https://github.com/TheAlgorithms/R/blob/HEAD/sorting_algorithms/wiggle_sort.r) diff --git a/documentation/ANN.html b/documentation/ANN.html deleted file mode 100644 index a78b63b..0000000 --- a/documentation/ANN.html +++ /dev/null @@ -1,279 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
library(neuralnet)
-
- -
## Error in library(neuralnet): there is no package called 'neuralnet'
-
- -
concrete<-read.csv(file = "concrete.txt",stringsAsFactors = F)#get the data
-
- -
## Warning in file(file, "rt"): cannot open file 'concrete.txt': No such file or
-## directory
-
- -
## Error in file(file, "rt"): cannot open the connection
-
- -
normalize<-function(x){
-  return((x-min(x))/(max(x)-min(x)))
-}
-concrete<-as.data.frame(lapply(concrete, normalize))
-
- -
## Error in lapply(concrete, normalize): object 'concrete' not found
-
- -
concrete_train<-concrete[1:773,]
-
- -
## Error in eval(expr, envir, enclos): object 'concrete' not found
-
- -
concrete_test<-concrete[774:1030,]
-
- -
## Error in eval(expr, envir, enclos): object 'concrete' not found
-
- -
concrete_model<-neuralnet(strength~cement+slag+ash+water+superplastic+coarseagg+fineagg+age,data = concrete_train,hidden = 5)
-
- -
## Error in neuralnet(strength ~ cement + slag + ash + water + superplastic + : could not find function "neuralnet"
-
- -
model_res<-compute(concrete_model,concrete_test[,1:8])
-
- -
## Error in compute(concrete_model, concrete_test[, 1:8]): could not find function "compute"
-
- -
x=model_res$net.result
-
- -
## Error in eval(expr, envir, enclos): object 'model_res' not found
-
- -
y=concrete_test$strength
-
- -
## Error in eval(expr, envir, enclos): object 'concrete_test' not found
-
- -
cor(x,y)
-
- -
## Error in is.data.frame(y): object 'y' not found
-
- -
plot(concrete_model)
-
- -
## Error in plot(concrete_model): object 'concrete_model' not found
-
- - - - diff --git a/documentation/ANN.md b/documentation/ANN.md deleted file mode 100644 index 92c1f15..0000000 --- a/documentation/ANN.md +++ /dev/null @@ -1,98 +0,0 @@ - - -```r -library(neuralnet) -``` - -``` -## Error in library(neuralnet): there is no package called 'neuralnet' -``` - -```r -concrete<-read.csv(file = "concrete.txt",stringsAsFactors = F)#get the data -``` - -``` -## Warning in file(file, "rt"): cannot open file 'concrete.txt': No such file or -## directory -``` - -``` -## Error in file(file, "rt"): cannot open the connection -``` - -```r -normalize<-function(x){ - return((x-min(x))/(max(x)-min(x))) -} -concrete<-as.data.frame(lapply(concrete, normalize)) -``` - -``` -## Error in lapply(concrete, normalize): object 'concrete' not found -``` - -```r -concrete_train<-concrete[1:773,] -``` - -``` -## Error in eval(expr, envir, enclos): object 'concrete' not found -``` - -```r -concrete_test<-concrete[774:1030,] -``` - -``` -## Error in eval(expr, envir, enclos): object 'concrete' not found -``` - -```r -concrete_model<-neuralnet(strength~cement+slag+ash+water+superplastic+coarseagg+fineagg+age,data = concrete_train,hidden = 5) -``` - -``` -## Error in neuralnet(strength ~ cement + slag + ash + water + superplastic + : could not find function "neuralnet" -``` - -```r -model_res<-compute(concrete_model,concrete_test[,1:8]) -``` - -``` -## Error in compute(concrete_model, concrete_test[, 1:8]): could not find function "compute" -``` - -```r -x=model_res$net.result -``` - -``` -## Error in eval(expr, envir, enclos): object 'model_res' not found -``` - -```r -y=concrete_test$strength -``` - -``` -## Error in eval(expr, envir, enclos): object 'concrete_test' not found -``` - -```r -cor(x,y) -``` - -``` -## Error in is.data.frame(y): object 'y' not found -``` - -```r -plot(concrete_model) -``` - -``` -## Error in plot(concrete_model): object 'concrete_model' not found -``` - diff --git a/documentation/ArmstrongNumber.md b/documentation/ArmstrongNumber.md deleted file mode 100644 index 4661ad6..0000000 --- a/documentation/ArmstrongNumber.md +++ /dev/null @@ -1,50 +0,0 @@ - - -```r -# Armstrong Number (also know as narcissistic numbers) checking in R - -isArmstrong <- function(integer){ - - digitAmount <- if(integer > 0){ - floor(log10(integer))+1 - } else if(integer == 0){ - 1 - } else return(FALSE) - - temp <- integer - Armstrong <- 0 - - while(temp > 0){ - Armstrong <- Armstrong + (temp %% 10)^digitAmount - temp <- floor(temp / 10) - } - - if(Armstrong == integer){ - return(TRUE) - } else return(FALSE) - -} - -isArmstrong(5) #returns TRUE -``` - -``` -## [1] TRUE -``` - -```r -isArmstrong(29) #returns FALSE -``` - -``` -## [1] FALSE -``` - -```r -isArmstrong(370) #returns TRUE -``` - -``` -## [1] TRUE -``` - diff --git a/documentation/EuclideanDistance.html b/documentation/EuclideanDistance.html deleted file mode 100644 index a350866..0000000 --- a/documentation/EuclideanDistance.html +++ /dev/null @@ -1,219 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
euclideanDistance <- function(x, y) {
-    return(sqrt(sum((x - y)^2)))
-}
-
-set.seed(1)
-x <- rnorm(1000)
-y <- runif(1000)
-print(euclideanDistance(x, y))
-
- -
## [1] 37.21474
-
- - - - diff --git a/documentation/EuclideanDistance.md b/documentation/EuclideanDistance.md deleted file mode 100644 index 7015763..0000000 --- a/documentation/EuclideanDistance.md +++ /dev/null @@ -1,17 +0,0 @@ - - -```r -euclideanDistance <- function(x, y) { - return(sqrt(sum((x - y)^2))) -} - -set.seed(1) -x <- rnorm(1000) -y <- runif(1000) -print(euclideanDistance(x, y)) -``` - -``` -## [1] 37.21474 -``` - diff --git a/documentation/Factorial.html b/documentation/Factorial.html deleted file mode 100644 index 1ed5aae..0000000 --- a/documentation/Factorial.html +++ /dev/null @@ -1,228 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
Fact <- function(n){
-  if(n < 0){
-    stop("Error: your input is wrong!")
-  } else if(n == 0){
-    return(1)
-  } else {
-    return(prod(1:n))
-  }
-}
-
-Fact(5)
-
- -
## [1] 120
-
- -
Fact(6)
-
- -
## [1] 720
-
- - - - diff --git a/documentation/Factorial.md b/documentation/Factorial.md deleted file mode 100644 index ba9982c..0000000 --- a/documentation/Factorial.md +++ /dev/null @@ -1,28 +0,0 @@ - - -```r -Fact <- function(n){ - if(n < 0){ - stop("Error: your input is wrong!") - } else if(n == 0){ - return(1) - } else { - return(prod(1:n)) - } -} - -Fact(5) -``` - -``` -## [1] 120 -``` - -```r -Fact(6) -``` - -``` -## [1] 720 -``` - diff --git a/documentation/Fibonacci.html b/documentation/Fibonacci.html deleted file mode 100644 index 291d9e1..0000000 --- a/documentation/Fibonacci.html +++ /dev/null @@ -1,230 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
Fibonacci <- function(n)
-{
-  if(n == 1|n == 2)
-  {
-    return(1)
-  }
-  else
-  {
-    return(Fibonacci(n-1) + Fibonacci(n - 2))
-  }
-}
-
-Fibonacci(1)
-
- -
## [1] 1
-
- -
Fibonacci(11)
-
- -
## [1] 89
-
- - - - diff --git a/documentation/Fibonacci.md b/documentation/Fibonacci.md deleted file mode 100644 index 3993ec5..0000000 --- a/documentation/Fibonacci.md +++ /dev/null @@ -1,30 +0,0 @@ - - -```r -Fibonacci <- function(n) -{ - if(n == 1|n == 2) - { - return(1) - } - else - { - return(Fibonacci(n-1) + Fibonacci(n - 2)) - } -} - -Fibonacci(1) -``` - -``` -## [1] 1 -``` - -```r -Fibonacci(11) -``` - -``` -## [1] 89 -``` - diff --git a/documentation/First_n_Fibonacci.html b/documentation/First_n_Fibonacci.html deleted file mode 100644 index 41bdf1d..0000000 --- a/documentation/First_n_Fibonacci.html +++ /dev/null @@ -1,238 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
First_n_Fibonacci <- function(n)
-{
-  # creating empty array of size n
-  Fibonacci <- numeric(n)
-  
-  # assigning first 2 fibonacci values
-  Fibonacci[1] <- 0
-  Fibonacci[2] <- 1
-  
-  # finding the remaining fibonacci numbers using a for loop ranging from 3 to n
-  for (i in 3:n) 
-  {
-    Fibonacci[i] <- Fibonacci[i - 2] + Fibonacci[i - 1]
-  }  
-  
-  # printing the result
-  print(Fibonacci)
-}
-
-First_n_Fibonacci(10) #returns 0 1 1 2 3 5 8 13 21 34 
-
-
- -
## [1] 0 1 1 2 3 5 8 13 21 34
-
- -
First_n_Fibonacci(15) #returns 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
-
- -
## [1] 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
-
- - - - diff --git a/documentation/First_n_Fibonacci.md b/documentation/First_n_Fibonacci.md deleted file mode 100644 index 1c3edb6..0000000 --- a/documentation/First_n_Fibonacci.md +++ /dev/null @@ -1,36 +0,0 @@ - - -```r -First_n_Fibonacci <- function(n) -{ - # creating empty array of size n - Fibonacci <- numeric(n) - - # assigning first 2 fibonacci values - Fibonacci[1] <- 0 - Fibonacci[2] <- 1 - - # finding the remaining fibonacci numbers using a for loop ranging from 3 to n - for (i in 3:n) - { - Fibonacci[i] <- Fibonacci[i - 2] + Fibonacci[i - 1] - } - - # printing the result - print(Fibonacci) -} - -First_n_Fibonacci(10) #returns 0 1 1 2 3 5 8 13 21 34 -``` - -``` -## [1] 0 1 1 2 3 5 8 13 21 34 -``` - -```r -First_n_Fibonacci(15) #returns 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 -``` - -``` -## [1] 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 -``` diff --git a/documentation/HammingDistance.md b/documentation/HammingDistance.md deleted file mode 100644 index d3fe618..0000000 --- a/documentation/HammingDistance.md +++ /dev/null @@ -1,57 +0,0 @@ - - -```r -# Hamming distance -library(roxygen2) -``` - -``` -## Error in library(roxygen2): there is no package called 'roxygen2' -``` - -```r -library(docstring) -``` - -``` -## Error in library(docstring): there is no package called 'docstring' -``` - -```r -hamming_distance <- function(input1, input2) { - #' Find the hamming distance between two strings - #' - #' @description Finds the hamming distance between two strings - #' @param input1 String - #' @param input2 String - #' @usage hamming_distance(input1, input2) - #' @details In information theory, the Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different. - #' In other words, it measures the minimum number of substitutions required to change one string into the other, or the minimum number of errors that could have transformed one string into the other. - #' In a more general context, the Hamming distance is one of several string metrics for measuring the edit distance between two sequences. It is named after the American mathematician Richard Hamming. - #' @references https://en.wikipedia.org/wiki/Hamming_distance - - if (length(input1) != length(input2)) stop("String lengths must be the same") - - sum(input1 != input2) -} - - -x1 = strsplit("karolin", "")[[1]] -y1 = strsplit("kathrin", "")[[1]] -print(hamming_distance(x1, y1) == 3) # returns TRUE -``` - -``` -## [1] TRUE -``` - -```r -x2 = strsplit("0000", "")[[1]] -y2 = strsplit("1111", "")[[1]] -print(hamming_distance(x2, y2) == 4) # returns TRUE -``` - -``` -## [1] TRUE -``` - diff --git a/documentation/K-Means.html b/documentation/K-Means.html deleted file mode 100644 index 0b8775f..0000000 --- a/documentation/K-Means.html +++ /dev/null @@ -1,213 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
library(cluster)
-fit <- kmeans(X, 3) # 5 cluster solution
-
- -
## Error in as.matrix(x): object 'X' not found
-
- - - - diff --git a/documentation/K-Means.md b/documentation/K-Means.md deleted file mode 100644 index 98822e5..0000000 --- a/documentation/K-Means.md +++ /dev/null @@ -1,11 +0,0 @@ - - -```r -library(cluster) -fit <- kmeans(X, 3) # 5 cluster solution -``` - -``` -## Error in as.matrix(x): object 'X' not found -``` - diff --git a/documentation/KNN.html b/documentation/KNN.html deleted file mode 100644 index 53487d5..0000000 --- a/documentation/KNN.html +++ /dev/null @@ -1,238 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
library(knn)
-
- -
## Error in library(knn): there is no package called 'knn'
-
- -
x <- cbind(x_train,y_train)
-
- -
## Error in cbind(x_train, y_train): object 'x_train' not found
-
- -
# Fitting model
-fit <-knn(y_train ~ ., data = x,k=5)
-
- -
## Error in knn(y_train ~ ., data = x, k = 5): could not find function "knn"
-
- -
summary(fit)
-
- -
## Error in summary(fit): object 'fit' not found
-
- -
# Predict Output 
-predicted= predict(fit,x_test)
-
- -
## Error in predict(fit, x_test): object 'fit' not found
-
- - - - diff --git a/documentation/KNN.md b/documentation/KNN.md deleted file mode 100644 index 3241822..0000000 --- a/documentation/KNN.md +++ /dev/null @@ -1,44 +0,0 @@ - - -```r -library(knn) -``` - -``` -## Error in library(knn): there is no package called 'knn' -``` - -```r -x <- cbind(x_train,y_train) -``` - -``` -## Error in cbind(x_train, y_train): object 'x_train' not found -``` - -```r -# Fitting model -fit <-knn(y_train ~ ., data = x,k=5) -``` - -``` -## Error in knn(y_train ~ ., data = x, k = 5): could not find function "knn" -``` - -```r -summary(fit) -``` - -``` -## Error in summary(fit): object 'fit' not found -``` - -```r -# Predict Output -predicted= predict(fit,x_test) -``` - -``` -## Error in predict(fit, x_test): object 'fit' not found -``` - diff --git a/documentation/K_Folds.html b/documentation/K_Folds.html deleted file mode 100644 index a6108e5..0000000 --- a/documentation/K_Folds.html +++ /dev/null @@ -1,237 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
# K folds cross validation is essential for machine learning
-# createFolds function in package caret is easy to use
-# here we write our own function
-
-get_k_folds<-function(y = c(),k = 10, isList = TRUE, seed = 123){
-  set.seed(seed)
-  folds<-sample(1:length(y), length(y))
-  every_n<-ceiling(length(y)/k)
-  matFolds<-suppressWarnings(matrix(folds, ncol=every_n, byrow = T))
-
-  if(isList){
-    value<-NULL
-    rownames(matFolds)<-paste("Folds",1:k,sep="")
-    value<-lapply(1:k, function(x){
-      if(x == k){
-        return(matFolds[x,][1:(length(y)-every_n*(k-1))])
-      }else{
-        return(matFolds[x,])
-      }
-    })
-  }else{
-    value<-c()
-    for(i in 1:length(y)){
-      value[i]<-ceiling(i/every_n)
-    }
-  }
-
-  return(value)
-}
-
- - - - diff --git a/documentation/K_Folds.md b/documentation/K_Folds.md deleted file mode 100644 index 35e505d..0000000 --- a/documentation/K_Folds.md +++ /dev/null @@ -1,34 +0,0 @@ - - -```r -# K folds cross validation is essential for machine learning -# createFolds function in package caret is easy to use -# here we write our own function - -get_k_folds<-function(y = c(),k = 10, isList = TRUE, seed = 123){ - set.seed(seed) - folds<-sample(1:length(y), length(y)) - every_n<-ceiling(length(y)/k) - matFolds<-suppressWarnings(matrix(folds, ncol=every_n, byrow = T)) - - if(isList){ - value<-NULL - rownames(matFolds)<-paste("Folds",1:k,sep="") - value<-lapply(1:k, function(x){ - if(x == k){ - return(matFolds[x,][1:(length(y)-every_n*(k-1))]) - }else{ - return(matFolds[x,]) - } - }) - }else{ - value<-c() - for(i in 1:length(y)){ - value[i]<-ceiling(i/every_n) - } - } - - return(value) -} -``` - diff --git a/documentation/LightGBM.html b/documentation/LightGBM.html deleted file mode 100644 index 4526a9a..0000000 --- a/documentation/LightGBM.html +++ /dev/null @@ -1,271 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
library(RLightGBM)
-
- -
## Error in library(RLightGBM): there is no package called 'RLightGBM'
-
- -
data(example.binary)
-
- -
## Warning in data(example.binary): data set 'example.binary' not found
-
- -
#Parameters
-
-num_iterations <- 100
-config <- list(objective = "binary",  metric="binary_logloss,auc", learning_rate = 0.1, num_leaves = 63, tree_learner = "serial", feature_fraction = 0.8, bagging_freq = 5, bagging_fraction = 0.8, min_data_in_leaf = 50, min_sum_hessian_in_leaf = 5.0)
-
-#Create data handle and booster
-handle.data <- lgbm.data.create(x)
-
- -
## Error in lgbm.data.create(x): could not find function "lgbm.data.create"
-
- -
lgbm.data.setField(handle.data, "label", y)
-
- -
## Error in lgbm.data.setField(handle.data, "label", y): could not find function "lgbm.data.setField"
-
- -
handle.booster <- lgbm.booster.create(handle.data, lapply(config, as.character))
-
- -
## Error in lgbm.booster.create(handle.data, lapply(config, as.character)): could not find function "lgbm.booster.create"
-
- -
#Train for num_iterations iterations and eval every 5 steps
-
-lgbm.booster.train(handle.booster, num_iterations, 5)
-
- -
## Error in lgbm.booster.train(handle.booster, num_iterations, 5): could not find function "lgbm.booster.train"
-
- -
#Predict
-pred <- lgbm.booster.predict(handle.booster, x.test)
-
- -
## Error in lgbm.booster.predict(handle.booster, x.test): could not find function "lgbm.booster.predict"
-
- -
#Test accuracy
-sum(y.test == (y.pred > 0.5)) / length(y.test)
-
- -
## Error in eval(expr, envir, enclos): object 'y.test' not found
-
- -
#Save model (can be loaded again via lgbm.booster.load(filename))
-lgbm.booster.save(handle.booster, filename = "/tmp/model.txt")
-
- -
## Error in lgbm.booster.save(handle.booster, filename = "/tmp/model.txt"): could not find function "lgbm.booster.save"
-
- - - - diff --git a/documentation/LightGBM.md b/documentation/LightGBM.md deleted file mode 100644 index a8cea36..0000000 --- a/documentation/LightGBM.md +++ /dev/null @@ -1,85 +0,0 @@ - - -```r -library(RLightGBM) -``` - -``` -## Error in library(RLightGBM): there is no package called 'RLightGBM' -``` - -```r -data(example.binary) -``` - -``` -## Warning in data(example.binary): data set 'example.binary' not found -``` - -```r -#Parameters - -num_iterations <- 100 -config <- list(objective = "binary", metric="binary_logloss,auc", learning_rate = 0.1, num_leaves = 63, tree_learner = "serial", feature_fraction = 0.8, bagging_freq = 5, bagging_fraction = 0.8, min_data_in_leaf = 50, min_sum_hessian_in_leaf = 5.0) - -#Create data handle and booster -handle.data <- lgbm.data.create(x) -``` - -``` -## Error in lgbm.data.create(x): could not find function "lgbm.data.create" -``` - -```r -lgbm.data.setField(handle.data, "label", y) -``` - -``` -## Error in lgbm.data.setField(handle.data, "label", y): could not find function "lgbm.data.setField" -``` - -```r -handle.booster <- lgbm.booster.create(handle.data, lapply(config, as.character)) -``` - -``` -## Error in lgbm.booster.create(handle.data, lapply(config, as.character)): could not find function "lgbm.booster.create" -``` - -```r -#Train for num_iterations iterations and eval every 5 steps - -lgbm.booster.train(handle.booster, num_iterations, 5) -``` - -``` -## Error in lgbm.booster.train(handle.booster, num_iterations, 5): could not find function "lgbm.booster.train" -``` - -```r -#Predict -pred <- lgbm.booster.predict(handle.booster, x.test) -``` - -``` -## Error in lgbm.booster.predict(handle.booster, x.test): could not find function "lgbm.booster.predict" -``` - -```r -#Test accuracy -sum(y.test == (y.pred > 0.5)) / length(y.test) -``` - -``` -## Error in eval(expr, envir, enclos): object 'y.test' not found -``` - -```r -#Save model (can be loaded again via lgbm.booster.load(filename)) -lgbm.booster.save(handle.booster, filename = "/tmp/model.txt") -``` - -``` -## Error in lgbm.booster.save(handle.booster, filename = "/tmp/model.txt"): could not find function "lgbm.booster.save" -``` - diff --git a/documentation/OneHotEncode.html b/documentation/OneHotEncode.html deleted file mode 100644 index c166f96..0000000 --- a/documentation/OneHotEncode.html +++ /dev/null @@ -1,248 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
oneHotEncode <- function(x, fullRank = T){
-    if(fullRank){
-        return(model.matrix(~ 0 + ., data = x))
-    } else {
-        charCols <- colnames(x)[sapply(x, is.character)]
-        if(length(charCols) > 0){
-            for(col in charCols){
-                x[[eval(col)]] <- factor(x[[eval(col)]])
-            }
-        }
-        factorCols <- colnames(x)[sapply(x, is.factor)]
-        contrastsList <- vector(mode = "list", length = length(factorCols))
-        names(contrastsList) <- factorCols
-        if(length(factorCols) > 0){
-            for(col in factorCols){
-                contrastsList[[eval(col)]] <- contrasts(x[[eval(col)]], contrasts = F)
-            }
-            return(model.matrix(~ 0 + ., data = x, contrasts = contrastsList))
-        } else {
-            return(model.matrix(~ 0 + ., data = x))
-        }
-    }
-}
-
-diamonds <- ggplot2::diamonds
-
- -
## Error in loadNamespace(x): there is no package called 'ggplot2'
-
- -
head(oneHotEncode(diamonds))
-
- -
## Error in terms.formula(object, data = data): object 'diamonds' not found
-
- -
head(oneHotEncode(diamonds, fullRank = F))
-
- -
## Error in is.data.frame(x): object 'diamonds' not found
-
- - - - diff --git a/documentation/OneHotEncode.md b/documentation/OneHotEncode.md deleted file mode 100644 index a1bfd43..0000000 --- a/documentation/OneHotEncode.md +++ /dev/null @@ -1,50 +0,0 @@ - - -```r -oneHotEncode <- function(x, fullRank = T){ - if(fullRank){ - return(model.matrix(~ 0 + ., data = x)) - } else { - charCols <- colnames(x)[sapply(x, is.character)] - if(length(charCols) > 0){ - for(col in charCols){ - x[[eval(col)]] <- factor(x[[eval(col)]]) - } - } - factorCols <- colnames(x)[sapply(x, is.factor)] - contrastsList <- vector(mode = "list", length = length(factorCols)) - names(contrastsList) <- factorCols - if(length(factorCols) > 0){ - for(col in factorCols){ - contrastsList[[eval(col)]] <- contrasts(x[[eval(col)]], contrasts = F) - } - return(model.matrix(~ 0 + ., data = x, contrasts = contrastsList)) - } else { - return(model.matrix(~ 0 + ., data = x)) - } - } -} - -diamonds <- ggplot2::diamonds -``` - -``` -## Error in loadNamespace(x): there is no package called 'ggplot2' -``` - -```r -head(oneHotEncode(diamonds)) -``` - -``` -## Error in terms.formula(object, data = data): object 'diamonds' not found -``` - -```r -head(oneHotEncode(diamonds, fullRank = F)) -``` - -``` -## Error in is.data.frame(x): object 'diamonds' not found -``` - diff --git a/documentation/PerfectSquare.html b/documentation/PerfectSquare.html deleted file mode 100644 index db77127..0000000 --- a/documentation/PerfectSquare.html +++ /dev/null @@ -1,218 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
perfectSquare <- function(x){
-    return(floor(sqrt(x)) == sqrt(x))
-}
-
-set.seed(1)
-inputs <- sample(1:100, 10)
-perfectSquare(inputs)
-
- -
##  [1] FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
-
- - - - diff --git a/documentation/PerfectSquare.md b/documentation/PerfectSquare.md deleted file mode 100644 index a70c7cc..0000000 --- a/documentation/PerfectSquare.md +++ /dev/null @@ -1,16 +0,0 @@ - - -```r -perfectSquare <- function(x){ - return(floor(sqrt(x)) == sqrt(x)) -} - -set.seed(1) -inputs <- sample(1:100, 10) -perfectSquare(inputs) -``` - -``` -## [1] FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE -``` - diff --git a/documentation/PiMonteCarlo.html b/documentation/PiMonteCarlo.html deleted file mode 100644 index 2297b9d..0000000 --- a/documentation/PiMonteCarlo.html +++ /dev/null @@ -1,226 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
estimatePi <- function(numSims){
-    x <- runif(numSims)
-    y <- runif(numSims)
-    inUnitCircle <- as.integer(x^2 + y^2 <= 1)
-    return(4 * sum(inUnitCircle) / numSims)
-}
-
-set.seed(1)
-estimatePi(3000)
-
- -
## [1] 3.125333
-
- -
estimatePi(30000)
-
- -
## [1] 3.132933
-
- - - - diff --git a/documentation/PiMonteCarlo.md b/documentation/PiMonteCarlo.md deleted file mode 100644 index 9a88622..0000000 --- a/documentation/PiMonteCarlo.md +++ /dev/null @@ -1,26 +0,0 @@ - - -```r -estimatePi <- function(numSims){ - x <- runif(numSims) - y <- runif(numSims) - inUnitCircle <- as.integer(x^2 + y^2 <= 1) - return(4 * sum(inUnitCircle) / numSims) -} - -set.seed(1) -estimatePi(3000) -``` - -``` -## [1] 3.125333 -``` - -```r -estimatePi(30000) -``` - -``` -## [1] 3.132933 -``` - diff --git a/documentation/Prime.html b/documentation/Prime.html deleted file mode 100644 index fa66d0d..0000000 --- a/documentation/Prime.html +++ /dev/null @@ -1,244 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
# Prime Number Checking in R
-isPrime <- function(number) {
-  if (number == 2 | number == 3) {
-    return(TRUE)
-  } else if (number %% 2 == 0 | number %% 3 == 0){
-    return(FALSE)
-  } else {
-    k <- 1
-    while(6 * k - 1 <= sqrt(number)){
-      if(number %% (6 * k + 1) == 0){
-        return(FALSE)
-      } else if(number %% (6 * k - 1) == 0){
-        return(FALSE)
-      }
-      k <- k + 1
-    }
-    return(TRUE)
-  }
-}
-
-isPrime(2)
-
- -
## [1] TRUE
-
- -
isPrime(5)
-
- -
## [1] TRUE
-
- -
isPrime(4)
-
- -
## [1] FALSE
-
- - - - diff --git a/documentation/Prime.md b/documentation/Prime.md deleted file mode 100644 index fa5127f..0000000 --- a/documentation/Prime.md +++ /dev/null @@ -1,46 +0,0 @@ - - -```r -# Prime Number Checking in R -isPrime <- function(number) { - if (number == 2 | number == 3) { - return(TRUE) - } else if (number %% 2 == 0 | number %% 3 == 0){ - return(FALSE) - } else { - k <- 1 - while(6 * k - 1 <= sqrt(number)){ - if(number %% (6 * k + 1) == 0){ - return(FALSE) - } else if(number %% (6 * k - 1) == 0){ - return(FALSE) - } - k <- k + 1 - } - return(TRUE) - } -} - -isPrime(2) -``` - -``` -## [1] TRUE -``` - -```r -isPrime(5) -``` - -``` -## [1] TRUE -``` - -```r -isPrime(4) -``` - -``` -## [1] FALSE -``` - diff --git a/documentation/SVM.html b/documentation/SVM.html deleted file mode 100644 index 61d898c..0000000 --- a/documentation/SVM.html +++ /dev/null @@ -1,238 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
library(e1071)
-
- -
## Error in library(e1071): there is no package called 'e1071'
-
- -
x <- cbind(x_train,y_train)
-
- -
## Error in cbind(x_train, y_train): object 'x_train' not found
-
- -
# Fitting model
-fit <-svm(y_train ~ ., data = x)
-
- -
## Error in svm(y_train ~ ., data = x): could not find function "svm"
-
- -
summary(fit)
-
- -
## Error in summary(fit): object 'fit' not found
-
- -
# Predict Output 
-predicted= predict(fit,x_test)
-
- -
## Error in predict(fit, x_test): object 'fit' not found
-
- - - - diff --git a/documentation/SVM.md b/documentation/SVM.md deleted file mode 100644 index 4f5289c..0000000 --- a/documentation/SVM.md +++ /dev/null @@ -1,44 +0,0 @@ - - -```r -library(e1071) -``` - -``` -## Error in library(e1071): there is no package called 'e1071' -``` - -```r -x <- cbind(x_train,y_train) -``` - -``` -## Error in cbind(x_train, y_train): object 'x_train' not found -``` - -```r -# Fitting model -fit <-svm(y_train ~ ., data = x) -``` - -``` -## Error in svm(y_train ~ ., data = x): could not find function "svm" -``` - -```r -summary(fit) -``` - -``` -## Error in summary(fit): object 'fit' not found -``` - -```r -# Predict Output -predicted= predict(fit,x_test) -``` - -``` -## Error in predict(fit, x_test): object 'fit' not found -``` - diff --git a/documentation/amicable_numbers.html b/documentation/amicable_numbers.html deleted file mode 100644 index f88e4be..0000000 --- a/documentation/amicable_numbers.html +++ /dev/null @@ -1,243 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
# Amicable numbers checker in R:
-    are_numbers_amicable <- function(x, y) {
-
-        #' @description Checks if numbers passed as a parameter are amicable numbers.
-        #' @param x first number to check
-        #' @param y second number to check
-        #' @usage are_numbers_amicable(x, y)
-        #' @details Amicable numbers are two different natural numbers related
-        #' in such a way that the sum of the proper divisors of each
-        #' is equal to the other number.
-        #' @references https://en.wikipedia.org/wiki/Amicable_numbers
-      
-        x_divisors_sum <- get_sum_of_divisors(x)
-        y_divisors_sum <- get_sum_of_divisors(y)
-      
-        return((x_divisors_sum == y) && (y_divisors_sum == x))
-      }
-      
-      get_sum_of_divisors <- function(n) {
-        sum <- 0
-        limit <- n - 1
-        for (i in 1:limit) {
-           if (n %% i == 0) {
-              sum <- sum + i
-           }
-        }
-      
-        return(sum)
-      }
-      
-      result <- are_numbers_amicable(220, 284)
-      print(result)  # expected true
-      
-      result <- are_numbers_amicable(15, 100)
-      print(result)  # expected false
-
- - - - diff --git a/documentation/amicable_numbers.md b/documentation/amicable_numbers.md deleted file mode 100644 index dfebe0d..0000000 --- a/documentation/amicable_numbers.md +++ /dev/null @@ -1,36 +0,0 @@ -```R -are_numbers_amicable <- function(x, y) { - - #' @description Checks if numbers passed as a parameter are amicable numbers. - #' @param x first number to check - #' @param y second number to check - #' @usage are_numbers_amicable(x, y) - #' @details Amicable numbers are two different natural numbers related - #' in such a way that the sum of the proper divisors of each - #' is equal to the other number. - #' @references https://en.wikipedia.org/wiki/Amicable_numbers - - x_divisors_sum <- get_sum_of_divisors(x) - y_divisors_sum <- get_sum_of_divisors(y) - - return((x_divisors_sum == y) && (y_divisors_sum == x)) -} - -get_sum_of_divisors <- function(n) { - sum <- 0 - limit <- n - 1 - for (i in 1:limit) { - if (n %% i == 0) { - sum <- sum + i - } - } - - return(sum) -} - -result <- are_numbers_amicable(220, 284) -print(result) # expected true - -result <- are_numbers_amicable(15, 100) -print(result) # expected false -``` \ No newline at end of file diff --git a/documentation/ann.html b/documentation/ann.html new file mode 100644 index 0000000..55e6eba --- /dev/null +++ b/documentation/ann.html @@ -0,0 +1,202 @@ + + + + + + + + + + +
+

+

+

+
+
+
library(neuralnet)
+
+
## Error in library(neuralnet): there is no package called 'neuralnet'
+
+
concrete<-read.csv(file = "concrete.txt",stringsAsFactors = F)#get the data
+
+
## Warning in file(file, "rt"): cannot open file 'concrete.txt': No such file or
+## directory
+
+
## Error in file(file, "rt"): cannot open the connection
+
+
normalize<-function(x){
+  return((x-min(x))/(max(x)-min(x)))
+}
+concrete<-as.data.frame(lapply(concrete, normalize))
+
+
## Error in lapply(concrete, normalize): object 'concrete' not found
+
+
concrete_train<-concrete[1:773,]
+
+
## Error in eval(expr, envir, enclos): object 'concrete' not found
+
+
concrete_test<-concrete[774:1030,]
+
+
## Error in eval(expr, envir, enclos): object 'concrete' not found
+
+
concrete_model<-neuralnet(strength~cement+slag+ash+water+superplastic+coarseagg+fineagg+age,data = concrete_train,hidden = 5)
+
+
## Error in neuralnet(strength ~ cement + slag + ash + water + superplastic + : could not find function "neuralnet"
+
+
model_res<-compute(concrete_model,concrete_test[,1:8])
+
+
## Error in compute(concrete_model, concrete_test[, 1:8]): could not find function "compute"
+
+
x=model_res$net.result
+
+
## Error in eval(expr, envir, enclos): object 'model_res' not found
+
+
y=concrete_test$strength
+
+
## Error in eval(expr, envir, enclos): object 'concrete_test' not found
+
+
cor(x,y)
+
+
## Error in is.data.frame(y): object 'y' not found
+
+
plot(concrete_model)
+
+
## Error in plot(concrete_model): object 'concrete_model' not found
+
+
+ + + + diff --git a/documentation/apriori.html b/documentation/apriori.html index 9f141da..7f567ae 100644 --- a/documentation/apriori.html +++ b/documentation/apriori.html @@ -1,255 +1,185 @@ - - + + - - - - - - - - - - - + - - - - -
library(arules)
+
+

+

+

+
+
+
library(arules)
 
- -
## Error in library(arules): there is no package called 'arules'
+
## Error in library(arules): there is no package called 'arules'
 
- -
groceries <- read.transactions("groceries.csv", sep=",")
+
groceries <- read.transactions("groceries.csv", sep=",")
 
-
## Error in read.transactions("groceries.csv", sep = ","): could not find function "read.transactions"
 
- -
summary(groceries)
+
summary(groceries)
 
- -
## Error in summary(groceries): object 'groceries' not found
+
## Error in summary(groceries): object 'groceries' not found
 
- -
itemFrequencyPlot(groceries, topN=20)
+
itemFrequencyPlot(groceries, topN=20)
 
-
## Error in itemFrequencyPlot(groceries, topN = 20): could not find function "itemFrequencyPlot"
 
- -
#sample for randomly extracting samples, image function for visualing sparse matrix
+
#sample for randomly extracting samples, image function for visualing sparse matrix
 image(sample(groceries,100))
 
- -
## Error in sample(groceries, 100): object 'groceries' not found
+
## Error in sample(groceries, 100): object 'groceries' not found
 
- -
groceries_rule <- apriori(data=groceries, parameter=list(support=0.006, confidence=0.25, minlen=2))
+
groceries_rule <- apriori(data=groceries, parameter=list(support=0.006, confidence=0.25, minlen=2))
 
-
## Error in apriori(data = groceries, parameter = list(support = 0.006, confidence = 0.25, : could not find function "apriori"
 
- -
plotly_arules(groceries_rule)
+
plotly_arules(groceries_rule)
 
-
## Error in plotly_arules(groceries_rule): could not find function "plotly_arules"
 
- -
summary(groceries_rule)
+
summary(groceries_rule)
 
- -
## Error in summary(groceries_rule): object 'groceries_rule' not found
+
## Error in summary(groceries_rule): object 'groceries_rule' not found
 
- +
+ + - diff --git a/documentation/binary_insertion_sort.html b/documentation/binary_insertion_sort.html new file mode 100644 index 0000000..ab140ea --- /dev/null +++ b/documentation/binary_insertion_sort.html @@ -0,0 +1,198 @@ + + + + + + + + + + +
+

+

+

+
+
+
# Binary Insertion Sort Function
+# Sorts an input vector using the Binary Insertion Sort algorithm.
+# Parameters:
+# - arr: Input vector to be sorted.
+# Returns:
+# - Sorted vector.
+binary_insertion_sort <- function(arr) {
+  # Loop through the input vector starting from the second element.
+  for (i in 2:length(arr)) {
+    # Store the current element in a variable.
+    key <- arr[i]
+    # Initialize left and right pointers for binary search.
+    left <- 1
+    right <- i - 1
+    
+    # Binary search to find the correct position to insert the key.
+    while (left <= right) {
+      mid <- left + (right - left) %/% 2
+      
+      if (key < arr[mid]) {
+        right <- mid - 1
+      } else {
+        left <- mid + 1
+      }
+    }
+    
+    # Shift elements to the right to make space for the key.
+    for (j in i: (left + 1)) {
+      arr[j] <- arr[j - 1]
+    }
+    
+    # Insert the key into its correct position.
+    arr[left] <- key
+  }
+  
+  # Return the sorted vector.
+  return(arr)
+}
+
+# Example usage:
+elements_vec <- c(64, 34, 25, 12, 22, 11, 90)
+sorted_vec <- binary_insertion_sort(elements_vec)
+print(sorted_vec)
+
+
## [1] 11 12 22 25 34 64 90 64
+
+
+ + + + diff --git a/documentation/binary_insertion_sort.md b/documentation/binary_insertion_sort.md new file mode 100644 index 0000000..44e477c --- /dev/null +++ b/documentation/binary_insertion_sort.md @@ -0,0 +1,52 @@ + + +```r +# Binary Insertion Sort Function +# Sorts an input vector using the Binary Insertion Sort algorithm. +# Parameters: +# - arr: Input vector to be sorted. +# Returns: +# - Sorted vector. +binary_insertion_sort <- function(arr) { + # Loop through the input vector starting from the second element. + for (i in 2:length(arr)) { + # Store the current element in a variable. + key <- arr[i] + # Initialize left and right pointers for binary search. + left <- 1 + right <- i - 1 + + # Binary search to find the correct position to insert the key. + while (left <= right) { + mid <- left + (right - left) %/% 2 + + if (key < arr[mid]) { + right <- mid - 1 + } else { + left <- mid + 1 + } + } + + # Shift elements to the right to make space for the key. + for (j in i: (left + 1)) { + arr[j] <- arr[j - 1] + } + + # Insert the key into its correct position. + arr[left] <- key + } + + # Return the sorted vector. + return(arr) +} + +# Example usage: +elements_vec <- c(64, 34, 25, 12, 22, 11, 90) +sorted_vec <- binary_insertion_sort(elements_vec) +print(sorted_vec) +``` + +``` +## [1] 11 12 22 25 34 64 90 64 +``` + diff --git a/documentation/binary_search.html b/documentation/binary_search.html new file mode 100644 index 0000000..aa059e9 --- /dev/null +++ b/documentation/binary_search.html @@ -0,0 +1,183 @@ + + + + + + + + + + +
+

+

+

+
+
+
binary_search <- function(arr, target) { #function for finding position of value 
+  low <- 1
+  high <- length(arr) 
+  
+  while (low <= high) {
+    mid <- low + (high - low) %/% 2 #finding mid of array
+    
+    if (arr[mid] == target) { #comapring the mis value with the value to search
+      return(mid)  # Target found, return its index
+    } else if (arr[mid] < target) {
+      low <- mid + 1  # Search in the right half
+    } else {
+      high <- mid - 1  # Search in the left half
+    }
+  }
+  return(-1)  # Target not found in the array
+}
+
+arr <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) #input array (hard code)
+target <- 7 #input value to be searched (hard code)
+
+result <- binary_search(arr, target) #binary_seach function calling
+
+if (result == -1) {
+  cat("Element", target, "not found in the array.\n")
+} else {
+  cat("Element", target, "found at position", result, ".\n")
+}
+
+
## Element 7 found at position 7 .
+
+
+ + + + diff --git a/documentation/binary_search.md b/documentation/binary_search.md new file mode 100644 index 0000000..de58404 --- /dev/null +++ b/documentation/binary_search.md @@ -0,0 +1,37 @@ + + +```r +binary_search <- function(arr, target) { #function for finding position of value + low <- 1 + high <- length(arr) + + while (low <= high) { + mid <- low + (high - low) %/% 2 #finding mid of array + + if (arr[mid] == target) { #comapring the mis value with the value to search + return(mid) # Target found, return its index + } else if (arr[mid] < target) { + low <- mid + 1 # Search in the right half + } else { + high <- mid - 1 # Search in the left half + } + } + return(-1) # Target not found in the array +} + +arr <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) #input array (hard code) +target <- 7 #input value to be searched (hard code) + +result <- binary_search(arr, target) #binary_seach function calling + +if (result == -1) { + cat("Element", target, "not found in the array.\n") +} else { + cat("Element", target, "found at position", result, ".\n") +} +``` + +``` +## Element 7 found at position 7 . +``` + diff --git a/documentation/bubble_sort.html b/documentation/bubble_sort.html index e0f86f7..3bbda65 100644 --- a/documentation/bubble_sort.html +++ b/documentation/bubble_sort.html @@ -1,207 +1,151 @@ - - + + - - - - - - - - - - - + - - - - -
# Bubble sort in R:
+
+

+

+

+
+
+
# Bubble sort in R:
 
 bubble.sort <- function(elements.vec) { 
   n <- length(elements.vec)
@@ -221,7 +165,8 @@
 # bubble.sort(c(5, 2, 3, 1, 4))
 # [1] 1 2 3 4 5
 
- +
+ + - diff --git a/documentation/bucket_sort.html b/documentation/bucket_sort.html new file mode 100644 index 0000000..290c089 --- /dev/null +++ b/documentation/bucket_sort.html @@ -0,0 +1,201 @@ + + + + + + + + + + +
+

+

+

+
+
+
# Bucket Sort Function
+# Sorts an input vector using the Bucket Sort algorithm.
+# Parameters:
+# - arr: Input vector to be sorted.
+# Returns:
+# - Sorted vector.
+bucket_sort <- function(arr) {
+  if (length(arr) == 0) {
+    return(arr)
+  }
+  
+  # Find the maximum and minimum values in the input vector
+  max_val <- max(arr)
+  min_val <- min(arr)
+  
+  # Create an array of buckets
+  num_buckets <- max_val - min_val + 1
+  buckets <- vector("list", length = num_buckets)
+  
+  # Initialize the buckets
+  for (i in 1:num_buckets) {
+    buckets[[i]] <- numeric(0)
+  }
+  
+  # Place elements into buckets
+  for (val in arr) {
+    bucket_index <- val - min_val + 1
+    buckets[[bucket_index]] <- c(buckets[[bucket_index]], val)
+  }
+  
+  # Sort each bucket (using any sorting algorithm, e.g., Bubble Sort)
+  sorted_buckets <- lapply(buckets, bubble.sort)
+  
+  # Concatenate the sorted buckets to obtain the final sorted array
+  sorted_arr <- unlist(sorted_buckets)
+  
+  return(sorted_arr)
+}
+
+# Example usage:
+elements_vec <- c(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5)
+bucket_sorted_vec <- bucket_sort(elements_vec)
+
+
## Error in match.fun(FUN): object 'bubble.sort' not found
+
+
print(bucket_sorted_vec)
+
+
## Error in print(bucket_sorted_vec): object 'bucket_sorted_vec' not found
+
+
+ + + + diff --git a/documentation/bucket_sort.md b/documentation/bucket_sort.md new file mode 100644 index 0000000..d88dda8 --- /dev/null +++ b/documentation/bucket_sort.md @@ -0,0 +1,59 @@ + + +```r +# Bucket Sort Function +# Sorts an input vector using the Bucket Sort algorithm. +# Parameters: +# - arr: Input vector to be sorted. +# Returns: +# - Sorted vector. +bucket_sort <- function(arr) { + if (length(arr) == 0) { + return(arr) + } + + # Find the maximum and minimum values in the input vector + max_val <- max(arr) + min_val <- min(arr) + + # Create an array of buckets + num_buckets <- max_val - min_val + 1 + buckets <- vector("list", length = num_buckets) + + # Initialize the buckets + for (i in 1:num_buckets) { + buckets[[i]] <- numeric(0) + } + + # Place elements into buckets + for (val in arr) { + bucket_index <- val - min_val + 1 + buckets[[bucket_index]] <- c(buckets[[bucket_index]], val) + } + + # Sort each bucket (using any sorting algorithm, e.g., Bubble Sort) + sorted_buckets <- lapply(buckets, bubble.sort) + + # Concatenate the sorted buckets to obtain the final sorted array + sorted_arr <- unlist(sorted_buckets) + + return(sorted_arr) +} + +# Example usage: +elements_vec <- c(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5) +bucket_sorted_vec <- bucket_sort(elements_vec) +``` + +``` +## Error in match.fun(FUN): object 'bubble.sort' not found +``` + +```r +print(bucket_sorted_vec) +``` + +``` +## Error in print(bucket_sorted_vec): object 'bucket_sorted_vec' not found +``` + diff --git a/documentation/cocktail_sort.html b/documentation/cocktail_sort.html new file mode 100644 index 0000000..2f2625f --- /dev/null +++ b/documentation/cocktail_sort.html @@ -0,0 +1,212 @@ + + + + + + + + + + +
+

+

+

+
+
+
cocktailSort <- function(arr) {
+  n <- length(arr)
+  swapped <- TRUE
+  beg <- 1
+  end <- n - 1
+
+  while (swapped) {
+    swapped <- FALSE
+    
+    # Forward pass (left to right)
+    for (i in seq(beg, end)) {
+      if (arr[i] > arr[i + 1]) {
+        # Swap arr[i] and arr[i + 1]
+        temp <- arr[i]
+        arr[i] <- arr[i + 1]
+        arr[i + 1] <- temp
+        swapped <- TRUE
+      }
+    }
+
+    # If no swaps occurred in the forward pass, the array is sorted
+    if (!swapped) {
+      break
+    }
+
+    swapped <- FALSE
+    end <- end - 1
+
+    # Backward pass (right to left)
+    for (i in seq(end, beg, by = -1)) {
+      if (arr[i] > arr[i + 1]) {
+        # Swap arr[i] and arr[i + 1]
+        temp <- arr[i]
+        arr[i] <- arr[i + 1]
+        arr[i + 1] <- temp
+        swapped <- TRUE
+      }
+    }
+
+    beg <- beg + 1
+  }
+  
+  return(arr)
+}
+
+# Example Usage
+unsorted_array <- c(38, 27, 43, 3, 9, 82, 10)
+cat("Unsorted Array: ", unsorted_array, "\n")
+
+
## Unsorted Array:  38 27 43 3 9 82 10
+
+
# Call the Cocktail Sort function to sort the array
+sorted_array <- cocktailSort(unsorted_array)
+
+cat("Sorted Array: ", sorted_array, "\n")
+
+
## Sorted Array:  3 9 10 27 38 43 82
+
+
# Example: The 'unsorted_array' is sorted using Cocktail Sort
+
+
+ + + + diff --git a/documentation/cocktail_sort.md b/documentation/cocktail_sort.md new file mode 100644 index 0000000..d486aef --- /dev/null +++ b/documentation/cocktail_sort.md @@ -0,0 +1,72 @@ + + +```r +cocktailSort <- function(arr) { + n <- length(arr) + swapped <- TRUE + beg <- 1 + end <- n - 1 + + while (swapped) { + swapped <- FALSE + + # Forward pass (left to right) + for (i in seq(beg, end)) { + if (arr[i] > arr[i + 1]) { + # Swap arr[i] and arr[i + 1] + temp <- arr[i] + arr[i] <- arr[i + 1] + arr[i + 1] <- temp + swapped <- TRUE + } + } + + # If no swaps occurred in the forward pass, the array is sorted + if (!swapped) { + break + } + + swapped <- FALSE + end <- end - 1 + + # Backward pass (right to left) + for (i in seq(end, beg, by = -1)) { + if (arr[i] > arr[i + 1]) { + # Swap arr[i] and arr[i + 1] + temp <- arr[i] + arr[i] <- arr[i + 1] + arr[i + 1] <- temp + swapped <- TRUE + } + } + + beg <- beg + 1 + } + + return(arr) +} + +# Example Usage +unsorted_array <- c(38, 27, 43, 3, 9, 82, 10) +cat("Unsorted Array: ", unsorted_array, "\n") +``` + +``` +## Unsorted Array: 38 27 43 3 9 82 10 +``` + +```r +# Call the Cocktail Sort function to sort the array +sorted_array <- cocktailSort(unsorted_array) + +cat("Sorted Array: ", sorted_array, "\n") +``` + +``` +## Sorted Array: 3 9 10 27 38 43 82 +``` + +```r +# Example: The 'unsorted_array' is sorted using Cocktail Sort +``` + diff --git a/documentation/comb_sort.html b/documentation/comb_sort.html index 7419061..7860e2b 100644 --- a/documentation/comb_sort.html +++ b/documentation/comb_sort.html @@ -1,207 +1,151 @@ - - + + - - - - - - - - - - - + - - - - -
# Comb sort in R:
+
+

+

+

+
+
+
# Comb sort in R:
 
 comb.sort <- function(elements.vec) {
   gap <- length(elements.vec)
@@ -228,7 +172,8 @@
 # comb.sort(sample(1:100,10))
 # [1] 9 49 50 51 56 60 61 71 86 95
 
- +
+ + - diff --git a/documentation/counting_sort.html b/documentation/counting_sort.html new file mode 100644 index 0000000..67681ed --- /dev/null +++ b/documentation/counting_sort.html @@ -0,0 +1,179 @@ + + + + + + + + + + +
+

+

+

+
+
+
# Counting sort in R:
+
+counting.sort <- function(elements.vec){  
+  min <- min(elements.vec)
+  max <- max(elements.vec)  
+  count <- rep(0,(max - min + 1))
+  for(i in 1:length(elements.vec)){
+    x <- 1 - min + elements.vec[i]
+    count[x] <- count[x] + 1
+  } 
+  for(i in 2:length(count)){
+    count[i] <- count[i] + count[i-1]
+  }  
+  result <- rep(0,length(elements.vec))
+  for(i in 1:length(elements.vec)){
+    x <- 1 - min + elements.vec[i]
+    index <- count[x]
+    result[index] <- elements.vec[i]
+    count[x] = count[x] - 1
+  } 
+  return(result)  
+}
+
+# Example:
+# counting.sort(c(5, 2, 3, 1, 4))
+# [1] 1 2 3 4 5
+
+
+ + + + diff --git a/documentation/cycle_sort.html b/documentation/cycle_sort.html new file mode 100644 index 0000000..a648a7c --- /dev/null +++ b/documentation/cycle_sort.html @@ -0,0 +1,214 @@ + + + + + + + + + + +
+

+

+

+
+
+
# Cycle Sort Function
+# Sorts an input vector in-place using the Cycle Sort algorithm.
+# Parameters:
+# - arr: Input vector to be sorted.
+# Returns:
+# - Sorted vector.
+cycle_sort <- function(arr) {
+  n <- length(arr)
+  for (cycle_start in 1:(n - 1)) {
+    item <- arr[cycle_start]
+    pos <- cycle_start
+    
+    # Find the correct position for the current item
+    for (i in (cycle_start + 1):n) {
+      if (arr[i] < item) {
+        pos <- pos + 1
+      }
+    }
+    
+    # Skip if the item is already in the correct position
+    if (pos == cycle_start) {
+      next
+    }
+    
+    # Move the item to its correct position
+    while (item == arr[pos]) {
+      pos <- pos + 1
+    }
+    temp <- arr[pos]
+    arr[pos] <- item
+    item <- temp
+    
+    # Rotate the remaining cycle
+    while (pos != cycle_start) {
+      pos <- cycle_start
+      for (i in (cycle_start + 1):n) {
+        if (arr[i] < item) {
+          pos <- pos + 1
+        }
+      }
+      
+      # Skip if the item is already in the correct position
+      while (item == arr[pos]) {
+        pos <- pos + 1
+      }
+      
+      # Move the item to its correct position
+      temp <- arr[pos]
+      arr[pos] <- item
+      item <- temp
+    }
+  }
+  return(arr)
+}
+
+# Example usage:
+elements_vec <- c(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5)
+cycle_sorted_vec <- cycle_sort(elements_vec)
+print(cycle_sorted_vec)
+
+
##  [1] 1 1 2 3 3 4 5 5 5 6 9
+
+
+ + + + diff --git a/documentation/cycle_sort.md b/documentation/cycle_sort.md new file mode 100644 index 0000000..cfa53f3 --- /dev/null +++ b/documentation/cycle_sort.md @@ -0,0 +1,68 @@ + + +```r +# Cycle Sort Function +# Sorts an input vector in-place using the Cycle Sort algorithm. +# Parameters: +# - arr: Input vector to be sorted. +# Returns: +# - Sorted vector. +cycle_sort <- function(arr) { + n <- length(arr) + for (cycle_start in 1:(n - 1)) { + item <- arr[cycle_start] + pos <- cycle_start + + # Find the correct position for the current item + for (i in (cycle_start + 1):n) { + if (arr[i] < item) { + pos <- pos + 1 + } + } + + # Skip if the item is already in the correct position + if (pos == cycle_start) { + next + } + + # Move the item to its correct position + while (item == arr[pos]) { + pos <- pos + 1 + } + temp <- arr[pos] + arr[pos] <- item + item <- temp + + # Rotate the remaining cycle + while (pos != cycle_start) { + pos <- cycle_start + for (i in (cycle_start + 1):n) { + if (arr[i] < item) { + pos <- pos + 1 + } + } + + # Skip if the item is already in the correct position + while (item == arr[pos]) { + pos <- pos + 1 + } + + # Move the item to its correct position + temp <- arr[pos] + arr[pos] <- item + item <- temp + } + } + return(arr) +} + +# Example usage: +elements_vec <- c(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5) +cycle_sorted_vec <- cycle_sort(elements_vec) +print(cycle_sorted_vec) +``` + +``` +## [1] 1 1 2 3 3 4 5 5 5 6 9 +``` + diff --git a/documentation/data_normalization_standardization.html b/documentation/data_normalization_standardization.html index 881cda6..db7b09a 100644 --- a/documentation/data_normalization_standardization.html +++ b/documentation/data_normalization_standardization.html @@ -1,207 +1,151 @@ - - + + - - - - - - - - - - - + - - - - -
# normalization & standardization
+
+

+

+

+
+
+
# normalization & standardization
 normalization<-function(x){
   return((x-min(x))/(max(x)-min(x)))
 }
@@ -212,7 +156,6 @@
 
 head(iris)
 
-
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
 ## 1          5.1         3.5          1.4         0.2  setosa
 ## 2          4.9         3.0          1.4         0.2  setosa
@@ -221,8 +164,7 @@
 ## 5          5.0         3.6          1.4         0.2  setosa
 ## 6          5.4         3.9          1.7         0.4  setosa
 
- -
# Sepal.Length Sepal.Width Petal.Length Petal.Width Species
+
# Sepal.Length Sepal.Width Petal.Length Petal.Width Species
 # 1          5.1         3.5          1.4         0.2  setosa
 # 2          4.9         3.0          1.4         0.2  setosa
 # 3          4.7         3.2          1.3         0.2  setosa
@@ -233,7 +175,6 @@
 iris<-iris[,-5]
 head(iris)
 
-
##   Sepal.Length Sepal.Width Petal.Length Petal.Width
 ## 1          5.1         3.5          1.4         0.2
 ## 2          4.9         3.0          1.4         0.2
@@ -242,8 +183,7 @@
 ## 5          5.0         3.6          1.4         0.2
 ## 6          5.4         3.9          1.7         0.4
 
- -
# Sepal.Length Sepal.Width Petal.Length Petal.Width
+
# Sepal.Length Sepal.Width Petal.Length Petal.Width
 # 1          5.1         3.5          1.4         0.2
 # 2          4.9         3.0          1.4         0.2
 # 3          4.7         3.2          1.3         0.2
@@ -254,7 +194,6 @@
 #normalize
 apply(as.matrix(iris),2,normalization)
 
-
##        Sepal.Length Sepal.Width Petal.Length Petal.Width
 ##   [1,]   0.22222222  0.62500000   0.06779661  0.04166667
 ##   [2,]   0.16666667  0.41666667   0.06779661  0.04166667
@@ -407,8 +346,7 @@
 ## [149,]   0.52777778  0.58333333   0.74576271  0.91666667
 ## [150,]   0.44444444  0.41666667   0.69491525  0.70833333
 
- -
# Sepal.Length Sepal.Width Petal.Length Petal.Width
+
# Sepal.Length Sepal.Width Petal.Length Petal.Width
 # [1,]   0.22222222  0.62500000   0.06779661  0.04166667
 # [2,]   0.16666667  0.41666667   0.06779661  0.04166667
 # [3,]   0.11111111  0.50000000   0.05084746  0.04166667
@@ -420,7 +358,6 @@
 #standardize
 apply(as.matrix(iris),2,standardization)
 
-
##        Sepal.Length Sepal.Width Petal.Length   Petal.Width
 ##   [1,]  -0.89767388  1.01560199  -1.33575163 -1.3110521482
 ##   [2,]  -1.13920048 -0.13153881  -1.33575163 -1.3110521482
@@ -573,8 +510,7 @@
 ## [149,]   0.43072244  0.78617383   0.93015445  1.4439940605
 ## [150,]   0.06843254 -0.13153881   0.76021149  0.7880306775
 
- -
# Sepal.Length Sepal.Width Petal.Length   Petal.Width
+
# Sepal.Length Sepal.Width Petal.Length   Petal.Width
 # [1,]  -0.89767388  1.01560199  -1.33575163 -1.3110521482
 # [2,]  -1.13920048 -0.13153881  -1.33575163 -1.3110521482
 # [3,]  -1.38072709  0.32731751  -1.39239929 -1.3110521482
@@ -583,7 +519,8 @@
 # [6,]  -0.53538397  1.93331463  -1.16580868 -1.0486667950
 # [7,]  -1.50149039  0.78617383  -1.33575163 -1.1798594716
 
- +
+ + - diff --git a/documentation/data_processing.html b/documentation/data_processing.html index 545803e..6c658d4 100644 --- a/documentation/data_processing.html +++ b/documentation/data_processing.html @@ -1,241 +1,175 @@ - - + + - - - - - - - - - - - + - - - - -
library(xlsx)
+
+

+

+

+
+
+
library(xlsx)
 
- -
## Error in library(xlsx): there is no package called 'xlsx'
+
## Error in library(xlsx): there is no package called 'xlsx'
 
- -
## Loading required package: rJava
+
## Loading required package: rJava
 ## Loading required package: xlsxjars
 
 setwd("/Users/chenfeiyang")
 
-
## Error in setwd("/Users/chenfeiyang"): cannot change working directory
 
- -
cameraData <- read.xlsx("./data/cameras.xlsx", sheetIndex = 1, header = TRUE)
+
cameraData <- read.xlsx("./data/cameras.xlsx", sheetIndex = 1, header = TRUE)
 
-
## Error in read.xlsx("./data/cameras.xlsx", sheetIndex = 1, header = TRUE): could not find function "read.xlsx"
 
- -
cameraData <- read.xlsx("./data/cameras.xlsx", "Baltimore Fixed Speed Cameras", 
+
cameraData <- read.xlsx("./data/cameras.xlsx", "Baltimore Fixed Speed Cameras", 
     header = TRUE)
 
-
## Error in read.xlsx("./data/cameras.xlsx", "Baltimore Fixed Speed Cameras", : could not find function "read.xlsx"
 
- -
head(cameraData)
+
head(cameraData)
 
- -
## Error in head(cameraData): object 'cameraData' not found
+
## Error in head(cameraData): object 'cameraData' not found
 
- -
##                          address direction      street  crossStreet
+
##                          address direction      street  crossStreet
 ## 1       S CATON AVE & BENSON AVE       N/B   Caton Ave   Benson Ave
 ## 2       S CATON AVE & BENSON AVE       S/B   Caton Ave   Benson Ave
 ## 3 WILKENS AVE & PINE HEIGHTS AVE       E/B Wilkens Ave Pine Heights
@@ -256,17 +190,13 @@
 cameraDataSubset <- read.xlsx("./data/cameras.xlsx", sheetIndex = 1, colIndex = colIndex, 
     rowIndex = rowIndex)
 
-
## Error in read.xlsx("./data/cameras.xlsx", sheetIndex = 1, colIndex = colIndex, : could not find function "read.xlsx"
 
- -
cameraDataSubset
+
cameraDataSubset
 
- -
## Error in eval(expr, envir, enclos): object 'cameraDataSubset' not found
+
## Error in eval(expr, envir, enclos): object 'cameraDataSubset' not found
 
- -
##   direction      street
+
##   direction      street
 ## 1       N/B   Caton Ave
 ## 2       S/B   Caton Ave
 ## 3       E/B Wilkens Ave
@@ -278,7 +208,6 @@
 X$var2[c(1, 3)] = NA
 X
 
-
##   var1 var2 var3
 ## 5    2   NA   11
 ## 4    4   10   12
@@ -286,8 +215,7 @@
 ## 2    1    7   15
 ## 3    5    6   13
 
- -
##   var1 var2 var3
+
##   var1 var2 var3
 ## 1    2   NA   15
 ## 4    1   10   11
 ## 2    3   NA   12
@@ -296,48 +224,38 @@
 
 X[, 1]
 
-
## [1] 2 4 3 1 5
 
- -
## [1] 2 1 3 5 4
+
## [1] 2 1 3 5 4
 X[, "var1"]
 
-
## [1] 2 4 3 1 5
 
- -
## [1] 2 1 3 5 4
+
## [1] 2 1 3 5 4
 X[1:2, "var2"]
 
-
## [1] NA 10
 
- -
## [1] NA 10
+
## [1] NA 10
 
 # Logicals and: & , or: |
 X[(X$var1 <= 3 & X$var3 > 11), ]
 
-
##   var1 var2 var3
 ## 1    3   NA   14
 ## 2    1    7   15
 
- -
##   var1 var2 var3
+
##   var1 var2 var3
 ## 1    2   NA   15
 ## 2    3   NA   12
 X[(X$var1 <= 3 | X$var3 > 15), ]
 
-
##   var1 var2 var3
 ## 5    2   NA   11
 ## 1    3   NA   14
 ## 2    1    7   15
 
- -
##   var1 var2 var3
+
##   var1 var2 var3
 ## 1    2   NA   15
 ## 4    1   10   11
 ## 2    3   NA   12
@@ -345,42 +263,33 @@
 ## Dealing with missing values
 X[which(X$var2 > 8), ]
 
-
##   var1 var2 var3
 ## 4    4   10   12
 
- -
##   var1 var2 var3
+
##   var1 var2 var3
 ## 4    1   10   11
 ## 5    4    9   13
 
 # Sorting
 sort(X$var1)
 
-
## [1] 1 2 3 4 5
 
- -
## [1] 1 2 3 4 5
+
## [1] 1 2 3 4 5
 sort(X$var1, decreasing = TRUE)
 
-
## [1] 5 4 3 2 1
 
- -
## [1] 5 4 3 2 1
+
## [1] 5 4 3 2 1
 sort(X$var2, na.last = TRUE)
 
-
## [1]  6  7 10 NA NA
 
- -
## [1]  6  9 10 NA NA
+
## [1]  6  9 10 NA NA
 
 # Ordering
 X[order(X$var1), ]
 
-
##   var1 var2 var3
 ## 2    1    7   15
 ## 5    2   NA   11
@@ -388,8 +297,7 @@
 ## 4    4   10   12
 ## 3    5    6   13
 
- -
##   var1 var2 var3
+
##   var1 var2 var3
 ## 4    1   10   11
 ## 1    2   NA   15
 ## 2    3   NA   12
@@ -398,7 +306,6 @@
 
 X[order(X$var1, X$var3), ]
 
-
##   var1 var2 var3
 ## 2    1    7   15
 ## 5    2   NA   11
@@ -406,8 +313,7 @@
 ## 4    4   10   12
 ## 3    5    6   13
 
- -
##   var1 var2 var3
+
##   var1 var2 var3
 ## 4    1   10   11
 ## 1    2   NA   15
 ## 2    3   NA   12
@@ -418,17 +324,13 @@
 
 library(plyr)
 
- -
## Error in library(plyr): there is no package called 'plyr'
+
## Error in library(plyr): there is no package called 'plyr'
 
- -
arrange(X, var1)
+
arrange(X, var1)
 
-
## Error in arrange(X, var1): could not find function "arrange"
 
- -
##   var1 var2 var3
+
##   var1 var2 var3
 ## 1    1   10   11
 ## 2    2   NA   15
 ## 3    3   NA   12
@@ -437,11 +339,9 @@
 
 arrange(X, desc(var1))
 
-
## Error in arrange(X, desc(var1)): could not find function "arrange"
 
- -
##   var1 var2 var3
+
##   var1 var2 var3
 ## 1    5    6   14
 ## 2    4    9   13
 ## 3    3   NA   12
@@ -452,7 +352,6 @@
 X$var4 <- rnorm(5)
 X
 
-
##   var1 var2 var3       var4
 ## 5    2   NA   11 -0.4150458
 ## 4    4   10   12  2.5437602
@@ -460,8 +359,7 @@
 ## 2    1    7   15 -0.6192328
 ## 3    5    6   13 -0.9261035
 
- -
##   var1 var2 var3     var4
+
##   var1 var2 var3     var4
 ## 1    2   NA   15  0.18760
 ## 4    1   10   11  1.78698
 ## 2    3   NA   12  0.49669
@@ -471,7 +369,6 @@
 Y <- cbind(X, rnorm(5))
 Y
 
-
##   var1 var2 var3       var4    rnorm(5)
 ## 5    2   NA   11 -0.4150458 -0.66549949
 ## 4    4   10   12  2.5437602 -0.02166735
@@ -479,15 +376,15 @@
 ## 2    1    7   15 -0.6192328  0.23900438
 ## 3    5    6   13 -0.9261035 -1.83245959
 
- -
##   var1 var2 var3     var4 rnorm(5)
+
##   var1 var2 var3     var4 rnorm(5)
 ## 1    2   NA   15  0.18760  0.62578
 ## 4    1   10   11  1.78698 -2.45084
 ## 2    3   NA   12  0.49669  0.08909
 ## 3    5    6   14  0.06318  0.47839
 ## 5    4    9   13 -0.53613  1.00053
 
- +
+ + - diff --git a/documentation/dbscan_clustering.html b/documentation/dbscan_clustering.html index 664f6f2..2ad5528 100644 --- a/documentation/dbscan_clustering.html +++ b/documentation/dbscan_clustering.html @@ -1,224 +1,164 @@ - - + + - - - - - - - - - - - + - - - - -
library(dbscan)
+
+

+

+

+
+
+
library(dbscan)
 
- -
## Error in library(dbscan): there is no package called 'dbscan'
+
## Error in library(dbscan): there is no package called 'dbscan'
 
- -
cl <- dbscan(iris[,-5], eps = .5, minPts = 5)
+
cl <- dbscan(iris[,-5], eps = .5, minPts = 5)
 
-
## Error in dbscan(iris[, -5], eps = 0.5, minPts = 5): could not find function "dbscan"
 
- -
plot(iris[,-5], col = cl$cluster)
+
plot(iris[,-5], col = cl$cluster)
 
- -
## Error in pairs.default(data.matrix(x), ...): object 'cl' not found
+
## Error in pairs.default(data.matrix(x), ...): object 'cl' not found
 
- +
+ + - diff --git a/documentation/decision_tree.html b/documentation/decision_tree.html index 741d3d9..179b5c9 100644 --- a/documentation/decision_tree.html +++ b/documentation/decision_tree.html @@ -1,233 +1,171 @@ - - + + - - - - - - - - - - - + - - - - -
library(rpart)
+
+

+

+

+
+
+
library(rpart)
 x <- cbind(x_train,y_train)
 
- -
## Error in cbind(x_train, y_train): object 'x_train' not found
+
## Error in cbind(x_train, y_train): object 'x_train' not found
 
- -
# grow tree 
+
# grow tree 
 fit <- rpart(y_train ~ ., data = x,method="class")
 
- -
## Error in model.frame.default(formula = y_train ~ ., data = x, na.action = function (x) : 'data' must be a data.frame, environment, or list
+
## Error in model.frame.default(formula = y_train ~ ., data = x, na.action = function (x) : 'data' must be a data.frame, environment, or list
 
- -
summary(fit)
+
summary(fit)
 
- -
## Error in summary(fit): object 'fit' not found
+
## Error in summary(fit): object 'fit' not found
 
- -
# Predict Output 
+
# Predict Output 
 predicted= predict(fit,x_test)
 
- -
## Error in predict(fit, x_test): object 'fit' not found
+
## Error in predict(fit, x_test): object 'fit' not found
 
- +
+ + - diff --git a/documentation/dimensionality_reduction_algorithms.html b/documentation/dimensionality_reduction_algorithms.html index 3bf38e2..92507e1 100644 --- a/documentation/dimensionality_reduction_algorithms.html +++ b/documentation/dimensionality_reduction_algorithms.html @@ -1,225 +1,165 @@ - - + + - - - - - - - - - - - + - - - - -
library(stats)
+
+

+

+

+
+
+
library(stats)
 pca <- princomp(train, cor = TRUE)
 
- -
## Error in princomp(train, cor = TRUE): object 'train' not found
+
## Error in princomp(train, cor = TRUE): object 'train' not found
 
- -
train_reduced  <- predict(pca,train)
+
train_reduced  <- predict(pca,train)
 
- -
## Error in predict(pca, train): object 'pca' not found
+
## Error in predict(pca, train): object 'pca' not found
 
- -
test_reduced  <- predict(pca,test)
+
test_reduced  <- predict(pca,test)
 
- -
## Error in predict(pca, test): object 'pca' not found
+
## Error in predict(pca, test): object 'pca' not found
 
- +
+ + - diff --git a/documentation/gmm.html b/documentation/gmm.html index 1189901..c710e2f 100644 --- a/documentation/gmm.html +++ b/documentation/gmm.html @@ -1,230 +1,168 @@ - - + + - - - - - - - - - - - + - - - - -
library(mclust) # Gaussian mixture model (GMM)
+
+

+

+

+
+
+
library(mclust) # Gaussian mixture model (GMM)
 
- -
## Error in library(mclust): there is no package called 'mclust'
+
## Error in library(mclust): there is no package called 'mclust'
 
- -
gmm_fit <- Mclust(iris[, 1:4]) # Fit a GMM model
+
gmm_fit <- Mclust(iris[, 1:4]) # Fit a GMM model
 
-
## Error in Mclust(iris[, 1:4]): could not find function "Mclust"
 
- -
summary(gmm_fit) # Summary table 
+
summary(gmm_fit) # Summary table 
 
- -
## Error in summary(gmm_fit): object 'gmm_fit' not found
+
## Error in summary(gmm_fit): object 'gmm_fit' not found
 
- -
plot(gmm_fit, 'BIC') # Select model based on BIC
+
plot(gmm_fit, 'BIC') # Select model based on BIC
 
- -
## Error in plot(gmm_fit, "BIC"): object 'gmm_fit' not found
+
## Error in plot(gmm_fit, "BIC"): object 'gmm_fit' not found
 
- +
+ + - diff --git a/documentation/heap_sort.html b/documentation/heap_sort.html index a05c836..8216d59 100644 --- a/documentation/heap_sort.html +++ b/documentation/heap_sort.html @@ -1,207 +1,151 @@ - - + + - - - - - - - - - - - + - - - - -
# Heap sort in R:
+
+

+

+

+
+
+
# Heap sort in R:
 
 build.heap <- function(elements.vec) {
   l = length(elements.vec)
@@ -265,7 +209,8 @@
 # heap.sort(build.heap(c(5, 2, 3, 1, 4))) 
 # [1] 1 2 3 4 5
 
- +
+ + - diff --git a/documentation/heirarchical_clustering.html b/documentation/heirarchical_clustering.html index e4f6aba..786b9dd 100644 --- a/documentation/heirarchical_clustering.html +++ b/documentation/heirarchical_clustering.html @@ -1,212 +1,157 @@ - - + + - - - - - - - - - - - + - - - - -
clusters <- hclust(dist(iris[, -5]))
+
+

+

+

+
+
+
set.seed(42)
+clusters <- hclust(dist(iris[, -5]))
 plot(clusters)
 
- -

plot of chunk unnamed-chunk-1

- +

plot of chunk unnamed-chunk-1

+
+ + - diff --git a/documentation/insertion_sort.html b/documentation/insertion_sort.html index c7180c4..a56dd56 100644 --- a/documentation/insertion_sort.html +++ b/documentation/insertion_sort.html @@ -1,207 +1,151 @@ - - + + - - - - - - - - - - - + - - - - -
# Insertion sort in R:
+
+

+

+

+
+
+
# Insertion sort in R:
 
 insertion.sort <- function(elements.vec) { 
   for (j in 2:length(elements.vec)) {
@@ -220,7 +164,8 @@
 # insertion.sort(c(5, 2, 3, 1, 4))
 # [1] 1 2 3 4 5
 
- +
+ + - diff --git a/documentation/josephus_problem.html b/documentation/josephus_problem.html deleted file mode 100644 index 491042d..0000000 --- a/documentation/josephus_problem.html +++ /dev/null @@ -1,236 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
# Insertion sort in R:
-    find_winner <- function(n, k) {
-
-        #' @description Finds the winner in the Josephus problem
-        #' @param n The number of people in the initial circle
-        #' @param k The count of each step
-        #' @usage find_winner(n, k)
-        #' @details In computer science and mathematics, the Josephus problem
-        #' (or Josephus permutation) is a theoretical problem related to a certain
-        #' counting-out game. Such games are used to pick out a person from a group.
-        #' @references https://en.wikipedia.org/wiki/Josephus_problem
-      
-        if (k > n) stop("Size of the group must be greater than step")
-      
-        winner <- 0
-      
-        for (i in 1:n) {
-           winner <- (winner + k) %% i
-        }
-      
-        return(winner + 1)
-      }
-      
-      result <- find_winner(11, 2)
-      print(result)  # expected 7
-      
-      result <- find_winner(5, 2)
-      print(result)  # expected 3
-
- - - - diff --git a/documentation/josephus_problem.md b/documentation/josephus_problem.md deleted file mode 100644 index f29719b..0000000 --- a/documentation/josephus_problem.md +++ /dev/null @@ -1,29 +0,0 @@ -```r -find_winner <- function(n, k) { - - #' @description Finds the winner in the Josephus problem - #' @param n The number of people in the initial circle - #' @param k The count of each step - #' @usage find_winner(n, k) - #' @details In computer science and mathematics, the Josephus problem - #' (or Josephus permutation) is a theoretical problem related to a certain - #' counting-out game. Such games are used to pick out a person from a group. - #' @references https://en.wikipedia.org/wiki/Josephus_problem - - if (k > n) stop("Size of the group must be greater than step") - - winner <- 0 - - for (i in 1:n) { - winner <- (winner + k) %% i - } - - return(winner + 1) -} - -result <- find_winner(11, 2) -print(result) # expected 7 - -result <- find_winner(5, 2) -print(result) # expected 3 -```r \ No newline at end of file diff --git a/documentation/k_folds.html b/documentation/k_folds.html new file mode 100644 index 0000000..08879ac --- /dev/null +++ b/documentation/k_folds.html @@ -0,0 +1,182 @@ + + + + + + + + + + +
+

+

+

+
+
+
# K folds cross validation is essential for machine learning
+# createFolds function in package caret is easy to use
+# here we write our own function
+
+get_k_folds<-function(y = c(),k = 10, isList = TRUE, seed = 123){
+  set.seed(seed)
+  folds<-sample(1:length(y), length(y))
+  every_n<-ceiling(length(y)/k)
+  matFolds<-suppressWarnings(matrix(folds, ncol=every_n, byrow = T))
+  
+  if(isList){
+    value<-NULL
+    rownames(matFolds)<-paste("Folds",1:k,sep="")
+    value<-lapply(1:k, function(x){
+      if(x == k){
+        return(matFolds[x,][1:(length(y)-every_n*(k-1))])
+      }else{
+        return(matFolds[x,])
+      }
+    })
+  }else{
+    value<-c()
+    for(i in 1:length(y)){
+      value[i]<-ceiling(i/every_n)
+    }
+  }
+  
+  return(value)
+}
+
+
+ + + + diff --git a/documentation/k_means.html b/documentation/k_means.html new file mode 100644 index 0000000..bc249b4 --- /dev/null +++ b/documentation/k_means.html @@ -0,0 +1,158 @@ + + + + + + + + + + +
+

+

+

+
+
+
library(cluster)
+set.seed(42)
+fit <- kmeans(X, 3) # 3 cluster solution
+
+
## Error in as.matrix(x): object 'X' not found
+
+
+ + + + diff --git a/documentation/kmeans_clustering.html b/documentation/kmeans_clustering.html index ba1bbfc..635f8d4 100644 --- a/documentation/kmeans_clustering.html +++ b/documentation/kmeans_clustering.html @@ -1,213 +1,158 @@ - - + + - - - - - - - - - - - + - - - - -
cl <- kmeans(iris[,-5], 3)
+
+

+

+

+
+
+
set.seed(42)
+cl <- kmeans(iris[,-5], 3)
 plot(iris[,-5], col = cl$cluster)
 points(cl$centers, col = 1:3, pch = 8)
 
- -

plot of chunk unnamed-chunk-1

- +

plot of chunk unnamed-chunk-1

+
+ + - diff --git a/documentation/kmeans_raw_R.html b/documentation/kmeans_raw_R.html deleted file mode 100644 index 05f7757..0000000 --- a/documentation/kmeans_raw_R.html +++ /dev/null @@ -1,261 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
custonKmeans<-function(dataset=NA,k=NA){
-  if(is.na(dataset) || is.na(k)){
-    stop("You must input valid parameters!")
-  }
-  Eudist<-function(x,y){
-    distance<-sqrt(sum((x-y)^2))
-    return (distance)
-  }
-
-  rows.dataset<-nrow(dataset)
-  continue.change=TRUE
-  initPoint<-dataset[sample.int(rows.dataset,size = k),]
-  formerPoint<-initPoint
-  iterPoint<-matrix(0,nrow = k,ncol = ncol(dataset))
-
-  #记录每一个点到每一个类的距离
-  error.matrix<-matrix(0,nrow=rows.dataset,ncol=k)
-  while(continue.change){
-    #记录每个点所属的类是哪一个
-    cluster.matrix<-matrix(0,nrow=rows.dataset,ncol=k)
-    for(i in 1:rows.dataset){#计算每个点到三个初始中心点的距离
-      for(j in 1:k){
-        error.matrix[i,j]<-Eudist(dataset[i,],formerPoint[j,])
-      }
-    }
-    #将每一个点所属的类计算出来
-    for(i in 1:rows.dataset){
-      cluster.matrix[i,which.min(error.matrix[i,])]<-1
-    }
-
-    #更新新的质心位置
-    for(i in 1:k){
-      iterPoint[i,]<-apply(dataset[which(cluster.matrix[,i] == 1),],2,"mean")
-    }
-    all.true<-c()
-    for(i in 1:k){
-      if(all(formerPoint[i,] == iterPoint[i,]) == T){
-        all.true[i]<-TRUE
-      }
-    }
-    formerPoint = iterPoint
-    continue.change=ifelse(all(all.true) == T,F,T)
-  }
-  colnames(iterPoint)<-colnames(dataset)
-  out=list()
-  out[["centers"]]<-iterPoint
-  out[["distance"]]<-error.matrix
-  out[["cluster"]]<-rep(1,rows.dataset)
-  for(i in 1:rows.dataset){
-    out[["cluster"]][i]<-which(cluster.matrix[i,] == 1)
-  }
-  return(out)
-}
-
- - - - diff --git a/documentation/kmeans_raw_R.md b/documentation/kmeans_raw_R.md deleted file mode 100644 index e33d7a0..0000000 --- a/documentation/kmeans_raw_R.md +++ /dev/null @@ -1,58 +0,0 @@ - - -```r -custonKmeans<-function(dataset=NA,k=NA){ - if(is.na(dataset) || is.na(k)){ - stop("You must input valid parameters!") - } - Eudist<-function(x,y){ - distance<-sqrt(sum((x-y)^2)) - return (distance) - } - - rows.dataset<-nrow(dataset) - continue.change=TRUE - initPoint<-dataset[sample.int(rows.dataset,size = k),] - formerPoint<-initPoint - iterPoint<-matrix(0,nrow = k,ncol = ncol(dataset)) - - #记录每一个点到每一个类的距离 - error.matrix<-matrix(0,nrow=rows.dataset,ncol=k) - while(continue.change){ - #记录每个点所属的类是哪一个 - cluster.matrix<-matrix(0,nrow=rows.dataset,ncol=k) - for(i in 1:rows.dataset){#计算每个点到三个初始中心点的距离 - for(j in 1:k){ - error.matrix[i,j]<-Eudist(dataset[i,],formerPoint[j,]) - } - } - #将每一个点所属的类计算出来 - for(i in 1:rows.dataset){ - cluster.matrix[i,which.min(error.matrix[i,])]<-1 - } - - #更新新的质心位置 - for(i in 1:k){ - iterPoint[i,]<-apply(dataset[which(cluster.matrix[,i] == 1),],2,"mean") - } - all.true<-c() - for(i in 1:k){ - if(all(formerPoint[i,] == iterPoint[i,]) == T){ - all.true[i]<-TRUE - } - } - formerPoint = iterPoint - continue.change=ifelse(all(all.true) == T,F,T) - } - colnames(iterPoint)<-colnames(dataset) - out=list() - out[["centers"]]<-iterPoint - out[["distance"]]<-error.matrix - out[["cluster"]]<-rep(1,rows.dataset) - for(i in 1:rows.dataset){ - out[["cluster"]][i]<-which(cluster.matrix[i,] == 1) - } - return(out) -} -``` - diff --git a/documentation/kmeans_raw_r.html b/documentation/kmeans_raw_r.html new file mode 100644 index 0000000..b62f018 --- /dev/null +++ b/documentation/kmeans_raw_r.html @@ -0,0 +1,206 @@ + + + + + + + + + + +
+

+

+

+
+
+
custonKmeans<-function(dataset=NA,k=NA){
+  if(is.na(dataset) || is.na(k)){
+    stop("You must input valid parameters!")
+  }
+  Eudist<-function(x,y){
+    distance<-sqrt(sum((x-y)^2))
+    return (distance)
+  }
+  
+  rows.dataset<-nrow(dataset)
+  continue.change=TRUE
+  initPoint<-dataset[sample.int(rows.dataset,size = k),]
+  formerPoint<-initPoint
+  iterPoint<-matrix(0,nrow = k,ncol = ncol(dataset))
+  
+  #记录每一个点到每一个类的距离
+  error.matrix<-matrix(0,nrow=rows.dataset,ncol=k)
+  while(continue.change){
+    #记录每个点所属的类是哪一个
+    cluster.matrix<-matrix(0,nrow=rows.dataset,ncol=k)
+    for(i in 1:rows.dataset){#计算每个点到三个初始中心点的距离
+      for(j in 1:k){
+        error.matrix[i,j]<-Eudist(dataset[i,],formerPoint[j,])
+      }
+    }
+    #将每一个点所属的类计算出来
+    for(i in 1:rows.dataset){
+      cluster.matrix[i,which.min(error.matrix[i,])]<-1
+    }
+    
+    #更新新的质心位置
+    for(i in 1:k){
+      iterPoint[i,]<-apply(dataset[which(cluster.matrix[,i] == 1),],2,"mean")
+    }
+    all.true<-c()
+    for(i in 1:k){
+      if(all(formerPoint[i,] == iterPoint[i,]) == T){
+        all.true[i]<-TRUE
+      }
+    }
+    formerPoint = iterPoint
+    continue.change=ifelse(all(all.true) == T,F,T)
+  }
+  colnames(iterPoint)<-colnames(dataset)
+  out=list()
+  out[["centers"]]<-iterPoint
+  out[["distance"]]<-error.matrix
+  out[["cluster"]]<-rep(1,rows.dataset)
+  for(i in 1:rows.dataset){
+    out[["cluster"]][i]<-which(cluster.matrix[i,] == 1)
+  }
+  return(out)
+}
+
+
+ + + + diff --git a/documentation/knn.html b/documentation/knn.html new file mode 100644 index 0000000..faf333e --- /dev/null +++ b/documentation/knn.html @@ -0,0 +1,174 @@ + + + + + + + + + + +
+

+

+

+
+
+
library(knn)
+
+
## Error in library(knn): there is no package called 'knn'
+
+
x <- cbind(x_train,y_train)
+
+
## Error in cbind(x_train, y_train): object 'x_train' not found
+
+
# Fitting model
+fit <-knn(y_train ~ ., data = x,k=5)
+
+
## Error in knn(y_train ~ ., data = x, k = 5): could not find function "knn"
+
+
summary(fit)
+
+
## Error in summary(fit): object 'fit' not found
+
+
# Predict Output 
+predicted= predict(fit,x_test)
+
+
## Error in predict(fit, x_test): object 'fit' not found
+
+
+ + + + diff --git a/documentation/lasso.html b/documentation/lasso.html index 3bde194..6e2b9d5 100644 --- a/documentation/lasso.html +++ b/documentation/lasso.html @@ -1,268 +1,196 @@ - - + + - - - - - - - - - - - + - - - - -
data(ggplot2::diamonds)
+
+

+

+

+
+
+
data(ggplot2::diamonds)
 
- -
## Warning in data(ggplot2::diamonds): data set 'ggplot2::diamonds' not found
+
## Warning in data(ggplot2::diamonds): data set 'ggplot2::diamonds' not found
 
- -
library(caret)
+
library(caret)
 
- -
## Error in library(caret): there is no package called 'caret'
+
## Error in library(caret): there is no package called 'caret'
 
- -
library(dplyr)
+
library(dplyr)
 
- -
## Error in library(dplyr): there is no package called 'dplyr'
+
## Error in library(dplyr): there is no package called 'dplyr'
 
- -
dia.trans<-bind_cols(diamonds %>% select_if(is.numeric),
+
dia.trans<-bind_cols(diamonds %>% select_if(is.numeric),
                      model.matrix(~cut-1,diamonds) %>% as_tibble(),
                      model.matrix(~color-1,diamonds) %>% as_tibble(),
                      model.matrix(~clarity-1,diamonds) %>% as_tibble())
 
-
## Error in bind_cols(diamonds %>% select_if(is.numeric), model.matrix(~cut - : could not find function "bind_cols"
 
- -
#setting parameters alpha and lambda
+
#setting parameters alpha and lambda
 lasso_expand<-expand.grid(alpha = 1, lambda = seq(0.001,0.1,by = 0.0005))
-lasso_mod <- train(x=dia.trans %>% select(-price), y=dia.trans$price, method='glmnet', 
+lasso_mod <- train(x=dia.trans %>% select(-price), y=dia.trans$price, method='glmnet', 
                    tuneGrid=lasso_expand)
 
-
## Error in train(x = dia.trans %>% select(-price), y = dia.trans$price, : could not find function "train"
 
- -
#best tune
+
#best tune
 lasso_mod$bestTune
 
- -
## Error in eval(expr, envir, enclos): object 'lasso_mod' not found
+
## Error in eval(expr, envir, enclos): object 'lasso_mod' not found
 
- -
lasso_mod$results$RMSE
+
lasso_mod$results$RMSE
 
- -
## Error in eval(expr, envir, enclos): object 'lasso_mod' not found
+
## Error in eval(expr, envir, enclos): object 'lasso_mod' not found
 
- -
lasso_imp<-varImp(lasso_mod)
+
lasso_imp<-varImp(lasso_mod)
 
-
## Error in varImp(lasso_mod): could not find function "varImp"
 
- -
#get the importance of each feature and eliminate some of them
+
#get the importance of each feature and eliminate some of them
 lasso_imp$importance
 
- -
## Error in eval(expr, envir, enclos): object 'lasso_imp' not found
+
## Error in eval(expr, envir, enclos): object 'lasso_imp' not found
 
- +
+ + - diff --git a/documentation/light_gbm.html b/documentation/light_gbm.html new file mode 100644 index 0000000..a6ed067 --- /dev/null +++ b/documentation/light_gbm.html @@ -0,0 +1,199 @@ + + + + + + + + + + +
+

+

+

+
+
+
library(RLightGBM)
+
+
## Error in library(RLightGBM): there is no package called 'RLightGBM'
+
+
data(example.binary)
+
+
## Warning in data(example.binary): data set 'example.binary' not found
+
+
#Parameters
+
+num_iterations <- 100
+config <- list(objective = "binary",  metric="binary_logloss,auc", learning_rate = 0.1, num_leaves = 63, tree_learner = "serial", feature_fraction = 0.8, bagging_freq = 5, bagging_fraction = 0.8, min_data_in_leaf = 50, min_sum_hessian_in_leaf = 5.0)
+
+#Create data handle and booster
+handle.data <- lgbm.data.create(x)
+
+
## Error in lgbm.data.create(x): could not find function "lgbm.data.create"
+
+
lgbm.data.setField(handle.data, "label", y)
+
+
## Error in lgbm.data.setField(handle.data, "label", y): could not find function "lgbm.data.setField"
+
+
handle.booster <- lgbm.booster.create(handle.data, lapply(config, as.character))
+
+
## Error in lgbm.booster.create(handle.data, lapply(config, as.character)): could not find function "lgbm.booster.create"
+
+
#Train for num_iterations iterations and eval every 5 steps
+
+lgbm.booster.train(handle.booster, num_iterations, 5)
+
+
## Error in lgbm.booster.train(handle.booster, num_iterations, 5): could not find function "lgbm.booster.train"
+
+
#Predict
+pred <- lgbm.booster.predict(handle.booster, x.test)
+
+
## Error in lgbm.booster.predict(handle.booster, x.test): could not find function "lgbm.booster.predict"
+
+
#Test accuracy
+sum(y.test == (y.pred > 0.5)) / length(y.test)
+
+
## Error in eval(expr, envir, enclos): object 'y.test' not found
+
+
#Save model (can be loaded again via lgbm.booster.load(filename))
+lgbm.booster.save(handle.booster, filename = "/tmp/model.txt")
+
+
## Error in lgbm.booster.save(handle.booster, filename = "/tmp/model.txt"): could not find function "lgbm.booster.save"
+
+
+ + + + diff --git a/documentation/linearRegressionRawR.html b/documentation/linearRegressionRawR.html deleted file mode 100644 index 53f777e..0000000 --- a/documentation/linearRegressionRawR.html +++ /dev/null @@ -1,221 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
ols<-function(y,x){
-    data<-model.matrix(y ~ ., data = x)
-    decomp <- svd(data)
-    return(decomp$v %*% diag(1 / decomp$d) %*% t(decomp$u) %*% y)
-  }
-
-set.seed(1)
-x <- rnorm(1000)
-y <- 4 * x + rnorm(1000, sd = .5)
-ols(y=y,x=matrix(x, ncol = 1))
-
- -
## Error in terms.formula(object, data = data): '.' in formula and no 'data' argument
-
- - - - diff --git a/documentation/linearRegressionRawR.md b/documentation/linearRegressionRawR.md deleted file mode 100644 index b21c937..0000000 --- a/documentation/linearRegressionRawR.md +++ /dev/null @@ -1,19 +0,0 @@ - - -```r -ols<-function(y,x){ - data<-model.matrix(y ~ ., data = x) - decomp <- svd(data) - return(decomp$v %*% diag(1 / decomp$d) %*% t(decomp$u) %*% y) - } - -set.seed(1) -x <- rnorm(1000) -y <- 4 * x + rnorm(1000, sd = .5) -ols(y=y,x=matrix(x, ncol = 1)) -``` - -``` -## Error in terms.formula(object, data = data): '.' in formula and no 'data' argument -``` - diff --git a/documentation/linear_regression.html b/documentation/linear_regression.html index ea7d905..88f9fcf 100644 --- a/documentation/linear_regression.html +++ b/documentation/linear_regression.html @@ -1,252 +1,184 @@ - - + + - - - - - - - - - - - + - - - - -
# Load Train and Test datasets
+
+

+

+

+
+
+
# Load Train and Test datasets
 # Identify feature and response variable(s) and values must be numeric and numpy arrays
 x_train <- input_variables_values_training_datasets
 
- -
## Error in eval(expr, envir, enclos): object 'input_variables_values_training_datasets' not found
+
## Error in eval(expr, envir, enclos): object 'input_variables_values_training_datasets' not found
 
- -
y_train <- target_variables_values_training_datasets
+
y_train <- target_variables_values_training_datasets
 
- -
## Error in eval(expr, envir, enclos): object 'target_variables_values_training_datasets' not found
+
## Error in eval(expr, envir, enclos): object 'target_variables_values_training_datasets' not found
 
- -
x_test <- input_variables_values_test_datasets
+
x_test <- input_variables_values_test_datasets
 
- -
## Error in eval(expr, envir, enclos): object 'input_variables_values_test_datasets' not found
+
## Error in eval(expr, envir, enclos): object 'input_variables_values_test_datasets' not found
 
- -
x <- cbind(x_train,y_train)
+
x <- cbind(x_train,y_train)
 
- -
## Error in cbind(x_train, y_train): object 'x_train' not found
+
## Error in cbind(x_train, y_train): object 'x_train' not found
 
- -
# Train the model using the training sets and check score
+
# Train the model using the training sets and check score
 linear <- lm(y_train ~ ., data = x)
 
- -
## Error in model.frame.default(formula = y_train ~ ., data = x, drop.unused.levels = TRUE): 'data' must be a data.frame, environment, or list
+
## Error in model.frame.default(formula = y_train ~ ., data = x, drop.unused.levels = TRUE): 'data' must be a data.frame, environment, or list
 
- -
summary(linear)
+
summary(linear)
 
- -
## Error in summary(linear): object 'linear' not found
+
## Error in summary(linear): object 'linear' not found
 
- -
# Predict Output
+
# Predict Output
 predicted= predict(linear,x_test) 
 
- -
## Error in predict(linear, x_test): object 'linear' not found
+
## Error in predict(linear, x_test): object 'linear' not found
 
- +
+ + - diff --git a/documentation/linear_search.html b/documentation/linear_search.html new file mode 100644 index 0000000..baa2abc --- /dev/null +++ b/documentation/linear_search.html @@ -0,0 +1,174 @@ + + + + + + + + + + +
+

+

+

+
+
+
linear_search<-function(vector, search_value){ #made a function named linear_search having two parameters that are an array and a value to be searched
+  for(i in 1:length(vector)){ 
+    if(vector[i]==search_value){ #comparing each value of array with the value to be searched
+      return (i)
+    }
+  }
+  return (-1)
+}
+
+user_vec<- c(10,20,30,40,50,60) #input array (hard code)
+user_val<-30 #input value to be searched (hard code)
+
+result<-linear_search(user_vec,user_val) #linear_seach function calling
+
+if(result!=-1){
+  cat("Searched value", user_val, "found at index", result-1) #displaying the index at which value is found (if any)
+}else{
+  cat("Searched value does not exist in array")
+}
+
+
## Searched value 30 found at index 2
+
+
+ + + + diff --git a/documentation/linear_search.md b/documentation/linear_search.md new file mode 100644 index 0000000..a7cb28a --- /dev/null +++ b/documentation/linear_search.md @@ -0,0 +1,28 @@ + + +```r +linear_search<-function(vector, search_value){ #made a function named linear_search having two parameters that are an array and a value to be searched + for(i in 1:length(vector)){ + if(vector[i]==search_value){ #comparing each value of array with the value to be searched + return (i) + } + } + return (-1) +} + +user_vec<- c(10,20,30,40,50,60) #input array (hard code) +user_val<-30 #input value to be searched (hard code) + +result<-linear_search(user_vec,user_val) #linear_seach function calling + +if(result!=-1){ + cat("Searched value", user_val, "found at index", result-1) #displaying the index at which value is found (if any) +}else{ + cat("Searched value does not exist in array") +} +``` + +``` +## Searched value 30 found at index 2 +``` + diff --git a/documentation/linearregressionrawr.html b/documentation/linearregressionrawr.html new file mode 100644 index 0000000..193f7df --- /dev/null +++ b/documentation/linearregressionrawr.html @@ -0,0 +1,165 @@ + + + + + + + + + + +
+

+

+

+
+
+
ols<-function(y,x){
+    data<-model.matrix(y ~ ., data = x)
+    decomp <- svd(data)
+    return(decomp$v %*% diag(1 / decomp$d) %*% t(decomp$u) %*% y)
+  }
+
+set.seed(1)
+x <- rnorm(1000)
+y <- 4 * x + rnorm(1000, sd = .5)
+ols(y=y,x=matrix(x, ncol = 1))
+
+
## Error in terms.formula(object, data = data): '.' in formula and no 'data' argument
+
+
+ + + + diff --git a/documentation/logistic_regression.html b/documentation/logistic_regression.html index 657b76e..a064aca 100644 --- a/documentation/logistic_regression.html +++ b/documentation/logistic_regression.html @@ -1,232 +1,170 @@ - - + + - - - - - - - - - - - + - - - - -
x <- cbind(x_train,y_train)
+
+

+

+

+
+
+
x <- cbind(x_train,y_train)
 
- -
## Error in cbind(x_train, y_train): object 'x_train' not found
+
## Error in cbind(x_train, y_train): object 'x_train' not found
 
- -
# Train the model using the training sets and check score
-logistic <- glm(y_train ~ ., data = x,family='binomial')
+
# Train the model using the training sets and check score
+logistic <- glm(y_train ~ ., data = x,family='binomial')
 
- -
## Error in model.frame.default(formula = y_train ~ ., data = x, drop.unused.levels = TRUE): 'data' must be a data.frame, environment, or list
+
## Error in model.frame.default(formula = y_train ~ ., data = x, drop.unused.levels = TRUE): 'data' must be a data.frame, environment, or list
 
- -
summary(logistic)
+
summary(logistic)
 
- -
## Error in summary(logistic): object 'logistic' not found
+
## Error in summary(logistic): object 'logistic' not found
 
- -
# Predict Output
+
# Predict Output
 predicted= predict(logistic,x_test)
 
- -
## Error in predict(logistic, x_test): object 'logistic' not found
+
## Error in predict(logistic, x_test): object 'logistic' not found
 
- +
+ + - diff --git a/documentation/logistic_regression2.html b/documentation/logistic_regression2.html deleted file mode 100644 index f25c59c..0000000 --- a/documentation/logistic_regression2.html +++ /dev/null @@ -1,229 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
# Introduction to logistic regression
-
-# glm stands for Generalized Linear Model
-mod1 <- glm(y_data~x_data, data=name_of_the_dataframe, family="binomial")
-
- -
## Error in is.data.frame(data): object 'name_of_the_dataframe' not found
-
- -
# displays the output of the model computed by the previous line
-summary(mod1)
-
- -
## Error in summary(mod1): object 'mod1' not found
-
- -
# modeled data : it predicts the output for x_test_data as input information for the model
-predicted <- predict(mod1, x_test_data)
-
- -
## Error in predict(mod1, x_test_data): object 'mod1' not found
-
- - - - diff --git a/documentation/logistic_regression2.md b/documentation/logistic_regression2.md deleted file mode 100644 index 2b973b4..0000000 --- a/documentation/logistic_regression2.md +++ /dev/null @@ -1,31 +0,0 @@ - - -```r -# Introduction to logistic regression - -# glm stands for Generalized Linear Model -mod1 <- glm(y_data~x_data, data=name_of_the_dataframe, family="binomial") -``` - -``` -## Error in is.data.frame(data): object 'name_of_the_dataframe' not found -``` - -```r -# displays the output of the model computed by the previous line -summary(mod1) -``` - -``` -## Error in summary(mod1): object 'mod1' not found -``` - -```r -# modeled data : it predicts the output for x_test_data as input information for the model -predicted <- predict(mod1, x_test_data) -``` - -``` -## Error in predict(mod1, x_test_data): object 'mod1' not found -``` - diff --git a/documentation/logistic_regression_2.html b/documentation/logistic_regression_2.html new file mode 100644 index 0000000..bde3ccb --- /dev/null +++ b/documentation/logistic_regression_2.html @@ -0,0 +1,169 @@ + + + + + + + + + + +
+

+

+

+
+
+
# Introduction to logistic regression
+
+# glm stands for Generalized Linear Model
+mod1 <- glm(y_data~x_data, data=name_of_the_dataframe, family="binomial")
+
+
## Error in is.data.frame(data): object 'name_of_the_dataframe' not found
+
+
# displays the output of the model computed by the previous line
+summary(mod1)
+
+
## Error in summary(mod1): object 'mod1' not found
+
+
# modeled data : it predicts the output for x_test_data as input information for the model
+predicted <- predict(mod1, x_test_data)
+
+
## Error in predict(mod1, x_test_data): object 'mod1' not found
+
+
+ + + + diff --git a/documentation/merge_sort.html b/documentation/merge_sort.html index 94d24b5..a984733 100644 --- a/documentation/merge_sort.html +++ b/documentation/merge_sort.html @@ -1,207 +1,151 @@ - - + + - - - - - - - - - - - + - - - - -
# Merge sort in R:
+
+

+

+

+
+
+
# Merge sort in R:
 
 merge.func <-function(leftArray, rightArray) {
     l <- numeric(length(leftArray) + length(rightArray))
@@ -234,7 +178,8 @@
 # merge.sort(c(5, 2, 3, 1, 4)) 
 # [1] 1 2 3 4 5
 
- +
+ + - diff --git a/documentation/multiple_linear_regression.html b/documentation/multiple_linear_regression.html index 37a003a..46296ef 100644 --- a/documentation/multiple_linear_regression.html +++ b/documentation/multiple_linear_regression.html @@ -1,230 +1,170 @@ - - + + - - - - - - - - - - - + - - - - -
# Introduction to multiple linear regression
+
+

+

+

+
+
+
# Introduction to multiple linear regression
 
 # lm stands for Linear Model
 # y_data are modeled as a.x1 + b.x2 + c.x3 + d.x4 + e
 mod3 <- lm(y_data~x1_data+x2_data+x3_data+x4_data, data=name_of_the_dataframe)
 
- -
## Error in is.data.frame(data): object 'name_of_the_dataframe' not found
+
## Error in is.data.frame(data): object 'name_of_the_dataframe' not found
 
- -
# displays the output of the model computed by the previous line
+
# displays the output of the model computed by the previous line
 summary(mod3)
 
- -
## Error in summary(mod3): object 'mod3' not found
+
## Error in summary(mod3): object 'mod3' not found
 
- -
# modeled data : it predicts the output for x_test_data as input information for the model
+
# modeled data : it predicts the output for x_test_data as input information for the model
 predicted <- predict(mod3, x1_test_data, x2_test_data, x3_test_data, x4_test_data)
 
- -
## Error in predict(mod3, x1_test_data, x2_test_data, x3_test_data, x4_test_data): object 'mod3' not found
+
## Error in predict(mod3, x1_test_data, x2_test_data, x3_test_data, x4_test_data): object 'mod3' not found
 
- +
+ + - diff --git a/documentation/naive_bayes.html b/documentation/naive_bayes.html index e9c0299..17fd93f 100644 --- a/documentation/naive_bayes.html +++ b/documentation/naive_bayes.html @@ -1,238 +1,174 @@ - - + + - - - - - - - - - - - + - - - - -
library(e1071)
+
+

+

+

+
+
+
library(e1071)
 
- -
## Error in library(e1071): there is no package called 'e1071'
+
## Error in library(e1071): there is no package called 'e1071'
 
- -
x <- cbind(x_train,y_train)
+
x <- cbind(x_train,y_train)
 
- -
## Error in cbind(x_train, y_train): object 'x_train' not found
+
## Error in cbind(x_train, y_train): object 'x_train' not found
 
- -
# Fitting model
+
# Fitting model
 fit <-naiveBayes(y_train ~ ., data = x)
 
-
## Error in naiveBayes(y_train ~ ., data = x): could not find function "naiveBayes"
 
- -
summary(fit)
+
summary(fit)
 
- -
## Error in summary(fit): object 'fit' not found
+
## Error in summary(fit): object 'fit' not found
 
- -
# Predict Output 
+
# Predict Output 
 predicted= predict(fit,x_test)
 
- -
## Error in predict(fit, x_test): object 'fit' not found
+
## Error in predict(fit, x_test): object 'fit' not found
 
- +
+ + - diff --git a/documentation/odd_even_sort.html b/documentation/odd_even_sort.html new file mode 100644 index 0000000..d305c5c --- /dev/null +++ b/documentation/odd_even_sort.html @@ -0,0 +1,194 @@ + + + + + + + + + + +
+

+

+

+
+
+
# Odd-Even Sort Function
+# Sorts an input vector in-place using the Odd-Even Sort algorithm.
+# Parameters:
+# - arr: Input vector to be sorted.
+# Returns:
+# - Sorted vector.
+odd_even_sort <- function(arr) {
+  n <- length(arr)
+  sorted <- FALSE
+  while (!sorted) {
+    sorted <- TRUE
+    
+    # Odd-Even Sort (Phase 1 - Odd)
+    for (i in seq(1, n - 1, by = 2)) {
+      if (arr[i] > arr[i + 1]) {
+        temp <- arr[i]
+        arr[i] <- arr[i + 1]
+        arr[i + 1] <- temp
+        sorted <- FALSE
+      }
+    }
+    
+    # Odd-Even Sort (Phase 2 - Even)
+    for (i in seq(2, n - 1, by = 2)) {
+      if (arr[i] > arr[i + 1]) {
+        temp <- arr[i]
+        arr[i] <- arr[i + 1]
+        arr[i + 1] <- temp
+        sorted <- FALSE
+      }
+    }
+  }
+  return(arr)
+}
+
+# Example usage:
+elements_vec <- c(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5)
+odd_even_sorted_vec <- odd_even_sort(elements_vec)
+print(odd_even_sorted_vec)
+
+
##  [1] 1 1 2 3 3 4 5 5 5 6 9
+
+
+ + + + diff --git a/documentation/odd_even_sort.md b/documentation/odd_even_sort.md new file mode 100644 index 0000000..f0cd132 --- /dev/null +++ b/documentation/odd_even_sort.md @@ -0,0 +1,48 @@ + + +```r +# Odd-Even Sort Function +# Sorts an input vector in-place using the Odd-Even Sort algorithm. +# Parameters: +# - arr: Input vector to be sorted. +# Returns: +# - Sorted vector. +odd_even_sort <- function(arr) { + n <- length(arr) + sorted <- FALSE + while (!sorted) { + sorted <- TRUE + + # Odd-Even Sort (Phase 1 - Odd) + for (i in seq(1, n - 1, by = 2)) { + if (arr[i] > arr[i + 1]) { + temp <- arr[i] + arr[i] <- arr[i + 1] + arr[i + 1] <- temp + sorted <- FALSE + } + } + + # Odd-Even Sort (Phase 2 - Even) + for (i in seq(2, n - 1, by = 2)) { + if (arr[i] > arr[i + 1]) { + temp <- arr[i] + arr[i] <- arr[i + 1] + arr[i + 1] <- temp + sorted <- FALSE + } + } + } + return(arr) +} + +# Example usage: +elements_vec <- c(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5) +odd_even_sorted_vec <- odd_even_sort(elements_vec) +print(odd_even_sorted_vec) +``` + +``` +## [1] 1 1 2 3 3 4 5 5 5 6 9 +``` + diff --git a/documentation/pam.html b/documentation/pam.html index b2dd1b3..fbcc7bf 100644 --- a/documentation/pam.html +++ b/documentation/pam.html @@ -1,211 +1,154 @@ - - + + - - - - - - - - - - - + - - - - -
library(cluster) 
+
+

+

+

+
+
+
library(cluster) 
 pam_fit <- pam(iris[, 1:4], 5) # Partition Around Medoids
 summary(pam_fit) # Get summary
 
-
## Medoids:
 ##       ID Sepal.Length Sepal.Width Petal.Length Petal.Width
 ## [1,]   8          5.0         3.4          1.5         0.2
@@ -396,7 +339,8 @@
 ##  [1] "medoids"    "id.med"     "clustering" "objective"  "isolation" 
 ##  [6] "clusinfo"   "silinfo"    "diss"       "call"       "data"
 
- +
+ + - diff --git a/documentation/pancake_sort.html b/documentation/pancake_sort.html new file mode 100644 index 0000000..e216dfb --- /dev/null +++ b/documentation/pancake_sort.html @@ -0,0 +1,202 @@ + + + + + + + + + + +
+

+

+

+
+
+
# Function to flip the first 'k' elements of an array
+flip <- function(arr, k) {
+  arr[1:k] <- rev(arr[1:k])  # Reverse the first 'k' elements
+  return(arr)
+}
+
+# Function to find the index of the maximum element in an array
+findMaxIndex <- function(arr, n) {
+  maxIndex <- 1
+  for (i in 2:n) {
+    if (arr[i] > arr[maxIndex]) {
+      maxIndex <- i
+    }
+  }
+  return(maxIndex)
+}
+
+# Function to perform Pancake Sort
+pancakeSort <- function(arr) {
+  n <- length(arr)
+  
+  for (currentSize in n:2) {
+    # Find the index of the maximum element in the unsorted part of the array
+    maxIndex <- findMaxIndex(arr, currentSize)
+    
+    # If the maximum element is not at the end of the unsorted part, flip it
+    if (maxIndex != currentSize) {
+      # Flip the maximum element to the beginning of the array
+      arr <- flip(arr, maxIndex)
+      
+      # Flip the maximum element to its correct position
+      arr <- flip(arr, currentSize)
+    }
+  }
+  
+  return(arr)
+}
+
+# Example usage:
+arr <- c(3, 1, 5, 2, 4)
+cat("Original Array:", arr, "\n")
+
+
## Original Array: 3 1 5 2 4
+
+
# Call the Pancake Sort function to sort the array
+sortedArr <- pancakeSort(arr)
+cat("Sorted Array:", sortedArr, "\n")
+
+
## Sorted Array: 1 2 3 4 5
+
+
+ + + + diff --git a/documentation/pancake_sort.md b/documentation/pancake_sort.md new file mode 100644 index 0000000..c62344f --- /dev/null +++ b/documentation/pancake_sort.md @@ -0,0 +1,60 @@ + + +```r +# Function to flip the first 'k' elements of an array +flip <- function(arr, k) { + arr[1:k] <- rev(arr[1:k]) # Reverse the first 'k' elements + return(arr) +} + +# Function to find the index of the maximum element in an array +findMaxIndex <- function(arr, n) { + maxIndex <- 1 + for (i in 2:n) { + if (arr[i] > arr[maxIndex]) { + maxIndex <- i + } + } + return(maxIndex) +} + +# Function to perform Pancake Sort +pancakeSort <- function(arr) { + n <- length(arr) + + for (currentSize in n:2) { + # Find the index of the maximum element in the unsorted part of the array + maxIndex <- findMaxIndex(arr, currentSize) + + # If the maximum element is not at the end of the unsorted part, flip it + if (maxIndex != currentSize) { + # Flip the maximum element to the beginning of the array + arr <- flip(arr, maxIndex) + + # Flip the maximum element to its correct position + arr <- flip(arr, currentSize) + } + } + + return(arr) +} + +# Example usage: +arr <- c(3, 1, 5, 2, 4) +cat("Original Array:", arr, "\n") +``` + +``` +## Original Array: 3 1 5 2 4 +``` + +```r +# Call the Pancake Sort function to sort the array +sortedArr <- pancakeSort(arr) +cat("Sorted Array:", sortedArr, "\n") +``` + +``` +## Sorted Array: 1 2 3 4 5 +``` + diff --git a/documentation/perfect_number.html b/documentation/perfect_number.html deleted file mode 100644 index 6d9634b..0000000 --- a/documentation/perfect_number.html +++ /dev/null @@ -1,248 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - -
# Perfect number checker in R:
-    is_perfect_number <- function(n) {
-
-        #' @description Checks if number passed as a parameter is a perfect number.
-        #' @param n number to check
-        #' @usage is_perfect_number(n)
-        #' @details In number theory, a perfect number is a positive integer that
-        #' is equal to the sum of its positive divisors, excluding the number itself.
-        #' For instance, 6 has divisors 1, 2 and 3 (excluding itself)
-        #' and 1 + 2 + 3 = 6, so 6 is a perfect number.
-        #' @references https://en.wikipedia.org/wiki/Perfect_number
-      
-        if (n < 0) stop("Parameter n must have positive value")
-      
-        sum_of_divisors <- 0
-        limit <- n - 1
-      
-        for (i in 1:limit) {
-           if (n %% i == 0) {
-              sum_of_divisors <- sum_of_divisors + i
-           }
-        }
-      
-        return(sum_of_divisors == n)
-      }
-      
-      result <- is_perfect_number(4)
-      print(result)  # expected false
-      
-      result <- is_perfect_number(5)
-      print(result)  # expected false
-      
-      result <- is_perfect_number(6)
-      print(result)  # expected true
-      
-      result <- is_perfect_number(7)
-      print(result)  # expected false
-      
-      result <- is_perfect_number(28)
-      print(result)  # expected true
-
- - - - diff --git a/documentation/perfect_number.md b/documentation/perfect_number.md deleted file mode 100644 index 56320ff..0000000 --- a/documentation/perfect_number.md +++ /dev/null @@ -1,42 +0,0 @@ -```r - -is_perfect_number <- function(n) { - - #' @description Checks if number passed as a parameter is a perfect number. - #' @param n number to check - #' @usage is_perfect_number(n) - #' @details In number theory, a perfect number is a positive integer that - #' is equal to the sum of its positive divisors, excluding the number itself. - #' For instance, 6 has divisors 1, 2 and 3 (excluding itself) - #' and 1 + 2 + 3 = 6, so 6 is a perfect number. - #' @references https://en.wikipedia.org/wiki/Perfect_number - - if (n < 0) stop("Parameter n must have positive value") - - sum_of_divisors <- 0 - limit <- n - 1 - - for (i in 1:limit) { - if (n %% i == 0) { - sum_of_divisors <- sum_of_divisors + i - } - } - - return(sum_of_divisors == n) -} - -result <- is_perfect_number(4) -print(result) # expected false - -result <- is_perfect_number(5) -print(result) # expected false - -result <- is_perfect_number(6) -print(result) # expected true - -result <- is_perfect_number(7) -print(result) # expected false - -result <- is_perfect_number(28) -print(result) # expected true -``` \ No newline at end of file diff --git a/documentation/quick_sort.html b/documentation/quick_sort.html index 9c21238..2842ff3 100644 --- a/documentation/quick_sort.html +++ b/documentation/quick_sort.html @@ -1,207 +1,151 @@ - - + + - - - - - - - - - - - + - - - - -
# Quick sort in R:
+
+

+

+

+
+
+
# Quick sort in R:
 
 quick.sort <- function(elements.vec) {
   if(length(elements.vec) <= 1) {
@@ -220,11 +164,12 @@
 
 # Notes:
 # 1. Quick sort is not a stable sorting algorithm.
-# 2. It is implemented in the 'sort' function of base R:
+# 2. It is implemented in the 'sort' function of base R:
 # sort(c(5, 2, 3, 1, 1, 4), method = "quick" , index.return = FALSE)
 # [1] 1 1 2 3 4 5
 
- +
+ + - diff --git a/documentation/radix_sort.html b/documentation/radix_sort.html index 5474b80..db2c0c0 100644 --- a/documentation/radix_sort.html +++ b/documentation/radix_sort.html @@ -1,207 +1,151 @@ - - + + - - - - - - - - - - - + - - - - -
# Radix sort in R:
+
+

+

+

+
+
+
# Radix sort in R:
 
 radix.sort <- function(elements.vec) {
     x <- nchar(max(elements.vec))
@@ -215,11 +159,12 @@
 # [1] 27 50 820 976 3200
 
 # Note:
-# It is implemented in the 'sort' function of base R:
+# It is implemented in the 'sort' function of base R:
 # sort(c(50, 3200, 27, 976, 820), method = "radix" , index.return = FALSE)
 # [1] 27 50 820 976 3200
 
- +
+ + - diff --git a/documentation/random_forest.html b/documentation/random_forest.html index 4c12467..7a05fb9 100644 --- a/documentation/random_forest.html +++ b/documentation/random_forest.html @@ -1,238 +1,174 @@ - - + + - - - - - - - - - - - + - - - - -
library(randomForest)
+
+

+

+

+
+
+
library(randomForest)
 
- -
## Error in library(randomForest): there is no package called 'randomForest'
+
## Error in library(randomForest): there is no package called 'randomForest'
 
- -
x <- cbind(x_train,y_train)
+
x <- cbind(x_train,y_train)
 
- -
## Error in cbind(x_train, y_train): object 'x_train' not found
+
## Error in cbind(x_train, y_train): object 'x_train' not found
 
- -
# Fitting model
+
# Fitting model
 fit <- randomForest(Species ~ ., x,ntree=500)
 
-
## Error in randomForest(Species ~ ., x, ntree = 500): could not find function "randomForest"
 
- -
summary(fit)
+
summary(fit)
 
- -
## Error in summary(fit): object 'fit' not found
+
## Error in summary(fit): object 'fit' not found
 
- -
# Predict Output 
+
# Predict Output 
 predicted= predict(fit,x_test)
 
- -
## Error in predict(fit, x_test): object 'fit' not found
+
## Error in predict(fit, x_test): object 'fit' not found
 
- +
+ + - diff --git a/documentation/selection_sort.html b/documentation/selection_sort.html index a65c9a3..c61fdcb 100644 --- a/documentation/selection_sort.html +++ b/documentation/selection_sort.html @@ -1,207 +1,151 @@ - - + + - - - - - - - - - - - + - - - - -
# Selection sort in R:
+
+

+

+

+
+
+
# Selection sort in R:
 
 selection.sort <- function(elements.vec, ascending = TRUE) {
   max <- length(elements.vec)
@@ -225,7 +169,8 @@
 # [1] 1 1 2 3 4 5
 # Note that selection sort is not a stable sorting algorithm.
 
- +
+ + - diff --git a/documentation/shell_sort.html b/documentation/shell_sort.html new file mode 100644 index 0000000..a0ba18b --- /dev/null +++ b/documentation/shell_sort.html @@ -0,0 +1,194 @@ + + + + + + + + + + +
+

+

+

+
+
+
# Function to perform Shell Sort
+shellSort <- function(arr) {
+  n <- length(arr)
+  
+  # Start with a large gap and reduce it
+  gap <- n %/% 2  # Initial gap
+  
+  while (gap > 0) {
+    for (i in (gap + 1):n) {
+      # Store the current element to be compared
+      temp <- arr[i]
+      
+      # Compare the current element with elements at positions 'i - gap', 'i - 2 * gap', ...
+      j <- i
+      while (j > gap && arr[j - gap] > temp) {
+        arr[j] <- arr[j - gap]
+        j <- j - gap
+      }
+      
+      # Place the current element in its correct position
+      arr[j] <- temp
+    }
+    
+    # Reduce the gap for the next iteration
+    gap <- gap %/% 2
+  }
+  
+  return(arr)
+}
+
+# Example usage:
+arr <- c(12, 34, 54, 2, 3)
+cat("Original Array:", arr, "\n")
+
+
## Original Array: 12 34 54 2 3
+
+
# Call the Shell Sort function to sort the array
+sortedArr <- shellSort(arr)
+cat("Sorted Array:", sortedArr, "\n")
+
+
## Sorted Array: 2 3 12 34 54
+
+
+ + + + diff --git a/documentation/shell_sort.md b/documentation/shell_sort.md new file mode 100644 index 0000000..304347a --- /dev/null +++ b/documentation/shell_sort.md @@ -0,0 +1,52 @@ + + +```r +# Function to perform Shell Sort +shellSort <- function(arr) { + n <- length(arr) + + # Start with a large gap and reduce it + gap <- n %/% 2 # Initial gap + + while (gap > 0) { + for (i in (gap + 1):n) { + # Store the current element to be compared + temp <- arr[i] + + # Compare the current element with elements at positions 'i - gap', 'i - 2 * gap', ... + j <- i + while (j > gap && arr[j - gap] > temp) { + arr[j] <- arr[j - gap] + j <- j - gap + } + + # Place the current element in its correct position + arr[j] <- temp + } + + # Reduce the gap for the next iteration + gap <- gap %/% 2 + } + + return(arr) +} + +# Example usage: +arr <- c(12, 34, 54, 2, 3) +cat("Original Array:", arr, "\n") +``` + +``` +## Original Array: 12 34 54 2 3 +``` + +```r +# Call the Shell Sort function to sort the array +sortedArr <- shellSort(arr) +cat("Sorted Array:", sortedArr, "\n") +``` + +``` +## Sorted Array: 2 3 12 34 54 +``` + diff --git a/documentation/stooge_sort.html b/documentation/stooge_sort.html index 5d0d65c..ef22251 100644 --- a/documentation/stooge_sort.html +++ b/documentation/stooge_sort.html @@ -1,226 +1,171 @@ - - + + - - - - - - - - - - - + - - - - -
# Stooge sort in R:
+
+

+

+

+
+
+
# Stooge sort in R:
 
 stooge.sort <- function(elements.vec) {
-    i = 1
-    j = length(elements.vec)
-    if (elements.vec[j] < elements.vec[i]) elements.vec[c(j, i)] = elements.vec[c(i, j)]
-    if (j - i > 1) {
-        t = (j - i + 1) %/% 3
-        elements.vec[i:(j - t)] = stooge.sort(elements.vec[i:(j - t)])
-        elements.vec[(i + t):j] = stooge.sort(elements.vec[(i + t):j])
-        elements.vec[i:(j - t)] = stooge.sort(elements.vec[i:(j - t)])
-    }
-    elements.vec
-}
-
+	i = 1
+	j = length(elements.vec)
+	if (elements.vec[j] < elements.vec[i]) elements.vec[c(j, i)] = elements.vec[c(i, j)]
+	if (j - i > 1) {
+		t = (j - i + 1) %/% 3
+		elements.vec[i:(j - t)] = stooge.sort(elements.vec[i:(j - t)])
+		elements.vec[(i + t):j] = stooge.sort(elements.vec[(i + t):j])
+		elements.vec[i:(j - t)] = stooge.sort(elements.vec[i:(j - t)])
+	}
+	elements.vec
+}
+ 
 # Example:
 # stooge.sort(sample(21, 20))
 # [1] 1  2  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21
 
- +
+ + - diff --git a/documentation/svm.html b/documentation/svm.html new file mode 100644 index 0000000..37fa964 --- /dev/null +++ b/documentation/svm.html @@ -0,0 +1,174 @@ + + + + + + + + + + +
+

+

+

+
+
+
library(e1071)
+
+
## Error in library(e1071): there is no package called 'e1071'
+
+
x <- cbind(x_train,y_train)
+
+
## Error in cbind(x_train, y_train): object 'x_train' not found
+
+
# Fitting model
+fit <-svm(y_train ~ ., data = x)
+
+
## Error in svm(y_train ~ ., data = x): could not find function "svm"
+
+
summary(fit)
+
+
## Error in summary(fit): object 'fit' not found
+
+
# Predict Output 
+predicted= predict(fit,x_test)
+
+
## Error in predict(fit, x_test): object 'fit' not found
+
+
+ + + + diff --git a/documentation/topological_sort.html b/documentation/topological_sort.html new file mode 100644 index 0000000..2658c57 --- /dev/null +++ b/documentation/topological_sort.html @@ -0,0 +1,204 @@ + + + + + + + + + + +
+

+

+

+
+
+
# Function to perform topological sort
+topological_sort <- function(graph) {
+  # Number of vertices in the graph
+  num_vertices <- length(graph)
+  
+  # Helper function to perform DFS
+  dfs <- function(node, visited, stack) {
+    visited[node] <- TRUE
+    
+    # Visit all adjacent vertices
+    for (neighbor in graph[[node]]) {
+      if (!visited[neighbor]) {
+        dfs(neighbor, visited, stack)
+      }
+    }
+    
+    # Push the current node onto the stack
+    stack <<- c(stack, node)
+  }
+  
+  # Initialize data structures
+  visited <- rep(FALSE, num_vertices)
+  stack <- c()
+  
+  # Perform DFS for each unvisited vertex
+  for (node in 1:num_vertices) {
+    if (!visited[node]) {
+      dfs(node, visited, stack)
+    }
+  }
+  
+  # Reverse the stack to get the topological order
+  topological_order <- rev(stack)
+  return(topological_order)
+}
+
+# Example usage
+# Define a sample DAG as an adjacency list
+# Here, we represent the graph as a list of vectors, where each vector contains the neighbors of the corresponding node.
+graph <- list(
+  c(2, 3),    # Node 1 points to nodes 2 and 3
+  c(3, 4),    # Node 2 points to nodes 3 and 4
+  c(5),       # Node 3 points to node 5
+  c(5),       # Node 4 points to node 5
+  numeric(0)  # Node 5 has no outgoing edges
+)
+
+topological_order <- topological_sort(graph)
+cat("Topological Order:", topological_order, "\n")
+
+
## Topological Order: 5 4 3 2 1
+
+
+ + + + diff --git a/documentation/topological_sort.md b/documentation/topological_sort.md new file mode 100644 index 0000000..84e9fa7 --- /dev/null +++ b/documentation/topological_sort.md @@ -0,0 +1,58 @@ + + +```r +# Function to perform topological sort +topological_sort <- function(graph) { + # Number of vertices in the graph + num_vertices <- length(graph) + + # Helper function to perform DFS + dfs <- function(node, visited, stack) { + visited[node] <- TRUE + + # Visit all adjacent vertices + for (neighbor in graph[[node]]) { + if (!visited[neighbor]) { + dfs(neighbor, visited, stack) + } + } + + # Push the current node onto the stack + stack <<- c(stack, node) + } + + # Initialize data structures + visited <- rep(FALSE, num_vertices) + stack <- c() + + # Perform DFS for each unvisited vertex + for (node in 1:num_vertices) { + if (!visited[node]) { + dfs(node, visited, stack) + } + } + + # Reverse the stack to get the topological order + topological_order <- rev(stack) + return(topological_order) +} + +# Example usage +# Define a sample DAG as an adjacency list +# Here, we represent the graph as a list of vectors, where each vector contains the neighbors of the corresponding node. +graph <- list( + c(2, 3), # Node 1 points to nodes 2 and 3 + c(3, 4), # Node 2 points to nodes 3 and 4 + c(5), # Node 3 points to node 5 + c(5), # Node 4 points to node 5 + numeric(0) # Node 5 has no outgoing edges +) + +topological_order <- topological_sort(graph) +cat("Topological Order:", topological_order, "\n") +``` + +``` +## Topological Order: 5 4 3 2 1 +``` + diff --git a/documentation/wiggle_sort.html b/documentation/wiggle_sort.html new file mode 100644 index 0000000..032d68d --- /dev/null +++ b/documentation/wiggle_sort.html @@ -0,0 +1,179 @@ + + + + + + + + + + +
+

+

+

+
+
+
# Wiggle Sort Function
+# Rearranges the elements in the input vector into a wiggle pattern.
+# Parameters:
+# - arr: Input vector to be rearranged.
+# Returns:
+# - Wiggle sorted vector.
+wiggle_sort <- function(arr) {
+  n <- length(arr)
+  for (i in 2:n) {
+    if ((i %% 2 == 0 && arr[i] < arr[i - 1]) || (i %% 2 != 0 && arr[i] > arr[i - 1])) {
+      # Swap elements at odd positions if they are greater
+      # or at even positions if they are smaller.
+      temp <- arr[i]
+      arr[i] <- arr[i - 1]
+      arr[i - 1] <- temp
+    }
+  }
+  return(arr)
+}
+
+# Example usage:
+elements_vec <- c(3, 5, 2, 1, 6, 4)
+wiggle_sorted_vec <- wiggle_sort(elements_vec)
+print(wiggle_sorted_vec)
+
+
## [1] 3 5 1 6 2 4
+
+
+ + + + diff --git a/documentation/wiggle_sort.md b/documentation/wiggle_sort.md new file mode 100644 index 0000000..a6636d0 --- /dev/null +++ b/documentation/wiggle_sort.md @@ -0,0 +1,33 @@ + + +```r +# Wiggle Sort Function +# Rearranges the elements in the input vector into a wiggle pattern. +# Parameters: +# - arr: Input vector to be rearranged. +# Returns: +# - Wiggle sorted vector. +wiggle_sort <- function(arr) { + n <- length(arr) + for (i in 2:n) { + if ((i %% 2 == 0 && arr[i] < arr[i - 1]) || (i %% 2 != 0 && arr[i] > arr[i - 1])) { + # Swap elements at odd positions if they are greater + # or at even positions if they are smaller. + temp <- arr[i] + arr[i] <- arr[i - 1] + arr[i - 1] <- temp + } + } + return(arr) +} + +# Example usage: +elements_vec <- c(3, 5, 2, 1, 6, 4) +wiggle_sorted_vec <- wiggle_sort(elements_vec) +print(wiggle_sorted_vec) +``` + +``` +## [1] 3 5 1 6 2 4 +``` + diff --git a/documentation/xgboost.html b/documentation/xgboost.html index c35ac66..0c08714 100644 --- a/documentation/xgboost.html +++ b/documentation/xgboost.html @@ -1,286 +1,206 @@ - - + + - - - - - - - - - - - + - - - - -
library(tidyverse)
+
+

+

+

+
+
+
library(tidyverse)
 
- -
## Error in library(tidyverse): there is no package called 'tidyverse'
+
## Error in library(tidyverse): there is no package called 'tidyverse'
 
- -
library(xgboost)
+
library(xgboost)
 
- -
## Error in library(xgboost): there is no package called 'xgboost'
+
## Error in library(xgboost): there is no package called 'xgboost'
 
- -
ind<-sample(2,nrow(diamonds),replace = T,prob = c(0.7,0.3))
+
ind<-sample(2,nrow(diamonds),replace = T,prob = c(0.7,0.3))
 
- -
## Error in nrow(diamonds): object 'diamonds' not found
+
## Error in nrow(diamonds): object 'diamonds' not found
 
- -
train.set<-diamonds[ind==1,]
+
train.set<-diamonds[ind==1,]
 
- -
## Error in eval(expr, envir, enclos): object 'diamonds' not found
+
## Error in eval(expr, envir, enclos): object 'diamonds' not found
 
- -
test.set<-diamonds[ind==2,]
+
test.set<-diamonds[ind==2,]
 
- -
## Error in eval(expr, envir, enclos): object 'diamonds' not found
+
## Error in eval(expr, envir, enclos): object 'diamonds' not found
 
- -
xgb.train<-bind_cols(select_if(train.set,is.numeric),model.matrix(~cut-1,train.set) %>% as.tibble(),model.matrix(~color-1,train.set) %>% as.tibble(),model.matrix(~clarity-1,train.set) %>% as.tibble())
+
xgb.train<-bind_cols(select_if(train.set,is.numeric),model.matrix(~cut-1,train.set) %>% as.tibble(),model.matrix(~color-1,train.set) %>% as.tibble(),model.matrix(~clarity-1,train.set) %>% as.tibble())
 
-
## Error in bind_cols(select_if(train.set, is.numeric), model.matrix(~cut - : could not find function "bind_cols"
 
- -
xgboost.train<-xgb.DMatrix(data = as.matrix(select(xgb.train,-price)),label=xgb.train$price)
+
xgboost.train<-xgb.DMatrix(data = as.matrix(select(xgb.train,-price)),label=xgb.train$price)
 
-
## Error in xgb.DMatrix(data = as.matrix(select(xgb.train, -price)), label = xgb.train$price): could not find function "xgb.DMatrix"
 
- -
xgb.test<-bind_cols(select_if(test.set,is.numeric),model.matrix(~cut-1,test.set) %>% as.tibble(),model.matrix(~color-1,test.set) %>% as.tibble(),model.matrix(~clarity-1,test.set) %>% as.tibble())
+
xgb.test<-bind_cols(select_if(test.set,is.numeric),model.matrix(~cut-1,test.set) %>% as.tibble(),model.matrix(~color-1,test.set) %>% as.tibble(),model.matrix(~clarity-1,test.set) %>% as.tibble())
 
-
## Error in bind_cols(select_if(test.set, is.numeric), model.matrix(~cut - : could not find function "bind_cols"
 
- -
xgboost.test<-xgb.DMatrix(data = select(xgb.test,-price) %>% as.matrix(),label=xgb.test$price)
+
xgboost.test<-xgb.DMatrix(data = select(xgb.test,-price) %>% as.matrix(),label=xgb.test$price)
 
-
## Error in xgb.DMatrix(data = select(xgb.test, -price) %>% as.matrix(), : could not find function "xgb.DMatrix"
 
- -
param<-list(eval_metric='rmse',gamma=1,max_depth=6,nthread = 3)
+
param<-list(eval_metric='rmse',gamma=1,max_depth=6,nthread = 3)
 xg.model<-xgb.train(data = xgboost.train,params = param,watchlist = list(test=xgboost.test),nrounds = 500,early_stopping_rounds = 60,
                       print_every_n = 30)
 
-
## Error in xgb.train(data = xgboost.train, params = param, watchlist = list(test = xgboost.test), : could not find function "xgb.train"
 
- -
xg.predict<-predict(xg.model,xgboost.test)
+
xg.predict<-predict(xg.model,xgboost.test)
 
- -
## Error in predict(xg.model, xgboost.test): object 'xg.model' not found
+
## Error in predict(xg.model, xgboost.test): object 'xg.model' not found
 
- -
mse.xgb<-sqrt(mean((test.set$price-xg.predict)^2))
+
mse.xgb<-sqrt(mean((test.set$price-xg.predict)^2))
 
- -
## Error in mean((test.set$price - xg.predict)^2): object 'test.set' not found
+
## Error in mean((test.set$price - xg.predict)^2): object 'test.set' not found
 
- -
plot((test.set$price-xg.predict))
+
plot((test.set$price-xg.predict))
 
- -
## Error in plot((test.set$price - xg.predict)): object 'test.set' not found
+
## Error in plot((test.set$price - xg.predict)): object 'test.set' not found
 
- +
+ + -