Skip to content

Instantly share code, notes, and snippets.

View halilbilgin's full-sized avatar
💭
Fun times

Halil Bilgin halilbilgin

💭
Fun times
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@halilbilgin
halilbilgin / welchtTest.R
Last active March 17, 2018 13:00
R code for t test
calculatePforWelchtTest = function(s) {
t.value = (s['mean', 'x'] - s['mean', 'y'] - 0) /
(sqrt(s['var', 'x']/s['#samples', 'x'] +
s['var', 'y']/s['#samples', 'y'] )
)
r = (s['var', 'x']/s['#samples', 'x'] +
s['var', 'y']/s['#samples', 'y'] )^2 /
( (s['var', 'x']/s['#samples', 'x'])^2/(s['#samples', 'x']-1) +
(s['var', 'y']/s['#samples', 'y'])^2/(s['#samples', 'y']-1)
@halilbilgin
halilbilgin / variableImportance.R
Created November 12, 2017 16:51
Variable Importance function for deep learning
#This function assumes that there is at least one hidden layer.
variableImportance = function(modelTf) {
numberOfWeights = c(dim(modelTf$weight$W1)[2], dim(modelTf$weight$W2)[2], dim(modelTf$weight$W2)[1])
Qik = matrix(0, numberOfWeights[1], numberOfWeights[3])
sumWj = array(0, numberOfWeights[2]);
sumWk = array(0, numberOfWeights[3]);
for(j in 1:numberOfWeights[2]){
sumWj[j] = sum(abs(modelTf$weight$W1[,j]))
@halilbilgin
halilbilgin / MontyHall.java
Created October 21, 2017 18:57
Solve Monty Hall Problem using Monte Carlo simulations
public class MontyHall {
int usersChoice;
int doorWithTheCar;
}
nuSVRGrid <- expand.grid(
gamma = c(0.0000305176, 0.000122070, 0.000488281, 0.00195313, 0.0078125, 0.03125, 0.125, 0.5, 2, 8, 32),
nu = c(0.01,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,
0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9,0.95,1.0),
C = c(0.0000305176,0.000122070,0.000488281,0.00195313,0.0078125,
0.03125,0.125,0.5,2,8,32)
)
library(doParallel)
registerDoParallel(cores=10)
modelInfo <- list(label = "nu-SVR with Radial Basis Function Kernel",
library = "e1071",
type = c("Regression"),
parameters = data.frame(parameter = c("nu", "C", "gamma"),
class = c("numeric", "numeric", "numeric"),
label = c("Nu", "Cost", "Gamma")),
loop = NULL,
grid=NULL,
fit = function(x, y, wts, param, lev, last, classProbs, ...) {
if(any(names(list(...)) == "prob.model") | is.numeric(y)) {
@halilbilgin
halilbilgin / trainingTest
Last active June 14, 2017 01:25
split data into training and test sets without data leakage
trTest <- function(dataset, p = 0.75, scaleData='min-max', colsToBeScaled = c()) {
dataset[, 'train'] <- ifelse(runif(nrow(dataset)) <= p, 1, 0)
trData <- dataset[dataset[, 'train'] == 1,]
tData <- dataset[dataset[, 'train'] == 0,]
trData[,'train'] <- NULL
tData[,'train'] <- NULL
if(scaleData != FALSE) {
@halilbilgin
halilbilgin / crossValidation
Last active June 14, 2017 01:23
do cross validation without data leakage
crossValidation <- function(dataset, k = 10, scaleData='min-max', colsToBeScaled = c()) {
require(caret)
#create fold ids
folds <- createFolds(as.integer(row.names(dataset)), k = k)
folds <- lapply(folds, function(x) {
scaleData <- get('scaleData')
colsToBeScaled <- get('colsToBeScaled')
trData <- get('dataset')[-c(x), ]
tData <- get('dataset')[c(x), ]