This file contains hidden or 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
users.gender.replace('-unknown-', np.nan, inplace=True) |
This file contains hidden or 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
users_nan = (users.isnull().sum() / users.shape[0]) * 100 | |
users_nan[users_nan > 0].drop('country_destination') |
This file contains hidden or 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
users[users.age > 122]['age'].describe() |
This file contains hidden or 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
users.loc[users.age > 95, 'age'] = np.nan |
This file contains hidden or 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
## Convert categorical features into numerical features ## | |
for (f in common_vars) { | |
if (class(train[[f]]) == "character"){ | |
levels <- unique(c(train[[f]], test[[f]])) | |
train[[f]] <- as.integer(factor(train[[f]], levels=levels)) | |
test[[f]] <- as.integer(factor(test[[f]], levels=levels)) | |
} | |
} |
This file contains hidden or 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
nci = subset(nci, select = c("CNS", "RENAL", "BREAST", "NSCLC", "MELANOMA", "OVARIAN", "LEUKEMIA", "COLON")) | |
nci = nci[, c("CNS", "RENAL", "BREAST", "NSCLC", "MELANOMA", "OVARIAN", "LEUKEMIA", "COLON")] | |
nci = nci[, which(colnames(nci) %in% c("CNS", "RENAL", "BREAST", "NSCLC", "MELANOMA", "OVARIAN", "LEUKEMIA", "COLON"))] |
This file contains hidden or 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
result = if(any(result <= 1.5)) 1 else 2 | |
result = ifelse(result <= 1.5, 1, 2) |
This file contains hidden or 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
prediction <- as.numeric(pred > 0.5) |
This file contains hidden or 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
err <- mean(as.numeric(pred > 0.5) != test$label) |
This file contains hidden or 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
library(xgboost) | |
X = as.matrix(train[,-58]) | |
y = train[,58] | |
numberOfClasses <- max(y) + 1 | |
bst <- xgboost(data = X, label = y, max.depth = 2, eta = 1, nthread = 2, nround = 200, objective = "binary:logistic", verbose = 1) | |
pred = predict(bst, data.matrix(test[,-58])) | |
pred = as.numeric(pred > 0.5) |