Skip to content

Instantly share code, notes, and snippets.

require(mlbench)
require(caret)
require(MLmetrics)
require(plyr)
require(ade4)
data(Satellite)
summary(Satellite)
dim(Satellite)
my_data <- Satellite
@yabyzq
yabyzq / UI1.R
Last active March 22, 2017 12:13
SOM
library(shiny)
shinyUI(fluidPage(
titlePanel("Self-Organized-Maps"),
fluidRow(
sidebarPanel(
fileInput("file1", "Select CSV:", accept = c("text/csv", "text/comma-separated-values,text/plain", ".csv")),
selectInput("sep", label = "Separator",
choices = list("Coma" = ",", "Semicolon" = ";", "Tab" = "\t"),
selected = 1),
@yabyzq
yabyzq / server1.R
Last active March 22, 2017 12:12
SOM
# based on Manuel Bernal's code
######## SOM GENERATOR ###########
#Loading Packages needed
library(png) # For writePNG function
library(kohonen)
library(shiny)
library(ggplot2)
library(jsonlite)
library(Hmisc)
@yabyzq
yabyzq / SOM - Server.R
Last active February 20, 2017 12:56
Shiny App on SOM
# based on Manuel Bernal's code
######## SOM GENERATOR ###########
#Loading Packages needed
library(png) # For writePNG function
library(kohonen)
library(shiny)
library(ggplot2)
library(jsonlite)
library(Hmisc)
@yabyzq
yabyzq / SOM - Basic.R
Created February 19, 2017 13:23
basic SOM
library(kohonen)
library(Hmisc) # useful for multi histogram
#loading client data
client <- read.csv(file = "C:/Users/eye1/Desktop/Customer Data.csv")
#Feature selection
data_train <- client[, c("NO_OF_PRODUCTS_6","Balance","LOGIN_DAYS_L3M", "ONLINE_TRANSACTION_L3M")]#data_train <- iris[c(1,2,3,4)]
#Explore the data
@yabyzq
yabyzq / MXNET
Created February 13, 2017 13:44
library(Hmisc) # useful for multi histogram
hist.data.frame(full) # histogram of each variable
pairs(full) # pairwise scatter plots
data = mx.symbol.Variable('data')
fc1 = mx.symbol.FullyConnected(data=data, num_hidden=7)
sigm1 = mx.symbol.Activation(data=fc1, act_type="relu")
fc2 = mx.symbol.FullyConnected(data=sigm1, num_hidden=2)
net = mx.symbol.SoftmaxOutput(data=fc2)
@yabyzq
yabyzq / Xgboost.R
Created November 22, 2016 13:43
Xgboost
library(xgboost)
library(Matrix)
library(data.table)
library(vcd)
data(Arthritis)
df <- data.table(Arthritis, keep.rownames = F)
head(df[,AgeDiscret := as.factor(round(Age/10,0))])
@yabyzq
yabyzq / caret.R
Created November 14, 2016 13:59
R - caret data handling
library(caret)
#looking at missing value
options(digits=2)
stats <- data.frame(missing = sapply(iris, function(x) sum(is.na(x))),
mean = sapply(iris, function(x) if(is.numeric(x)) {mean(x, na.rm = T)} else names(table(x)[order(table(x), decreasing = T)])[1])
)
library(rpart)
#Generate binary Target
iris$isSetosa <- "N"
iris[iris$Species == "setosa",]$isSetosa <- "Y"
iris$isSetosa <- as.factor((iris$isSetosa))
levels(iris$isSetosa) <- c("N","Y")
head(iris)
#Create function
@yabyzq
yabyzq / R - ggplot.R
Created October 24, 2016 13:15
basic ggplot
# Basic scatter plot of vocabulary (y) against education (x). Use geom_point()
ggplot(Vocab, aes(education, vocabulary))+geom_point()
# Use geom_jitter() instead of geom_point()
ggplot(Vocab, aes(education, vocabulary))+geom_jitter()
# Using the above plotting command, set alpha to a very low 0.2
ggplot(Vocab, aes(education, vocabulary))+geom_jitter(alpha = 0.2)