-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplication_On_GlassData.R
51 lines (34 loc) · 1.18 KB
/
Application_On_GlassData.R
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
# Data set from https://machinelearningmastery.com/machine-learning-datasets-in-r/
library(pracma)
library(mlbench)
# Glass Identification Database
data(Glass)
dim(Glass)
levels(Glass$Type)
head(Glass)
# Put Glass data into dataframe
df <- data.frame(Glass)
# Remove NA values by removing row
df <- na.omit(df)
# init = rep(.1, ncol(df))
model1 <- glm(Type ~ RI + Na + Mg + Al + Si + K + Ca + Ba + Fe, data = df, family = binomial)
init = model1$coefficients + .05*rnorm(ncol(df), 0, 1)
df <- cbind(free = 1, df)
# y <- rbinom(nrow(df), 1, p.true)
# df[ncol(df)] <- y
# Turn df into a matrix to make compatible with algorithm
print(unique(df[c("Type")]))
df <- data.matrix(df)
# df_norm <- as.data.frame(lapply(df[:], min_max_norm))
# df_norm <- scale(df)
# print(df)
# # Apply the stochastic newton algo
# print(tail(stochastic_newton_algo(df,init))) # Output gives lots on NaNs (could be dividing by 0?)
#
# # Apply the truncated stochastic netwon algo
# print(tail(trunc_stochastic_newton_algo(df, 10^(-10), .49, init)))
#
# model1 <- glm(Type ~ RI + Na + Mg + Al + Si + K + Ca + Ba + Fe, data = Glass, family = binomial)
print(model1$coefficients)
print(sgd2(df))
print(tail(df))