data("iris")
View(iris)
summary(iris)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100 setosa :50
1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300 versicolor:50
Median :5.800 Median :3.000 Median :4.350 Median :1.300 virginica :50
Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199
3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
summary(iris[c("Petal.Width", "Sepal.Width")])
Petal.Width Sepal.Width
Min. :0.100 Min. :2.000
1st Qu.:0.300 1st Qu.:2.800
Median :1.300 Median :3.000
Mean :1.199 Mean :3.057
3rd Qu.:1.800 3rd Qu.:3.300
Max. :2.500 Max. :4.400
summary(iris[c("Petal.Length", "Sepal.Length")])
Petal.Length Sepal.Length
Min. :1.000 Min. :4.300
1st Qu.:1.600 1st Qu.:5.100
Median :4.350 Median :5.800
Mean :3.758 Mean :5.843
3rd Qu.:5.100 3rd Qu.:6.400
Max. :6.900 Max. :7.900
install.packages('ggvis')
library(ggvis)
iris %>% ggvis(~Sepal.Length, ~Sepal.Width, fill = ~Species) %>% layer_points()
install.packages("class")
Installing package into ‘/Users/jaclynbazsika/Library/R/3.3/library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/macosx/mavericks/contrib/3.3/class_7.3-14.tgz'
Content type 'application/x-gzip' length 87780 bytes (85 KB)
==================================================
downloaded 85 KB
The downloaded binary packages are in
/var/folders/8s/6xnh03sd7zzc1nny5h0xzx3h0000gn/T//Rtmpc87WBd/downloaded_packages
library("class")
set.seed(3465)
ind <- sample(2, nrow(iris), replace=TRUE, prob=c(0.8, 0.2))
# use the array, ind, to define the training and test sets
irisTrain <- iris[ind==1, 1:4]
irisTest <- iris[ind==2, 1:4]
irisTrainLabels <- iris[ind==1, 5]
irisTestLabels <- iris[ind==2, 5]
set.seed(3465)
ind <- sample(2, nrow(iris), replace=TRUE, prob=c(0.8, 0.2))
# use the array, ind, to define the training and test sets
irisTrain <- iris[ind==1, 1:4]
irisTest <- iris[ind==2, 1:4]
irisTrainLabels <- iris[ind==1, 5]
irisTestLabels <- iris[ind==2, 5]
iris_pred <- knn(train=irisTrain, test=irisTest, cl=irisTrainLabels, k=3)
iris_pred # view results of knn function
[1] setosa setosa setosa setosa setosa setosa setosa setosa versicolor versicolor versicolor versicolor versicolor versicolor
[15] versicolor versicolor virginica virginica virginica virginica
Levels: setosa versicolor virginica
install.packages("gmodels")
Installing package into ‘/Users/jaclynbazsika/Library/R/3.3/library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/macosx/mavericks/contrib/3.3/gmodels_2.16.2.tgz'
Content type 'application/x-gzip' length 72626 bytes (70 KB)
==================================================
downloaded 70 KB
The downloaded binary packages are in
/var/folders/8s/6xnh03sd7zzc1nny5h0xzx3h0000gn/T//Rtmpc87WBd/downloaded_packages
library(gmodels)
CrossTable(x=irisTestLabels, y=iris_pred, prop.chisq=F, prop.r=F, prop.c=F, prop.t=F)
Cell Contents
|-------------------------|
| N |
|-------------------------|
Total Observations in Table: 20
| iris_pred
irisTestLabels | setosa | versicolor | virginica | Row Total |
---------------|------------|------------|------------|------------|
setosa | 8 | 0 | 0 | 8 |
---------------|------------|------------|------------|------------|
versicolor | 0 | 8 | 0 | 8 |
---------------|------------|------------|------------|------------|
virginica | 0 | 0 | 4 | 4 |
---------------|------------|------------|------------|------------|
Column Total | 8 | 8 | 4 | 20 |
---------------|------------|------------|------------|------------|
install.packages('caret')
Error in install.packages : Updating loaded packages
library(caret)
Loading required package: lattice
Error: unexpected symbol in "Loading required"
normalize <- function(x) {
num <- x - min(x)
denom <- max(x) - min(x)
return (num/denom)
}
# apply this newly created normalize argument to the dataset
iris_x <- as.data.frame(lapply(iris[1:4], normalize))
summary(iris)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100 setosa :50
1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300 versicolor:50
Median :5.800 Median :3.000 Median :4.350 Median :1.300 virginica :50
Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199
3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
summary(iris_x)
Sepal.Length Sepal.Width Petal.Length Petal.Width
Min. :0.0000 Min. :0.0000 Min. :0.0000 Min. :0.00000
1st Qu.:0.2222 1st Qu.:0.3333 1st Qu.:0.1017 1st Qu.:0.08333
Median :0.4167 Median :0.4167 Median :0.5678 Median :0.50000
Mean :0.4287 Mean :0.4406 Mean :0.4675 Mean :0.45806
3rd Qu.:0.5833 3rd Qu.:0.5417 3rd Qu.:0.6949 3rd Qu.:0.70833
Max. :1.0000 Max. :1.0000 Max. :1.0000 Max. :1.00000
How do supervised learning algorithms solve regression and classification problems?
What packages in R perform supervised learning?
MICE,rpart,PARTY,CARET,nnet
3.How would we compare the results of two different models, or sets of hyperparameters for one model?
You would use the F-test in a two way ANOVA to compare the results of two different models.