代码拉取完成,页面将自动刷新
vifs <- car::vif(mod)
}
# The best model will be stored in myMod. If Any of the X'x is insignificant, reove it and build the model agn.
summary(mod)
car::vif(mod)
# p - Value viltering
df <- data.frame(summary(mod)$coefficients)[-1, ]
pvalues <- df$Pr...t..
while(any(pvalues > 0.05)){
var_with_max_pvalue <- rownames(df)[which.max(df$Pr...t..)]
frmla <- formula(paste0(". ~ . - ", var_with_max_pvalue))
mod <- update(mod, frmla)
df <- data.frame(summary(mod)$coefficients)[-1, ]
pvalues <- df$Pr...t..
}
summary(mod)
car::vif(mod)
DMwR::regr.eval(actuals, predicteds)
predicteds <- predict(mod)
exp(predicteds)
actuals
predicteds_final <- exp(predicteds)
predicteds_final <- exp(predicteds)
DMwR::regr.eval(actuals, predicteds_final)
bcmod
?BoxCoxTrans
lmtest::bptest(mod)
car::ncvTest(mod)
mod <- lm(mpg ~ ., data=mtcars)
vifs <- car::vif(mod)
vifs
while(any(vifs > 4)){
var_with_max_vif <- names(which(vifs == max(vifs))) # get the var with max vif
frmla <- formula(paste0(". ~ . - ", var_with_max_vif))
mod <- update(mod, frmla)
vifs <- car::vif(mod)
}
summary(mod)
car::vif(mod)
df <- data.frame(summary(mod)$coefficients)[-1, ]
pvalues <- df$Pr...t..
pvalues
while(any(pvalues > 0.05)){
var_with_max_pvalue <- rownames(df)[which.max(df$Pr...t..)]
frmla <- formula(paste0(". ~ . - ", var_with_max_pvalue))
mod <- update(mod, frmla)
df <- data.frame(summary(mod)$coefficients)[-1, ]
pvalues <- df$Pr...t..
}
mod
car::vif(mod)
summary(mod)
lmtest::bptest(mod)
data("mtcars", package=MASS)
data("mtcars", package='MASS')
data(mtcars, package='MASS')
library(MASS)
mtcar
mtcars
a -> mtcars
mtcars
mod <- lm(mpg ~ ., data=mtcars)
vifs <- car::vif(mod)
vifs
while(any(vifs > 4)){
var_with_max_vif <- names(which(vifs == max(vifs))) # get the var with max vif
frmla <- formula(paste0(". ~ . - ", var_with_max_vif))
mod <- update(mod, frmla)
vifs <- car::vif(mod)
}
summary(mod)
car::vif(mod)
df <- data.frame(summary(mod)$coefficients)[-1, ]
pvalues <- df$Pr...t..
pvalues
while(any(pvalues > 0.05)){
var_with_max_pvalue <- rownames(df)[which.max(df$Pr...t..)]
frmla <- formula(paste0(". ~ . - ", var_with_max_pvalue))
mod <- update(mod, frmla)
df <- data.frame(summary(mod)$coefficients)[-1, ]
pvalues <- df$Pr...t..
}
summary(mod)
car::vif(mod)
lmtest::bptest(mod)
car::ncvTest(mod)
actuals <- mtcars$mpg
library(caret)
bcmod <- BoxCoxTrans(mtcars$mpg)
bcmod
mtcars$mpg <- predict(bcmod, mtcars$mpg)
mtcars$mpg
DMwR::regr.eval(actuals, predict(mod))
mod <- lm(mpg ~ ., data=mtcars)
vifs <- car::vif(mod)
# while
while(any(vifs > 4)){
var_with_max_vif <- names(which(vifs == max(vifs))) # get the var with max vif
frmla <- formula(paste0(". ~ . - ", var_with_max_vif))
mod <- update(mod, frmla)
vifs <- car::vif(mod)
}
summary(mod)
car::vif(mod)
# p values
df <- data.frame(summary(mod)$coefficients)[-1, ]
pvalues <- df$Pr...t..
while(any(pvalues > 0.05)){
var_with_max_pvalue <- rownames(df)[which.max(df$Pr...t..)]
frmla <- formula(paste0(". ~ . - ", var_with_max_pvalue))
mod <- update(mod, frmla)
df <- data.frame(summary(mod)$coefficients)[-1, ]
pvalues <- df$Pr...t..
}
summary(mod)
car::vif(mod)
predicteds <- predict(mod)
predicteds_final <- exp(predicteds)
predicteds_final
DMwR::regr.eval(actuals, predicteds_final)
lmtest::bptest(mod)
car::ncvTest(mod)
par(mfrow=c(2,2))
plot(mod)
plot(mod)
install.packages("rvest")
devtools::install_github("hadley/rvest")
devtools::install_github("hadley/rvest")
install.packages("rvest")
library(rvest)
lego_movie <- html("http://www.imdb.com/title/tt1490017/")
lego_movie
rating <- lego_movie %>%
html_nodes("strong span") %>%
html_text() %>%
as.numeric()
rating
demo(package = "rvest")
money <- html(http://www.moneycontrol.com)
money <- html("http://www.moneycontrol.com")
money %>% html_nodes("a")
money %>% html_nodes("a href")
money %>% html_nodes("a")
?rvest
library(help=rvest)
all_links <- money %>% html_nodes("a")
file.path(money, "/india/stockmarket/pricechartquote/")
root_url <- "http://www.moneycontrol.com"
root_url <- "http://www.moneycontrol.com"
file.path(root_url, "/india/stockmarket/pricechartquote/")
basepath <- file.path(root_url, "/india/stockmarket/pricechartquote/")
basepath
LETTERS
paste0(basepath, LETTERS)
all_letters_urls <- paste0(basepath, LETTERS)
letter_urls <- paste0(basepath, LETTERS)
letter_url <- letter_urls[1]
letter_url
letter_html <- html(letter_url)
letter_html
library(rvest)
?html_session
uastring <- "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
session <- html_session("https://www.linkedin.com/job/", user_agent(uastring))
form <- html_form(session)[[1]]
uastring <- "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
session <- html_session("https://www.linkedin.com/job/", user_agent(uastring))
library(rvest)
library(httr)
session <- html_session("https://www.linkedin.com/job/", user_agent(uastring))
html_form(session)
form <- html_form(session)[[1]]
form <- set_values(form, keywords = "Data Science", location="New York")
new_url <- submit_geturl(session,form)
library(mlbench)
head(DNA)
data(DNA)
head(DNA)
?DNA
str(DNA)
str(DNA$Class)
library(mlbench)
?OJ
library(help=mlbench)
head(BreastCancer)
data("BreastCancer")
head(BreastCancer)
library(OJ)
install.packages("OJ")
data("Zoo")
head(Zoo)
str(Zoo)
head(Soybean)
data(Soybean)
head(Soybean)
?Soybean
str(Soybean)
head(Ozone)
data(Ozone)
head(Ozone)
data("Glass")
head(Glass)
str(Glass)
?Glass
str(Zoo)
data("Ionosphere")
head(Ionosphere)
?Ionosphere
data("Satellite")
head(Satellite)
?Satellite
data(PimaIndiansDiabetes)
?PimaIndiansDiabetes
head(PimaIndiansDiabetes)
data("Servo")
head(Servo)
?Servo
str(Servo)
data("LetterRecognition")
head(LetterRecognition)
str(LetterRecognition)
data("HouseVotes84")
head(HouseVotes84)
?HouseVotes84
BostonHousing
data(BostonHousing)
?BostonHousing
data("Sonar")
data("Vehicle")
?Sonar
head(Sonar)
str(Sonar)
?Vehicle
head(Vehicle)
str(Vehicle)
str(Vowel)
data("Vowel")
str(Vowel)
?Vowel
Glass
?Glass
?Soybean
?Zoo
head(Zoo)
rownames(Zoo)
View(Zoo)
library(KlaR)
library(klaR)
install.packages("klaR")
library(klaR)
library(help=klaR)
data("GermanCredit")
head(GermanCredit)
dim(GermanCredit)
B3
data(B3)
B3
?B3
centerlines
?centerlines
example("triplot")
data(countries)
?countries
head(countries)
?woe
library(help=kernlab)
library(kernlab)
install.packages
install.packages("kernlab")
library(kernlab)
library(help=kernlab)
specc
data(spam)
?spam
head(spa,)
head(spam)
example(spam)
dim(spam)
data(promotergene)
?promotergene
head(promotergene)
ranking
reuters
data(reuters)
reuters
?reuters
spirals
data(spirals)
head(v)
head(spirals)
data(ticdata)
head(ticdata)
?ticdata
str(ticdata)
data(income)
head(income)
str(income)
data(musk)
?mush
?musk
str(musk)
getwd()
setwd("/Users/selvaprabhakaran/Documents/work/rwork/EDXAnalyticsEdge")
quality = read.csv("quality.csv")
str(quality)
table(quality$PoorCare)
98/131
install.packages("caTools")
library(caTools)
# Randomly split data
set.seed(88)
?sample.split
split = sample.split(quality$PoorCare, SplitRatio = 0.75)
split
qualityTrain = subset(quality, split == TRUE)
qualityTest = subset(quality, split == FALSE)
# Logistic Regression Model
QualityLog = glm(PoorCare ~ OfficeVisits + Narcotics, data=qualityTrain, family=binomial)
summary(QualityLog)
predictTrain = predict(QualityLog, type="response")
summary(predictTrain)
predictTrain = predict(QualityLog, type="response")
predictTrain
summary(predictTrain)
plogis(predictTrain)
summary(plogis(predictTrain))
tapply(predictTrain, qualityTrain$PoorCare, mean)
predictTrain
qualityTrain$PoorCare
?tapply
predictTrain
tapply(predictTrain, qualityTrain$PoorCare, mean)
groups <- as.factor(rbinom(32, n = 5, prob = 0.4))
tapply(groups, groups, length)
groups
table(qualityTrain$PoorCare, predictTrain > 0.5)
install.packages("ROCR")
library(ROCR)
ROCRpred = prediction(predictTrain, qualityTrain$PoorCare)
ROCRpred
ROCRpred
predictTrain
ROCRperf = performance(ROCRpred, "tpr", "fpr")
ROCRperf
ROCRperf
plot(ROCRperf)
library(InformationValue)
plotROC(qualityTrain$PoorCare, predictTrain)
plot(ROCRperf, colorize=TRUE)
plot(ROCRperf, colorize=TRUE, print.cutoffs.at=seq(0,1,by=0.1), text.adj=c(-0.2,1.7))
plotROC
?plotROC
plotROC(qualityTrain$PoorCare, predictTrain, Show.labels = T)
library(help="ROCR.hiv")
library(help="ROCR")
optimalCutoff(qualityTrain$PoorCare, predictTrain)
?optimalCutoff
optimalCutoff(qualityTrain$PoorCare, predictTrain, optimiseFor = "Ones")
optimalCutoff(qualityTrain$PoorCare, predictTrain, optimiseFor = "Zeros")
optimalCutoff(qualityTrain$PoorCare, predictTrain, optimiseFor = "both")
optimalCutoff(qualityTrain$PoorCare, predictTrain, optimiseFor = "Both")
BreastCancer
sapply(c("mlbench", "kernlab"), library)
lapply(c("mlbench", "kernlab"), library)
library(mlbench)
library(kernlab)
BreastCancer
str(BreastCancer)
levels(BreastCancer)
levels(BreastCancer$Class)
BreastCancer -> a
as.character(BreastCancer$Class)
ifelse(as.character(BreastCancer$Class) == "malignant", 1, 0)
bc <- BreastCancer
bc$Class <- ifelse(as.character(BreastCancer$Class) == "malignant", 1, 0)
head(bc)
tail(bc)
setwd("/Users/selvaprabhakaran/Documents/Complete R Programming Course/Data/datasets
")
setwd("/Users/selvaprabhakaran/Documents/Complete R Programming Course/Data/datasets")
write.csv(bc, "BreastCancer.csv", row.names=F)
mlbench::Ionosphere
library(mlbench)
mlbench::Ionosphere
data("Ionosphere")
Ionosphere
?Ionosphere
is
is <- Ionosphere
is
is()
is <- Ionosphere
head(Ionosphere)
is$Class <- ifelse(as.character(Ionosphere$Class) == "good", 1, 0)
is
Ionosphere$Class
is$Class
is$Class <- ifelse(as.character(Ionosphere$Class) == "good", 1, 0)
write.csv(is, "Ionosphere.csv", row.names=F)
mlbench::PimaIndiansDiabetes
data("PimaIndiansDiabetes2")
head(PimaIndiansDiabetes2)
head(PimaIndiansDiabetes)
data("PimaIndiansDiabetes")
data(spam)
pid
pid <- PimaIndiansDiabetes
?space
x <- rep(1:5, 10)
y <- round(rnorm(length(x),x))
prepar <- par("mfrow")
par(mfrow=c(1,3))
# standard x-y plot: noverlapping points are hidden
plot(x,y)
# 'spaced' plot: overlapping points are spread out and visible
plot(space(x,y))
title("Plot with 'space'")
sp <- spam
pg <- promotergene
tic <- ticdata
ms <- musk
head(pid)
str(pid)
hv <- HouseVotes84
head(hv)
table(hv$Class)
hv <- HouseVotes84
hv$Class <- ifelse(as.character(hv$Class) == "republican", 1, 0)
write.csv(hv, "HouseVotes84.csv", row.names=F)
sr <- Sonar
head(sr)
table(sr$Class)
sr$Class <- ifelse(as.character(sr$Class) == "R", 1, 0)
data(Sonar)
sr <- Sonar
sr$Class <- ifelse(as.character(sr$Class) == "R", 1, 0)
write.csv(sr, "Sonar.csv", row.names=F)
data("GermanCredit")
gc <- GermanCredit
tail(gc)
gc$credit_risk <- ifelse(as.character(gc$credit_risk) == "good", 1, 0)
write.csv(gc, "GermanCredit.csv", row.names=F)
data(spam)
sp <- spam
tail(sp)
tail(pg)
table(pg$Class)
pg$Class <- ifelse(as.character(pg$Class) == "+", 1, 0)
tail(tic)
table(tic$CARAVAN)
headms$Class
head(ms$Class)
head(ms)
head(ms$Class)
setwd("/Users/selvaprabhakaran/Documents/Complete R Programming Course/Data/datasets")
library(mlbench)
library(kernlab)
library(klaR)
# Breast Cancer
bc <- BreastCancer
bc$Class <- ifelse(as.character(BreastCancer$Class) == "malignant", 1, 0)
write.csv(bc, "BreastCancer.csv", row.names=F)
# mlbench::Ionosphere
data("Ionosphere")
is <- Ionosphere
is$Class <- ifelse(as.character(Ionosphere$Class) == "good", 1, 0)
write.csv(is, "Ionosphere.csv", row.names=F)
# mlbench::PimaIndiansDiabetes
data("PimaIndiansDiabetes")
pid <- PimaIndiansDiabetes
pid$diabetes <- ifelse(as.character(pid$diabetes) == "pos", 1, 0)
write.csv(is, "PimaIndiansDiabetes.csv", row.names=F)
# mlbench::HouseVotes84
data(HouseVotes84)
hv <- HouseVotes84
hv$Class <- ifelse(as.character(hv$Class) == "republican", 1, 0)
write.csv(hv, "HouseVotes84.csv", row.names=F)
# mlbench::Sonar
data(Sonar)
sr <- Sonar
sr$Class <- ifelse(as.character(sr$Class) == "R", 1, 0)
write.csv(sr, "Sonar.csv", row.names=F)
# klaR::GermanCredit
data("GermanCredit")
gc <- GermanCredit
gc$credit_risk <- ifelse(as.character(gc$credit_risk) == "good", 1, 0)
write.csv(gc, "GermanCredit.csv", row.names=F)
# kernlab::spam
data(spam)
sp <- spam
sp$type <- ifelse(as.character(sp$type) == "spam", 1, 0)
write.csv(sp, "spam.csv", row.names=F)
# kernlab::promotergene
data(promotergene)
pg <- promotergene
pg$Class <- ifelse(as.character(pg$Class) == "+", 1, 0)
write.csv(pg, "promotergene.csv", row.names=F)
# kernlab::ticdata
data(ticdata)
tic <- ticdata
tic$CARAVAN <- ifelse(as.character(tic$CARAVAN) == "insurance", 1, 0)
write.csv(tic, "ticdata.csv", row.names=F)
# kernlab::musk
data(musk)
ms <- musk
ms$Class <- ifelse(as.character(ms$Class) == 1, 1, 0)
write.csv(ms, "musk.csv", row.names=F)
?Sonar
?ticdata
a <- read.csv("http://bit.ly/1NILUyA")
a <- read.csv("https://github.com/selva86/datasets/blob/master/Ionosphere.csv")
head(a)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。