Skip to content

Wine quality example #104

Description

@fortisil

I am trying to SGD for classification of a huge dataset and wanted first to try it on the example you provided about the wine quality. But with the wine quality, something doesn't work for me. When I am trying to predict using the sgd.theta all the results are false and don't predict the quality at all.

Here is the code:


Wine quality (Cortez et al., 2009): Logistic regression

set.seed(42)
#data("winequality")
#dat <- winequality
dat <- read.csv("../Data/winequality-red.csv", header = TRUE, sep = ";", stringsAsFactors = FALSE)
dat$quality <- as.numeric(dat$quality > 5) # transform to binary
test.set <- sample(1:nrow(dat), size=nrow(dat)/8, replace=FALSE)
dat.test <- dat[test.set, ]
dat <- dat[-test.set, ]
sgd.theta <- sgd(quality ~ ., data=dat,
model="glm", model.control=binomial(link="logit"),
sgd.control=list(reltol=1e-5, npasses=200),
lr.control=c(scale=1, gamma=1, alpha=30, c=1))
sgd.theta
sprintf("Mean squared error: %0.3f", mean((theta - as.numeric(sgd.theta$coefficients))^2))

sum(dat[190,]*sgd.theta$coefficients)


Output>

sgd.theta
[,1]
[1,] -0.21988224003
[2,] -0.14012303981
[3,] -0.70007323510
[4,] 0.24427708544
[5,] -0.27235118177
[6,] -0.06525874448
[7,] 0.07980364712
[8,] -0.04987978826
[9,] -0.21990837019
[10,] -0.74766256961
[11,] 0.24841101887
[12,] 0.55420888771
sprintf("Mean squared error: %0.3f", mean((theta - as.numeric(sgd.theta$coefficients))^2))
[1] "Mean squared error: 26.214"

sum(dat[190,]*sgd.theta$coefficients)
[1] 4.761156998


Maybe am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions