diff --git a/DIRECTORY.md b/DIRECTORY.md index b29ea94d..16ffcfd3 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -6,8 +6,9 @@ * [Decision Tree](https://github.com/TheAlgorithms/R/blob/HEAD/classification_algorithms/decision_tree.r) * [Gradient Boosting Algorithms](https://github.com/TheAlgorithms/R/blob/HEAD/classification_algorithms/gradient_boosting_algorithms.r) * [Knn](https://github.com/TheAlgorithms/R/blob/HEAD/classification_algorithms/knn.r) - * [Lasso](https://github.com/TheAlgorithms/R/blob/HEAD/classification_algorithms/lasso.r) * [Light Gbm](https://github.com/TheAlgorithms/R/blob/HEAD/classification_algorithms/light_gbm.r) + * [Logistic Regression](https://github.com/TheAlgorithms/R/blob/HEAD/classification_algorithms/logistic_regression.r) + * [Logistic Regression 2](https://github.com/TheAlgorithms/R/blob/HEAD/classification_algorithms/logistic_regression_2.r) * [Naive Bayes](https://github.com/TheAlgorithms/R/blob/HEAD/classification_algorithms/naive_bayes.r) * [Random Forest](https://github.com/TheAlgorithms/R/blob/HEAD/classification_algorithms/random_forest.r) * [Svm](https://github.com/TheAlgorithms/R/blob/HEAD/classification_algorithms/svm.r) @@ -51,8 +52,6 @@ * [Depth First Search](https://github.com/TheAlgorithms/R/blob/HEAD/graph_algorithms/depth_first_search.r) * [Dijkstra Shortest Path](https://github.com/TheAlgorithms/R/blob/HEAD/graph_algorithms/dijkstra_shortest_path.r) -## [Levenshtein](https://github.com/TheAlgorithms/R/blob/HEAD//levenshtein.r) - ## Mathematics * [Amicable Numbers](https://github.com/TheAlgorithms/R/blob/HEAD/mathematics/amicable_numbers.r) * [Armstrong Number](https://github.com/TheAlgorithms/R/blob/HEAD/mathematics/armstrong_number.r) @@ -63,7 +62,6 @@ * [Fibonacci](https://github.com/TheAlgorithms/R/blob/HEAD/mathematics/fibonacci.r) * [First N Fibonacci](https://github.com/TheAlgorithms/R/blob/HEAD/mathematics/first_n_fibonacci.r) * [Greatest Common Divisor](https://github.com/TheAlgorithms/R/blob/HEAD/mathematics/greatest_common_divisor.r) - * [Hamming Distance](https://github.com/TheAlgorithms/R/blob/HEAD/mathematics/hamming_distance.r) * [Josephus Problem](https://github.com/TheAlgorithms/R/blob/HEAD/mathematics/josephus_problem.r) * [Least Common Multiple](https://github.com/TheAlgorithms/R/blob/HEAD/mathematics/least_common_multiple.r) * [Perfect Number](https://github.com/TheAlgorithms/R/blob/HEAD/mathematics/perfect_number.r) @@ -80,13 +78,8 @@ ## Regression Algorithms * [Ann](https://github.com/TheAlgorithms/R/blob/HEAD/regression_algorithms/ann.r) - * [Gradient Boosting Algorithms](https://github.com/TheAlgorithms/R/blob/HEAD/regression_algorithms/gradient_boosting_algorithms.r) - * [Knn](https://github.com/TheAlgorithms/R/blob/HEAD/regression_algorithms/knn.r) - * [Light Gbm](https://github.com/TheAlgorithms/R/blob/HEAD/regression_algorithms/light_gbm.r) * [Linear Regression](https://github.com/TheAlgorithms/R/blob/HEAD/regression_algorithms/linear_regression.r) * [Linearregressionrawr](https://github.com/TheAlgorithms/R/blob/HEAD/regression_algorithms/linearregressionrawr.r) - * [Logistic Regression](https://github.com/TheAlgorithms/R/blob/HEAD/regression_algorithms/logistic_regression.r) - * [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 @@ -123,9 +116,11 @@ ## String Manipulation * [Burrows](https://github.com/TheAlgorithms/R/blob/HEAD/string_manipulation/burrows.r) * [Findpalindrome](https://github.com/TheAlgorithms/R/blob/HEAD/string_manipulation/findpalindrome.r) + * [Hamming Distance](https://github.com/TheAlgorithms/R/blob/HEAD/string_manipulation/hamming_distance.r) * [Is.Anagram](https://github.com/TheAlgorithms/R/blob/HEAD/string_manipulation/is.anagram.r) * [Is.Lower](https://github.com/TheAlgorithms/R/blob/HEAD/string_manipulation/is.lower.r) * [Is.Uppercase](https://github.com/TheAlgorithms/R/blob/HEAD/string_manipulation/is.uppercase.r) + * [Levenshtein](https://github.com/TheAlgorithms/R/blob/HEAD/string_manipulation/levenshtein.r) * [Longest.Palindromic.Subsequence](https://github.com/TheAlgorithms/R/blob/HEAD/string_manipulation/longest.palindromic.subsequence.r) * [Longest.Substring.No.Repeat](https://github.com/TheAlgorithms/R/blob/HEAD/string_manipulation/longest.substring.no.repeat.r) * [Manacher.Longest.Palindrome](https://github.com/TheAlgorithms/R/blob/HEAD/string_manipulation/manacher.longest.palindrome.r) diff --git a/classification_algorithms/lasso.r b/classification_algorithms/lasso.r deleted file mode 100644 index 82d99190..00000000 --- a/classification_algorithms/lasso.r +++ /dev/null @@ -1,25 +0,0 @@ -library(glmnet) - -# make iris dataset a binary dataset - -iris.mdy <- iris[iris$Species != 'versicolor',] -iris.mdy$Species <- as.character(iris.mdy$Species) -# level virginica is the target class -iris.mdy$Species <- as.factor(iris.mdy$Species) -cv.fit <- cv.glmnet(x=as.matrix(iris.mdy[, 1:4]), - y=iris.mdy$Species, - family = 'binomial', - type.measure="auc" - ) - -plot(cv.fit) - -# coefficients of each varibale -coefficient<-coef(cv.fit$glmnet.fit, s=cv.fit$lambda.min) - -# predict the fitted probability of each test observation -predict(cv.fit$glmnet.fit, - as.matrix(iris.mdy[1:5, 1:4]), - type = 'response', - s=cv.fit$lambda.min) - diff --git a/regression_algorithms/logistic_regression.r b/classification_algorithms/logistic_regression.r similarity index 100% rename from regression_algorithms/logistic_regression.r rename to classification_algorithms/logistic_regression.r diff --git a/regression_algorithms/logistic_regression_2.r b/classification_algorithms/logistic_regression_2.r similarity index 100% rename from regression_algorithms/logistic_regression_2.r rename to classification_algorithms/logistic_regression_2.r diff --git a/documentation/longest_common_subsequence.html b/documentation/longest_common_subsequence.html index 6db617ad..cb059c0a 100644 --- a/documentation/longest_common_subsequence.html +++ b/documentation/longest_common_subsequence.html @@ -550,12 +550,12 @@ cat("Standard algorithm: LCS length =", standard_result, "Time:", sprintf("%.6f", standard_time), "seconds\n") -
## Standard algorithm: LCS length = 59 Time: 0.050064 seconds
+## Standard algorithm: LCS length = 59 Time: 0.052980 seconds
cat("Optimized algorithm: LCS length =", optimized_result,
"Time:", sprintf("%.6f", optimized_time), "seconds\n")
-## Optimized algorithm: LCS length = 59 Time: 0.046882 seconds
+## Optimized algorithm: LCS length = 59 Time: 0.049993 seconds
cat("Results match:", standard_result == optimized_result, "\n\n")
diff --git a/documentation/longest_common_subsequence.md b/documentation/longest_common_subsequence.md
index 58feb159..b0eb4b87 100644
--- a/documentation/longest_common_subsequence.md
+++ b/documentation/longest_common_subsequence.md
@@ -540,7 +540,7 @@ cat("Standard algorithm: LCS length =", standard_result,
```
```
-## Standard algorithm: LCS length = 59 Time: 0.050064 seconds
+## Standard algorithm: LCS length = 59 Time: 0.052980 seconds
```
``` r
@@ -549,7 +549,7 @@ cat("Optimized algorithm: LCS length =", optimized_result,
```
```
-## Optimized algorithm: LCS length = 59 Time: 0.046882 seconds
+## Optimized algorithm: LCS length = 59 Time: 0.049993 seconds
```
``` r
diff --git a/documentation/longest_increasing_subsequence.html b/documentation/longest_increasing_subsequence.html
index deef9825..100ae952 100644
--- a/documentation/longest_increasing_subsequence.html
+++ b/documentation/longest_increasing_subsequence.html
@@ -412,7 +412,7 @@
cat("Time taken:", sprintf("%.4f sec", opt_time), "\n")
-## Time taken: 0.0148 sec
+## Time taken: 0.0189 sec
# Verify correctness with basic DP (smaller sample for time comparison)
nums_small <- nums_perf[1:100]
diff --git a/documentation/longest_increasing_subsequence.md b/documentation/longest_increasing_subsequence.md
index b59f2099..671f6663 100644
--- a/documentation/longest_increasing_subsequence.md
+++ b/documentation/longest_increasing_subsequence.md
@@ -398,7 +398,7 @@ cat("Time taken:", sprintf("%.4f sec", opt_time), "\n")
```
```
-## Time taken: 0.0148 sec
+## Time taken: 0.0189 sec
```
``` r
diff --git a/regression_algorithms/gradient_boosting_algorithms.r b/regression_algorithms/gradient_boosting_algorithms.r
deleted file mode 100644
index c0966175..00000000
--- a/regression_algorithms/gradient_boosting_algorithms.r
+++ /dev/null
@@ -1,71 +0,0 @@
-# GBM
-library(caret)
-x <- cbind(x_train,y_train)
-# Fitting model
-fitControl <- trainControl( method = "repeatedcv", number = 4, repeats = 4)
-fit <- train(y ~ ., data = x, method = "gbm", trControl = fitControl,verbose = FALSE)
-predicted= predict(fit,x_test,type= "prob")[,2]
-
-
-
-# XGBoost
-require(caret)
-x <- cbind(x_train,y_train)
-# Fitting model
-TrainControl <- trainControl( method = "repeatedcv", number = 10, repeats = 4)
-model<- train(y ~ ., data = x, method = "xgbLinear", trControl = TrainControl,verbose = FALSE)
-# OR
-model<- train(y ~ ., data = x, method = "xgbTree", trControl = TrainControl,verbose = FALSE)
-predicted <- predict(model, x_test)
-
-
-
-# LightGBM
-library(RLightGBM)
-data(example.binary)
-# 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)
-lgbm.data.setField(handle.data, "label", y)
-handle.booster <- lgbm.booster.create(handle.data, lapply(config, as.character))
-# Train for num_iterations iterations and eval every 5 steps
-lgbm.booster.train(handle.booster, num_iterations, 5)
-# Predict
-pred <- lgbm.booster.predict(handle.booster, x.test)
-# Test accuracy
-sum(y.test == (y.pred > 0.5)) / length(y.test)
-# Save model (can be loaded again via lgbm.booster.load(filename))
-lgbm.booster.save(handle.booster, filename = "/tmp/model.txt")
-
-
-
-# Catboost
-set.seed(1)
-
-require(titanic)
-
-require(caret)
-
-require(catboost)
-
-tt <- titanic::titanic_train[complete.cases(titanic::titanic_train),]
-
-data <- as.data.frame(as.matrix(tt), stringsAsFactors = TRUE)
-
-drop_columns = c("PassengerId", "Survived", "Name", "Ticket", "Cabin")
-
-x <- data[,!(names(data) %in% drop_columns)]y <- data[,c("Survived")]
-
-fit_control <- trainControl(method = "cv", number = 4,classProbs = TRUE)
-
-grid <- expand.grid(depth = c(4, 6, 8),learning_rate = 0.1,iterations = 100, l2_leaf_reg = 1e-3, rsm = 0.95, border_count = 64)
-
-report <- train(x, as.factor(make.names(y)),method = catboost.caret,verbose = TRUE, preProc = NULL,tuneGrid = grid, trControl = fit_control)
-
-print(report)
-
-importance <- varImp(report, scale = FALSE)
-
-print(importance)
diff --git a/regression_algorithms/knn.r b/regression_algorithms/knn.r
deleted file mode 100644
index afd79f6c..00000000
--- a/regression_algorithms/knn.r
+++ /dev/null
@@ -1,7 +0,0 @@
-library(knn)
-x <- cbind(x_train,y_train)
-# Fitting model
-fit <-knn(y_train ~ ., data = x,k=5)
-summary(fit)
-# Predict Output
-predicted= predict(fit,x_test)
diff --git a/regression_algorithms/light_gbm.r b/regression_algorithms/light_gbm.r
deleted file mode 100644
index 993ba931..00000000
--- a/regression_algorithms/light_gbm.r
+++ /dev/null
@@ -1,26 +0,0 @@
-library(RLightGBM)
-data(example.binary)
-#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)
-
-lgbm.data.setField(handle.data, "label", y)
-
-handle.booster <- lgbm.booster.create(handle.data, lapply(config, as.character))
-
-#Train for num_iterations iterations and eval every 5 steps
-
-lgbm.booster.train(handle.booster, num_iterations, 5)
-
-#Predict
-pred <- lgbm.booster.predict(handle.booster, x.test)
-
-#Test accuracy
-sum(y.test == (y.pred > 0.5)) / length(y.test)
-
-#Save model (can be loaded again via lgbm.booster.load(filename))
-lgbm.booster.save(handle.booster, filename = "/tmp/model.txt")
diff --git a/mathematics/hamming_distance.r b/string_manipulation/hamming_distance.r
similarity index 100%
rename from mathematics/hamming_distance.r
rename to string_manipulation/hamming_distance.r
diff --git a/levenshtein.r b/string_manipulation/levenshtein.r
similarity index 100%
rename from levenshtein.r
rename to string_manipulation/levenshtein.r