Docsity

Exercícios de data science, Exercícios de Armazém de Dados

Toggle sidebar
bg1
Data$Science$
2024/2025&
Exam&
Date: January 20th, 2025
Duration: 1.75 hours
Student ID: _________ Name:_____________________________________________________________
Rules:
- Start the exam within 30 minutes of the starting time. Withdrawals are allowed only 1 hour after the
starting time.
- No consultation, but a calculator is allowed.
- Deliver just this sheet, with your identification and answers inside the grid.
- Pick the truth value for each statement and fill it in the grid below.
- Each correct answer counts 0.4 points and each wrong one -0.1 points.
Solution(
Data
Profiling
Classification
II
T
F
T
F
T
F
T
F
T
F
1
X
X
X
X
X
2
X
X
X
X
X
3
X
X
X
X
X
4
X
X
X
X
X
5
X
X
X
X
X
Pattern
Mining
Forecasting
I
T
F
T
F
T
F
T
F
T
F
1
X
X
X
X
X
2
X
X
X
X
X
3
X
X
X
X
X
4
X
X
X
X
X
5
X
X
X
X
X
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Pré-visualização parcial do texto

Baixe Exercícios de data science e outras Exercícios em PDF para Armazém de Dados, somente na Docsity!

Data Science

Exam

Date: January 20 th, 20 25

Duration: 1.75 hours

Student ID: _________ Name:_____________________________________________________________

Rules:

  • Start the exam within 30 minutes of the starting time. Withdrawals are allowed only 1 hour after the starting time.
  • No consultation, but a calculator is allowed.
  • Deliver just this sheet, with your identification and answers inside the grid.
  • Pick the truth value for each statement and fill it in the grid below.
  • Each correct answer counts 0.4 points and each wrong one - 0. 1 points.

Solution

Data

Profiling

Data

Preparation

Classification

I

Classification

II

Ethics

T F T F T F T F T F

1 X X X X X

2 X X X X X

3 X X X X X

4 X X X X X

5 X X X X X

Pattern

Mining

Clustering

Anomaly

Detection

Forecasting

I

Forecasting

II

T F T F T F T F T F

1 X X X X X

2 X X X X X

3 X X X X X

4 X X X X X

5 X X X X X

Data Science

Data Description

Consider a dataset collected to help on identifying people in need of some social support. Each record

represents a person, described by 14 variables , where income was used as the target variable for a

classification task. As usual, the names of the variables express their semantics. The dataset contains around

32.5 thousand records, with 24% of people with income larger than 50K dollars ( Yes value).

Figure 1 - Profiling for symbolic non-binary variables

Figure 3 – Income distribution Figure 4 – Variables with missing values Figure 5 – Heatmap for multidimensional analysis after variable encoding

Figure 6 – Scatterplots for multidimensional analysis after variable encoding

Naïve Bayes, Decision Trees and KNN

Figure 8 Accuracy for different specializations of decision trees (left) and KNN (right) over train and test datasets Figure 9 Performance for NB and different parameterizations of DT and KNN (max_depth and K, respectively)

Random Forests and Gradient Boosting

Figure 10 RF (left) and GB (right) performances with different parameterizations (percentage of features and learning rate, respectively)

Clustering

Consider a sample from the previous multivariate dataset after scaling, with around 1400 records, now only

described by variables age and fnlwgt.

Figure 12 Clustering results obtained with a first clustering algorithm p 1 =a, p 2 =z p 1 =a, p 2 =y p 1 =b, p 2 =z p 1 =b, p 2 =y Figure 13 Clustering results obtained with a second clustering algorithm with different values for two parameters

Anomaly Detection

Consider the sample used for clustering, taken from the multivariate dataset after scaling, with around 1400

records, again only described by variables age and fnlwgt.

Figure 14 LOF results over a sample with around

A

B

z

Figure 19 Cost matrix between s1=[1.5, 1.6, 1.8, 2.0, 1.9] and s2=[1.5, 1.6, 1.9, 2.0, 1.7, 1.8, 2.4]

Statements A. Data Profiling

  1. The variable education-num can be discarded without risking losing information.
  2. It is possible to state that education is the second most discriminative variable regarding the class.
  3. We may state with confidence that age variable expresses approximate values.
  4. The presence of outliers seems to be one of the major problems of this dataset.
  5. The scatterplot presents valuable insights to the classification task, but not for a clustering one B. Data preparation
  6. Dummification would be mandatory to encode some of the symbolic variables.
  7. Removing one of the variables education or education-num, should improve the performance of KNN.
  8. Eliminating missing values would reduce the data at most in 1843 records.
  9. Dummifying native_country variable would increase the number of correlated variables.
  10. An ordinal encoding of variable race would be inadmissible. C. Classification I
  11. The accuracy for the presented tree is higher than 75%.
  12. The recall for the presented tree is higher than its precision.
  13. The Decision Tree presented classifies (A, not B) as positive.
  14. Consider the binarized dataset just described by A and B , where A= True órelationship≤ 3 .5 and B= True óeducation≤ 1 1.5. It is possible to state that to classify (A, not B), the KNN algorithm with K= would only have to look at the two leaves at the tree's center.
  15. Consider the binarized dataset just described by A and B , where A= True órelationship≤ 3 .5 and B= True óeducation≤ 1 1.5. It is possible to state that the Naive Bayes algorithm classifies (A, not B) with a large margin between the classes (larger than 20ppc). D. Classification II
  16. Knowing that identifying people in need is a priority, recall is a more adequate metric than accuracy in this classification task.
  17. Decision trees’ overfitting, in this case, is due to the increase of false positives.
  18. Decision trees and KNN show similar behaviors in terms of overfitting.
  19. The low performance of several Random Forests models is due to a lack of diversity, and the same is true for Gradient Boosting.
  20. The performance of MLP models was the expected one. E. Ethical Concerns
  21. The GDPR protects the dataset described but not the AI law.
  22. According to GDPR, some data in the described dataset is prohibited.
  23. Most of the described models do not meet the transparency requirement imposed by AI law but may meet the data protection principle with the same name.
  24. According to AI law, any trained models shown would be considered a limited risk.
  25. According to AI law, any trained models shown could be used without human supervision.

Resolution

B5 – False: there are no data preparation inadmissible techniques unless they lose considerable

amounts of information that can be avoided using other techniques

D2 – True : it is possible to see that when the accuracy decreases, precision also declines, even

harder. Since precision is smaller for higher values of FP, the increased number of FP is a reason

for the reduction of accuracy.

E1 – True : AI Law does not apply to datasets but to AI systems.

Classifiers evaluation:

TP = 973

TN= 4877 + 209 + 2180 = 7266

FP= 360

FN=247+111+1043= 1401

Acc=( 973 + 7266 )/ 10000 = 8239/10000 = 82%

Recall= 7266 /( 7266 + 1401 ) = 7266 / 8667 = 84 %

Precision= 7266 /( 7266 + 360 ) = 7266/7626 = 95 %

KNN

For K= 3543 , we need to look at the three last leaves, since the objects on the second and fourth one are at

the same distance.

Naïve Bayes

P(Yes)= 2374 / 10000 = 24 %

P(Neg)=7626 / 10000 =76%

P(A|Yes)= 358 / 2374 = 15 %

P(A|No)= 5086/7626 = 67%

P(not B|Yes)= P(not B|AYes) + P(not B|not AYes)= 111/358 + 973/2016 = 0.31 + 0.48 = 79%

P(not B|No)= P(not B|ANo) + P(not B|notANo) = 209/5086 + 360/2540 = 0.04 + 0.14 = 18%

NB = argmax(P(Yes)P(A|Yes)P(B|Yes), P(No)P(A|No)P(B|No))

=argmax(. 24 x. 15 x. 79 ,. 76 x. 67 x. 18 ) = argmax(. 03 ,. 09 ) =No

9%-3% = 6ppc < 20ppc

PM

  1. sup(A notB)=320/10000 = 3% < 10%
  2. minimum confidence was not specified so we can’t say anything about the association rules found.
  3. sup(A) = 5444 / 10000 = 54 % cnf(AànotB) = P(A notB)/P(A) = 320/5444 = 6%
  4. Knowing that (B, race=White) is not frequent, is enough to state that (A, B, race=White) is not frequent, according to the anti-monotonocity property.
  5. lift(AànotB)= sup(A notB) / (sup(A) x sup(notB)) = cnf(AànotB)/sup(notB)=.06/.165=0. sup(notB)=P(notB|A)+P(notB|notA) = (320 + 1333)/10000 = 1653/10000 =.

Clustering

Kmeans: K=2, K= 7

DBSCAN: p1=dist, p2=nr; a=0.22, b=0. 57 ; z=2, y= 10

Anomaly Detection

LOF: nr = 5 (left); nr= 5 0 (right)

Forecasting