Do you want to learn more? Also check out and star the Exploratory Data Analysis in R: Case Study course, also taught by David Robinson, for free now! Also, don't miss out on our data.table cheat sheet for data manipulation in R and our other cheat sheets for data science. (Click above to download a printable version or read the online version. R Base Graphics Cheatsheet Joyce&Robbins,&joycerobbins1@gmail.com& Created Date: 3/7/2016 5:52:42 PM.
This article lists down 10 popular machine learning algorithms and related R commands (& package information) that could be used to create respective models. The objective is to represent a quick reference page for beginners/intermediate level R programmers who working on machine learning related problems. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos.
Following are the different ML algorithms included in this article:- Linear regression
- Logistic Regression
- K-Means Clustering
- K-Nearest Neighbors (KNN) Classification
- Naive Bayes Classification
- Decison Trees
- Support Vector Machine (SVM)
- Artifical Neural Network (ANN)
- Apriori
- AdaBoost
Cheat Sheet – ML Algorithms & R Commands
Basic R Commands Cheat Sheet
- Linear regression: “lm” method from base package could be used for linear regression models. Following is the sample command:
- Logistic Regression: Logistic regression is a classification based model. “glm” method from base R package could be used for logistic regression. Following is the sample command:
- K-Means Clustering: “kmeans” method from base R package could be used to run k-means clustering. Following is a sample command given X is a data matrix and m is the number of clusters:
- K-Nearest Neighbors (KNN) Classification: “knn” method from “class” package could be used for K-NN modeling. One need to install and load “class” package. Following is the sample command given X_train represents a training dataset, X_test represents test data set, k represents number of nearest neighbors to be included for the modeling
- Naive Bayes Classification: “naiveBayes” method from “e1071” package could be used for Naive Bayes classification. One need to install and load “e1071” package prior to analysis. Following is the sample command:
- Decision Trees: “rpart” method from “rpart” can be used for Decision Trees. One need to install and load “rpart” package. Following is the sample command:
- Support Vector Machine (SVM): “svm” method from “e1071” package could be used for SVM. Note that the same package also provide method, naiveBayes, for Naive Bayes classification. One need to install and load “e1071” package. Following is the sample command given X is the matrix of features, labels be the vector of 0-1 class labels, and C being regularization parameter
- Artifical Neural Network (ANN): “neuralnet” method from “neuralnet” package could be used for ANN modeling. Following is sample command:
Prediction could be made using following formula:
- Apriori: “apriori” method from “arules” package could be used for Apriori analysis. One need to install and load “arules” package. Following is the sample command:
- AdaBoost: “ada” method from “rpart” package could be used as boosting function. Following is sample command:
For most of the above formulas including linear regression model, one could use following function to predict:
R Cheat Sheets Pdf
- First Principles Understanding based on Physics - April 13, 2021
- Precision & Recall Explained using Covid-19 Example - April 11, 2021
- Moving Average Method for Time-series forecasting - April 4, 2021