-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20161202.R
More file actions
70 lines (57 loc) · 2.55 KB
/
Copy path20161202.R
File metadata and controls
70 lines (57 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# LabStat2 02.12.2016
rm(list=ls())
# install.packages("ggplot2")
library(ggplot2)
# install.packages("moments")
library(moments)
# install.packages("lmtest")
library(lmtest)
# install.packages("MASS")
library(MASS)
# install.packages("GGally")
library(GGally)
# install.packages("car")
library(car)
# install.packages("ggfortify")
library(ggfortify)
########## DATA LOADING
?diamonds
data(diamonds)
str(diamonds)
########## SET DIVIDING
set.seed(23) #MEGA WA¯NE!!!!!
train= sample(1:nrow(diamonds),floor(0.6 * nrow(diamonds)))
diamonds_train=diamonds[train,]
diamonds_rest=diamonds[-train,]
query=sample(1:nrow(diamonds_rest),floor(0.5 * nrow(diamonds_rest)))
diamonds_query=diamonds_rest[query,]
diamonds_test=diamonds_rest[-query,]
str(diamonds_train)
summary(diamonds_train)
ggplot(diamonds_train, aes(x=price)) +
geom_histogram(aes(y =..count..), colour="black", fill="white") +
geom_vline(aes(xintercept=mean(price), color="blue"), linetype="dashed", size=1) +
geom_vline(aes(xintercept=median(price), color="green"), linetype="dashed", size=1) +
labs(title="Histogram", x="Cena [USD]", y="LicznoϾ") +
scale_colour_manual(name="Statystyki",values=c('green'='green','blue'='blue'),
labels=c(paste('Mediana =', median(diamonds_train$price)),
paste('Œrednia =', round(mean(diamonds_train$price)),2))) +
annotate("text", x=15000, y=6000, label=paste("Occhylenie std. =", round(sqrt(var(diamonds_train$price)), 2))) +
annotate("text", x=15000, y=6500, label=paste("Skoœnoœæ =", round(skewness(diamonds_train$price), 2))) +
annotate("text", x=15000, y=7000, label=paste("Kurtoza =", round(kurtosis(diamonds_train$price), 2)))
diamonds_train$price <- log(diamonds_train$price)
ggplot(diamonds_train, aes(x=price)) +
geom_histogram(aes(y =..count..), colour="black", fill="white") +
geom_vline(aes(xintercept=mean(price), color="blue"), linetype="dashed", size=1) +
geom_vline(aes(xintercept=median(price), color="green"), linetype="dashed", size=1) +
labs(title="Histogram", x="Cena [USD]", y="LicznoϾ") +
scale_colour_manual(name="Statystyki",values=c('green'='green','blue'='blue'),
labels=c(paste('Mediana =', median(diamonds_train$price)),
paste('Œrednia =', round(mean(diamonds_train$price)),2)))
ggplot(diamonds_train, aes(price, carat)) +
geom_point() +
geom_smooth()
?lm
lm.diamonds_train <- lm(price~., data=diamonds_train)
summary(lm.diamonds_train)
autoplot(lm.diamonds_train, which = 1:6, ncol = 3, label.size = 1)