Datascience 161212042051
Datascience 161212042051
Datascience 161212042051
DE DADOS
NAUBER GOIS
Aluno de Doutorado em Informática Aplicada da Unifor
Área de Estudo: Reinforcement Learning e
metaheurísticas aplicadas a testes de performance.
Analista de Desenvolvimento do Serpro
AGENDA
DEFINIÇÃO DE DATA SCIENCE
TIPOS DE MODELOS
EXEMPLOS DE APLICAÇÃO
RELATÓRIOS
TESTES A/B
O QUE É CIÊNCIA
DE DADOS?
DATA SCIENCE É MAIS
UM TERMO USADO
PARA DESCREVER O
PROCESSO DE
TRANSFORMAÇÃO DE
DADOS EM
CONHECIMENTO.
(LOUKIDES, 2016)
5
CIENTISTA DE
DADOS
Matemática e
estatística
Banco de Dados e
Programação
Conhecimento de
Negócio
Comunicação
Usar (coletar, armazenar, publicar) dados
não é data science. É preciso agregar
valor aos dados e permitir novas formas
de uso.
9
DESMISTIFICANDO A CIÊNCIA DE DADOS
DESMISTIFICANDO A CIÊNCIA DE DADOS
U.M.Fayyad, G.Patetsky-
Shapiro and P.Smyth (1995)
PROCESSO?
DESMISTIFICANDO A CIÊNCIA DE DADOS
13
DESMISTIFICANDO A CIÊNCIA DE DADOS
FORMULAÇÃO DE UM PROBLEMA
Identificação de uma área de interesse e o tipo de modelo
Clustering
14
DESMISTIFICANDO A CIÊNCIA DE DADOS
X 1 X 1 X 1
■ k-th Nearest Neighbour ■ Linear Discriminant Analysis, QDA ■ Classical Linear Regression
■ Parzen Window
■ Logistic Regression (Logit) ■ Ridge Regression
■ Unfolding, Conjoint Analysis,
Cat-PCA ■ Decision Trees, LSSVM, NN, VS ■ NN, CART
TIPOS DE
MODELOS
REGRESSÃO
CLASSIFICAÇÃO
AGRUPAMENTO
19
DESMISTIFICANDO A CIÊNCIA DE DADOS
CLASSIFICAÇÃO VS REGRESSÃO
20
O QUE É
REGRESSÃO
?
21
DESMISTIFICANDO A CIÊNCIA DE DADOS
https://plot.ly/pandas/line-and-scatter/
REGRESSÃO
DESMISTIFICANDO A CIÊNCIA DE DADOS
REGRESSÃO
24
DESMISTIFICANDO A CIÊNCIA DE DADOS
25
DESMISTIFICANDO A CIÊNCIA DE DADOS
REGRESSION ERROR
26
DESMISTIFICANDO A CIÊNCIA DE DADOS
BIAS E OVERFITTING
27
DESMISTIFICANDO A CIÊNCIA DE DADOS
OCCAM'S RAZOR
• Se os resultados forem
semelhantes escolha a
solução mais simples.
• Em Data Science prefira
sempre o modelo mais
simples
DESMISTIFICANDO A CIÊNCIA DE DADOS
29
O QUE É
CLASSIFICAÇÃO
?
30
DESMISTIFICANDO A CIÊNCIA DE DADOS
CLASSIFICAÇÃO
A A
B A
?
B B
31
DESMISTIFICANDO A CIÊNCIA DE DADOS
CLASSIFICADORES
DESMISTIFICANDO A CIÊNCIA DE DADOS
?
DESMISTIFICANDO A CIÊNCIA DE DADOS
A B
A ?
B
C
DESMISTIFICANDO A CIÊNCIA DE DADOS
• Dados de Teste
• Usados para testar a
performance do modelo
• Dados de validação.
Classificação
38
DESMISTIFICANDO A CIÊNCIA DE DADOS
• Não Supervisionado
• Sem conhecimento prévio
dos dados
• O objetivo é determinar
padrões
O QUE É
AGRUPAMENTO
?
40
DESMISTIFICANDO A CIÊNCIA DE DADOS
AGRUPAMENTO
Processo de agrupar objetos com características semelhantes
DESMISTIFICANDO A CIÊNCIA DE DADOS
CLUSTER
DESMISTIFICANDO A CIÊNCIA DE DADOS
COMO AGRUPAR?
DESMISTIFICANDO A CIÊNCIA DE DADOS
DISTÂNCIA
DESMISTIFICANDO A CIÊNCIA DE DADOS
MODELOS DE AGRUPAMENTO
ANÁLISE
DE
TEXTO
47
DESMISTIFICANDO A CIÊNCIA DE DADOS
Uma mutação aparentemente insignificante no
ANALISANDO TEXTO
Passados quase três meses do final dos Jogos, o Comitê
DNA dos ancestrais da humanidade
pode ter contribuído para que nosso cérebro
alcançasse o tamanho descomunal que tem
Rio-2016 ainda deve reembolso a hoje (três vezes maior que o dos grandes
macacos).
8.000 torcedores que utilizaram sua Bastou inserir o gene que contém essa
plataforma online para revender ingressos.
mutação em fetos de camundongo para que
dobrasse o número de células que dão origem
A entidade reduziu o contingente de consumidores a
aos neurônios do córtex, a área cerebral mais
quem devia pagamentos, que chegou a 140 mil em 19 de
"nobre".
outubro, data até a qual prometeu quitar os débitos. Mas
ainda não deu fim ao problema.
ANÁLISE DE SENTIMENTO
REPRESENTAÇÃO DE TEXTO
ANALISANDO A
PERFORMANCE
DE UM MODELO
51
DESMISTIFICANDO A CIÊNCIA DE DADOS
ACURÁCIA
DESMISTIFICANDO A CIÊNCIA DE DADOS
PERFORMANCE DE UM CLASSIFICADOR
• Acuracia = classificados corretamente /total de exemplos
• Erro = 1-Acuracia
TABELA CONFUSÃO
56
NUMPY
Biblioteca em python para
manipulação de arrays e
matrizes
PANDAS
Biblioteca de Manipulação
de dados e analise em
python
DESMISTIFICANDO A CIÊNCIA DE DADOS
import numpy as np
import pandas as pd
import visuals as vs # Supplementary code
from sklearn.cross_validation import ShuffleSplit
CLASSIFICAÇÃO NO SKLEARN
# Create a classifier: a support vector classifier
classifier = svm.SVC(gamma=0.001)
CLASSIFICANDO EMAILS
classifier = MultinomialNB()
…
classifier.fit(counts, targets)
7 F 2.1 8.1
8 F 2.1 8.2
67
EXEMPLO DE PROBLEMA - ÁREA (BIOLOGIA) - TIPO: REGRESSÃO
PESO CORAÇÃO
Peso
ggplot(a,aes(a$Bwt,a$Hwt))+geom_point()
68
EXEMPLO DE PROBLEMA - ÁREA (BIOLOGIA) - TIPO: REGRESSÃO
PESO CORAÇÃO
Peso
ggplot(a,aes(a$Bwt,a$Hwt))+geom_point()+geom_smooth()
69
70
EXEMPLO
PREDIZER
PREÇOS DE
CASAS EM
BOSTON
EXEMPLO DE PROBLEMA - PREÇO DE IMÓVEIS EM BOSTON
• RM' -Média do número de quartos
•'LSTAT' percentual de proprietários considerados "lower class" (working poor).
•'PTRATIO' razão do número de estudantes por professor no bairro
ARVORES DE DECISÃO
EXEMPLO DE PROBLEMA - PREÇO DE IMÓVEIS EM BOSTON
regressor = DecisionTreeRegressor(random_state=42)
# Fit the grid search object to the data to compute the optimal
model
grid = grid.fit(X, y)
EXEMPLO DE PROBLEMA - PREÇO DE IMÓVEIS EM BOSTON
PREDICTING
# Show predictions
for i, price in
enumerate(reg.predict(client_data)):
INTERVENÇÃO DE ESTUDANTES
Feature values:
school sex age address famsize Pstatus Medu Fedu Mjob Fjob \
0 GP F 18 U GT3 A 4 4 at_home teacher
1 GP F 17 U GT3 T 1 1 at_home other
2 GP F 15 U LE3 T 1 1 at_home other
3 GP F 15 U GT3 T 4 2 health services
4 GP F 16 U GT3 T 3 3 other other
... higher internet romantic famrel freetime goout Dalc Walc health \
0 ... yes no no 4 3 4 1 1 3
1 ... yes yes no 5 3 3 1 1 3
2 ... yes yes no 4 3 2 2 3 3
3 ... yes yes yes 3 2 2 1 1 5
4 ... yes no no 4 3 2 1 2 5
absences
0 6
1 4
2 10
3 2
4 4
INTERVENÇÃO DE ESTUDANTES
PREPARANDO OS DADOS
if col_data.dtype == object:
INICIALIZANDO MODELOS
clf_A = svm.SVC(random_state=42)
clf_B = tree.DecisionTreeClassifier(random_state=42)
clf_C = AdaBoostClassifier(tree.DecisionTreeClassifier(max_depth=1),
algorithm="SAMME",
n_estimators=300,random_state=42)
clf_D=KNeighborsClassifier(n_neighbors=3)
clf_E= GaussianNB()
clf_F=RandomForestClassifier(n_estimators=100,random_state=42)
clf_G=LogisticRegression(random_state=42)
INTERVENÇÃO DE ESTUDANTES
COMPARAÇÃO DE MODELOS
Logistic Regression Pros:
• Implementação eficiente
Logistic Regression Cons:
• Não é performático com muitas features
INTERVENÇÃO DE ESTUDANTES
COMPARAÇÃO DE MODELOS
Decision Trees Pros:
• Regras de decisão intuitivas
• Pode utilizar campos não lineares
Decision Trees Cons:
• Alto Bias [Random Forests pode ser a solução]
• Sem ranking score
INTERVENÇÃO DE ESTUDANTES
COMPARAÇÃO DE MODELOS
SVM Pros:
• Pode lidar com um grande número de features
SVM Cons:
• Não é performático em um dataset com um maior número de
linhas
INTERVENÇÃO DE ESTUDANTES
VERIFICANDO CORRELACIONAMENTO
PCA -REDUZINDO DIMENSÕES
GERANDO OS CLUSTERS
clusterer = KMeans(n_clusters=i,
random_state=29).fit(reduced_data)
preds = clusterer.predict(reduced_data)
SITES
ONDE
CONSEGUIR
INFORMAÇÃO
DESMISTIFICANDO A CIÊNCIA DE DADOS
HTTPS://ENSINANDOMAQUINASBLOG.WORDPRESS.COM
ONDE DESCOBRIR NOVAS INFORMAÇÕES
KAGGLE
RELATÓRIOS
RELATÓRIOS
▸ Notebooks online: iPython, Jupyter
▸ permitem a criação de
documentos
▸ ¨ Reproducible Research!
TESTE A/B
TESTE A/B
TESTE A/B
TESTE A/B
Teste A/B é um método de teste onde se comparam duas práticas, A e B,
em que estes são o controle e o tratamento de uma experiência
controlada, com o objetivo de melhorar a percentagem de aprovação.
LIVROS
Dúvidas:
naubergois@gmail.com