Code Monkey home page Code Monkey logo

Comments (2)

Greenwind1 avatar Greenwind1 commented on September 26, 2024
library(CASdatasets)  ## ausprivauto0405
library(dplyr)  ## group_by, summarise
library(ggplot2)  ## ggplot, geom_histogram, geom_bar, geom_point, coord_flip
library(MASS)  ## stepAIC
library(glmnet)
library(glmnetUtils) ## cv.glmnet
library(cvTools)  ## cvFolds
library(Matrix)  ## sparse.model.matrix
library(makedummies)  ## makedummies
library(aglm)  ## cv.aglm
library(parallel)  ## detectCores

## SETTING
col1 <- "gray"
col2 <- "deeppink"
SEED <- 2018
CPU <- detectCores() - 1

data("ausprivauto0405")  ## load data
aus.df <- ausprivauto0405
rm(ausprivauto0405)
dim(aus.df)  ## dimension of data

## IsClaim
aus.df["IsClaim"] <- aus.df$ClaimNb > 0

## DATA SPLIT
set.seed(SEED)  # for reproduciability
hold.out.num <- 
    sample(seq(nrow(aus.df)), round(nrow(aus.df) / 4))
aus.df['isHoldOut'] <- FALSE
aus.df[hold.out.num, 'isHoldOut'] <- TRUE
train <- aus.df[!aus.df$isHoldOut, ]
hold.out <- aus.df[aus.df$isHoldOut, ]

## AGLM
lambda.list <- 0.1^seq(1, 7, length.out = 100)
aus.x.ohe <- makedummies(aus.df[, 1:6], basal_level = FALSE)

aglm.cv.cl <- cv.aglm(
    x = aus.x.ohe[!aus.df$isHoldOut, ], 
    y = as.integer(aus.df[!aus.df$isHoldOut, "IsClaim"]),
    type.measure = "auc",
    nfolds = nfold,
    family = "binomial",
    alpha = 1,
    lambda = lambda.list
    )
(lambda.min <- aglm.cv.cl@lambda.min)

aglm.cl <- aglm(
    x = aus.x.ohe[!aus.df$isHoldOut, ], 
    y = as.integer(aus.df[!aus.df$isHoldOut, "IsClaim"]),
    family = "binomial",
    alpha = 1,
    lambda = lambda.min
)

## PREDICTION
aglm.pred <- 
    predict(aglm.cl, newx = aus.x.ohe[aus.df$isHoldOut, ], type = "response")
aglm.pred <- 
    predict(aglm.cl, newx = aus.x.ohe[aus.df$isHoldOut, ])  # failed

from aglm.

kkondo1981 avatar kkondo1981 commented on September 26, 2024

@Greenwind1 Please try #31

from aglm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.