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
% Package for subfloat | |
\usepackage{subfig} | |
% Figure with two sub-figures | |
\begin{figure} | |
\centering | |
\subfloat[caption of the figure goes here] | |
{ | |
\includegraphics[scale=.5]{fig-1.pdf} | |
\label{fig:foo-1} |
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
import numpy as np | |
def latlon2km(latlon1,latlon2): | |
# approximate radius of earth in km | |
R = 6373.0 | |
lat1 = np.radians(latlon1[0]) | |
lon1 = np.radians(latlon1[1]) | |
lat2 = np.radians(latlon2[0]) | |
lon2 = np.radians(latlon2[1]) |
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
import numpy as np | |
import statsmodels.formula.api as sm | |
def backward_elimination(X, y, sl): | |
""" | |
X: the data matrix with the independent variables (predictors) | |
y: the matrix of the dependent variable (target) | |
sl: statistical level, by default the user should add 0.05 (5%) | |
""" | |
X = np.append(arr=np.ones((len(X),1)).astype(int), values=X, axis=1) | |
while(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
import numpy as np | |
import statsmodels.formula.api as sm | |
def backward_elimination2(X, y, sl): | |
""" | |
X: the data matrix with the independent variables (predictors) | |
y: the matrix of the dependent variable (target) | |
sl: statistical level, by default the user should add 0.05 (5%) | |
""" | |
X = np.append(arr=np.ones((len(X),1)).astype(int), values=X, axis=1) | |
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
import re | |
my_string = "012.345.678-09" | |
digits_pattern = r"\d+" | |
digits = re.findall(digits_pattern, my_string) | |
number = int(''.join(digits)) | |
print(number) | |
# output: 1234567809 |
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
""" | |
Defining a custom function to be applied in pandas groupby | |
""" | |
import numpy as np | |
import pandas as pd | |
clients = ['joao', 'joao', 'joao', 'lucas', 'lucas', 'julia', 'julia', 'julia', 'julia'] | |
products = ['smartphone', 'notebook', 'book', 'ball', 'car', 'hat', 'bike', 'mouse', 'pen'] |
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(tidyverse) | |
# toy dataset | |
df <- tibble( | |
clientes = c('joao', 'joao', 'joao', 'lucas', 'lucas', 'julia', 'julia', 'julia', 'julia'), | |
produtos = c('celular', 'notebook', 'livro', 'bola', 'carro', 'chapéu', 'moto', 'moto', 'caneta') | |
) | |
# função customizada | |
get_produtos <- function(produtos){ |
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
import numpy as np | |
import pandas as pd | |
from sklearn import datasets | |
from sklearn.tree import DecisionTreeClassifier | |
from sklearn.metrics import accuracy_score | |
from sklearn.model_selection import GroupKFold | |
# Loading the data | |
iris = datasets.load_iris() | |
design_matrix = np.concatenate((iris['data'], iris['target'].reshape(150,1)), axis=1) |
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
import pandas as pd | |
from sklearn.tree import DecisionTreeClassifier | |
from sklearn.model_selection import train_test_split | |
from sklearn.pipeline import Pipeline | |
from sklearn.impute import SimpleImputer | |
from category_encoders import OneHotEncoder | |
# lendo o dataset | |
df = pd.read_csv("train.csv") |
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
import pandas as pd | |
from sklearn.tree import DecisionTreeClassifier | |
from sklearn.model_selection import train_test_split | |
from sklearn.pipeline import Pipeline | |
from sklearn.impute import SimpleImputer | |
from category_encoders import OneHotEncoder | |
from sklearn.model_selection import KFold | |
from sklearn.model_selection import cross_validate | |
# lendo o dataset |
OlderNewer