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
cdb <- function(capital, data_aplicacao, data_resgate, di, pct_cdi){ | |
library(dplyr) | |
library(bizdays) | |
dias_corridos <- as.numeric(difftime(data_resgate, data_aplicacao, units = "days")) | |
# computar biz days entre datas | |
bizdays::create.calendar("Brazil/ANBIMA", | |
bizdays::holidaysANBIMA, | |
weekdays=c("saturday", "sunday")) |
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
library(BatchGetSymbols) | |
library(tidyverse) | |
library(varngc) | |
x <- GetSP500Stocks() | |
stocks <- c("AAPL", "GOOG", "MSFT", "AMZN", "ADBE", "EBAY", "FB", "HPQ") | |
st <- as.Date("2010-01-01") | |
end <- as.Date("2018-01-01") |
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
plot_rf_tree <- function(final_model, tree_num, shorten_label = TRUE) { | |
# source: https://shiring.github.io/machine_learning/2017/03/16/rf_plot_ggraph | |
# get tree by index | |
tree <- randomForest::getTree(final_model, | |
k = tree_num, | |
labelVar = TRUE) %>% | |
tibble::rownames_to_column() %>% | |
# make leaf split points to NA, so the 0s won't get plotted |
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
# Criando um Correlation Plot | |
def visualize_correlation_matrix(data, hurdle = 0.0): | |
# fonte: data science academy | |
R = np.corrcoef(data, rowvar = 0) | |
R[np.where(np.abs(R) < hurdle)] = 0.0 | |
heatmap = plt.pcolor(R, cmap = mpl.cm.coolwarm, alpha = 0.8) | |
heatmap.axes.set_frame_on(False) | |
heatmap.axes.set_yticks(np.arange(R.shape[0]) + 0.5, minor = False) | |
heatmap.axes.set_xticks(np.arange(R.shape[1]) + 0.5, minor = False) | |
heatmap.axes.set_xticklabels(variables, minor = 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
#Code for "A Statistical Curiosity Voyage Through the Emotion of Stranger Things" | |
#Article and code written by Jordan Dworkin (https://medium.com/@jordandworkin/) | |
############################################################################### | |
####### Pull script data (would need to be edited based on data source) ####### | |
############################################################################### | |
library(rvest) | |
library(tibble) |
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
library(tidyverse) | |
library(purrr) | |
library(forecast) | |
library(lubridate) | |
vetor_uf <- c("RJ", "SP", "MG", "ES") | |
vetor_data <- seq.Date(as.Date("2010-01-01"), by = "month", | |
length.out = 60) |
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
grafico_tfidf <- function(data, n_grams = 1, remover_nomes_proprios, | |
agregar_por_noticia, remover_stop_words = TRUE){ | |
data <- data %>% | |
unnest_tokens(palavra, corpo_noticia, token = "ngrams", n = n_grams, to_lower = FALSE) | |
if (agregar_por_noticia){ | |
# remover as duplicatas dentre de uma mesma noticia | |
data %<>% distinct(url, palavra, .keep_all = TRUE) | |
} |
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
# source: https://gist.github.com/corynissen/5389426 | |
getLongURL.curl <- function(shorturl){ | |
# uses curl statement to get expanded url from t.co links (or any link) | |
# loop through until there's no location attribute... that's the long link. | |
newurl <- shorturl | |
url <- "" | |
while(url != newurl){ | |
data <- system(paste0("curl -I ", newurl), intern=T) | |
if(sum(grepl("location: ", tolower(data))) == 0){ |
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
library(stringr) | |
library(magrittr) | |
library(lubridate) | |
library(glue) | |
library(dplyr) | |
library(readr) | |
# exemplo: | |
extrair_ans_UF <- function(uf, limpar_pasta_temporaria = TRUE) { |
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
# projeto analise de sentimento | |
library(tidyr) | |
library(dplyr) | |
library(magrittr) | |
library(stringr) | |
library(lubridate) | |
library(ggplot2) | |
library(tm) | |
library(SnowballC) | |
library(wordcloud) |