This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# read dataset from local file | |
data <- read.csv("/Users/kostya/Downloads/abalone.data.csv", header=F) | |
# set names for dataframe columns | |
colnames(data) <- c('Sex', 'Length', 'Diameter', 'Height', 'WholeWeight', 'ShuckedWeight', | |
'VisceraWeight', 'ShellWeight', 'Rings') | |
# split dataset into train and test seta | |
train.size <- floor(0.9 * nrow(data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(100) | |
N <- 10000000 | |
USER_NUM <- 25000 | |
MOVIE_NUM <- 10000 | |
dayOfWeek = rnorm(N, 6, 2) | |
partOfDay = c(1,2,3,3,4,4,4) | |
isRainOrSnow = c(0,0,0,1) | |
isRainOfSnowBefore = c(0,0,0,1) | |
temperature = c(0,1,2,3,4) | |
cameFrom = c(0,1,2,3,4,5,6,7) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#install.packages("randomForest") | |
library(randomForest) | |
train = read.csv(file="D:\\work\\R\\train.csv",head=TRUE,sep=",") | |
test = read.csv(file="D:\\work\\R\\test.csv",head=TRUE,sep=",") | |
rf = randomForest(ACTION ~ RESOURCE+MGR_ID+ROLE_DEPTNAME+ROLE_FAMILY_DESC+ROLE_ROLLUP_2+ROLE_ROLLUP_1+ROLE_TITLE+ROLE_CODE, data=train, importance=TRUE, ntree=250, mtry=3) | |
prediction = predict(rf, test) | |
write.csv(prediction, "D:\\work\\R\\out.csv", row.names=FALSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def toSort = [5, 6, 7, 1, 4, 3, 2, 9, 0, 7, 8] | |
def partition(toSort) { | |
if(toSort.size == 1) return toSort | |
int midle = (int)(toSort.size/2) | |
def left = new ArrayList(), right = new ArrayList(); | |
for(int i = 0; i < midle; i++) left << toSort[i] | |
for(int i = midle; i < toSort.size; i++) right << toSort[i] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Install the R package arules if required | |
#install.packages("arules"); | |
#load the arules package | |
library("arules"); | |
# read the transaction file as a Transaction class | |
txn = read.transactions(file="d:\\work\\R\\items.csv", rm.duplicates= FALSE, format="basket",sep=","); | |
#To visualize the item frequency in txn file | |
itemFrequencyPlot(txn); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Constants { | |
static final goods = [ | |
'Apple', 'Orange', 'Pineaple', 'Cherry', 'Beef', 'Sugar', 'Milk', | |
'Pear', 'Limon', 'Blubbery', 'IceCream', 'Cake', 'Orange', 'Milk', | |
'Cola', 'Bread', 'Coffe', 'Cookies', 'Beer', 'Tea', 'Salmon', 'Steal Water', 'Nuts'] | |
} | |
rand = new Random() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
<dependencies> | |
<dependency> | |
<groupId>com.rabbitmq</groupId> | |
<artifactId>amqp-client</artifactId> | |
<version>3.1.1</version> | |
</dependency> | |
</dependencies> | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def levenshtain(String s1, String s2, int i, int j) { | |
if(i == -1 && j == -1) { | |
return 0 | |
} else if( j == -1 && i > -1 ) { | |
return i | |
} else if(i == -1 && j > -1) { | |
return j | |
} else { | |
return min( | |
levenshtain(s1, s2, i, j-1)+1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node { | |
def val | |
def left | |
def right | |
} | |
/* | |
root | |
A B |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int i = 0; | |
File file = new File("out2.csv") | |
file << "Id,Action\n" | |
new File('out.csv').eachLine { line -> | |
if(i > 0) { | |
file.append i | |
file.append ',' | |
file.append Double.valueOf(line) > 0.6 ? 1 : 0; | |
file.append '\n' |