View predict.r
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
# Predict the test set using the model | |
pred_lasso = predict(glmmod, test_sparse, type="response", s=best.lambda) | |
pred_lasso | |
# Apply a threshold | |
new_pred_lasso = ifelse(pred_lasso >= 0.5, 1, 0) | |
new_pred_lasso = data.frame(new_pred_lasso) | |
data_lasso = cbind(test[,2], new_pred_lasso) | |
names(data_lasso) = c("actual", "pred") | |
xtab_lasso = table(data_lasso$actual, data_lasso$pred) |
View analysis.r
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
# getBicop is a snippet from https://stats.stackexchange.com/questions/15011/generate-a-random-variable-with-a-defined-correlation-to-an-existing-variables/15035#15035 | |
# returns a data frame of two variables which correlate with a population correlation of rho | |
# If desired, one of both variables can be fixed to an existing variable by specifying x | |
getBiCop <- function(n, rho, mar.fun=rnorm, x = NULL, ...) { | |
if (!is.null(x)) {X1 <- x} else {X1 <- mar.fun(n, ...)} | |
if (!is.null(x) & length(x) != n) warning("Variable x does not have the same length as n!") | |
C <- matrix(rho, nrow = 2, ncol = 2) | |
diag(C) <- 1 | |
View word2vec_emotions.py
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
import gensim | |
from gensim.models.keyedvectors import KeyedVectors | |
# Load Google's pre-trained Word2Vec model. | |
model = KeyedVectors.load_word2vec_format('I:/Downloads/GoogleNews-vectors-negative300.bin/GoogleNews-vectors-negative300.bin', binary=True) | |
word1 = 'anger' | |
word2 = 'trust' | |
model.most_similar(positive = [word1, word2]) | |
word_w2v = 'resentment' |
View gist:bdc7821fc650563ffd3e2596fa3ff8ab
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
import gensim | |
from gensim.models.keyedvectors import KeyedVectors | |
# Load Google's pre-trained Word2Vec model. | |
model = KeyedVectors.load_word2vec_format('I:/Downloads/GoogleNews-vectors-negative300.bin/GoogleNews-vectors-negative300.bin', binary=True) | |
word1 = 'anger' | |