SlideShare a Scribd company logo
R Glass Analysis - Data Analysis Project
Andrea Ciccotta
Introduzione
R Glass Analysis è un progetto di analisi dei dati: il suo scopo è quello di analizzare diversi campioni di vetro
(disponibili nel package "Glass" di R Studio), costruendo così un algoritmo capace di classificare i vetri a
partire dai loro elementi chimici.
1_GlassAnalysis - kmeans, lda, tree
Inizialmente esploro il dataset e ottengo le informazioni generali dei vetri:
RI Na Mg Al Si K
Min. :1.511 Min. :10.73 Min. :0.000 Min. :0.290 Min. :69.81 Min. :0.0000
1st Qu.:1.517 1st Qu.:12.91 1st Qu.:2.115 1st Qu.:1.190 1st Qu.:72.28 1st Qu.:0.1225
Median :1.518 Median :13.30 Median :3.480 Median :1.360 Median :72.79 Median :0.5550
Mean :1.518 Mean :13.41 Mean :2.685 Mean :1.445 Mean :72.65 Mean :0.4971
3rd Qu.:1.519 3rd Qu.:13.82 3rd Qu.:3.600 3rd Qu.:1.630 3rd Qu.:73.09 3rd Qu.:0.6100
Max. :1.534 Max. :17.38 Max. :4.490 Max. :3.500 Max. :75.41 Max. :6.2100
Ca Ba Fe
Min. : 5.430 Min. :0.000 Min. :0.00000
1st Qu.: 8.240 1st Qu.:0.000 1st Qu.:0.00000
Median : 8.600 Median :0.000 Median :0.00000
Mean : 8.957 Mean :0.175 Mean :0.05701
3rd Qu.: 9.172 3rd Qu.:0.000 3rd Qu.:0.10000
Max. :16.190 Max. :3.150 Max. :0.51000
Provo con un primo plot a capire quali elementi sono più o meno presenti nei vari vetri ("dividendo il plot in
2" per maggior chiarezza):
In realtà questo non sembra tornare molto utile, provo quindi con un boxplot:
Ecco la prima informazione utile: il silicio è un elemento dominante!
Un altra informazione utile è sicuramente la correlazione tra gli elementi e la loro tipologia nota, utilizzo
quindi rispettivamente i metodi di Pearson e Spearman:
Pearson)
RI -0.1642372146
Na 0.5028980423
Mg -0.7449928875
Al 0.5988292084
Si 0.1515652579
K -0.0100544638
Ca 0.0009522246
Ba 0.5751614590
Fe -0.1882775640
Spearman)
RI -0.21293648
Na 0.39868242
Mg -0.58985414
Al 0.56014833
Si 0.14932051
K -0.23564177
Ca 0.05288838
Ba 0.50686917
Fe -0.15018589
Vedo quindi come si addensano i cluster del dataset tra gli elementi che hanno maggiormente attirato la mia
attenzione:
Scelgo quindi i miei criteri per la classificazione, saranno
A1 = RI * Na values ; A2 = Mg * Al values
R1 = Si * K values ; R2 = Ca * Ba values
Con questi criteri voglio classificare i vetri, tramite i discriminanti di
fisher (provo a distinguere le prime tre tipologie, sarà analogo per gli
altri).
Matrici di confusione ottenute:
Utilizzando A1 e A2 per distinugere Type1 e Type2:
analisi_p 1 2
1 25 15
2 45 61
Utilizzando A1 e A2 per distinugere Type2 e Type3:
analisi_p 2 3
2 76 17
3 0 0
Utilizzando A1 e A2 per distinugere Type1 e Type3:
analisi_p 1 2 3
1 70 0 17
2 0 0 0
3 0 0 0
//Analogo per R1 e R2
Ecco quindi l'albero decisionale ottenuto:
2_GlassAnalysis - Bayes Naive
Un esempio intuitivo di Bayes Naive è il seguente:
P(Maschio/capelliCorti) = [P(capelliCorti/M) * P(M)] / [P(capelliCorti)]
Posso quindi di certo ragionare nei seguenti termini:
P(Type==1/Mg==4.49) = [P(Mg==4.49/Type==1) * P(Type==1)] / [P(Mg==4.49)]
--->
P(Type==1/Mg~=4.49) = [P(Mg~=4.49/Type==1) * P(Type==1)] / [P(Mg~=4.49)]
P(Type==1) ---> totType1 / totRecord
P(Mg~=4.49) = [N°record( Mg > 4.4 ) U N°record( Mg < 4.6 )] / [N°Tot_record]
Voglio quindi creare un classificatore basato sull'elemento Mg, utilizzando la tecnica Bayes Naive.
[...] Lanciando l'esperimento si può notare come il risultato sia pessimo, dobbiamo
cambiare tecnica!
3_GlassAnalysis - MAP
Studiando i miei dati ho notato come alcune colonne abbiano un'alta differenza in termini di varianza e di
differenza tra gli estremi sup e inf.
Voglio settare manualmente un algoritmo che considerando gli intervalli degli
elementi che maggiormente "godono di questa proprietà", creando così un
classificatore che ragioni nel seguente modo:
"Ha il Magnesio nullo e il Calcio alto? Allora è sicuramente un vetro di tipo X !"
[...]
Scelti quindi gli intervalli ottengo un classificatore stupido poichè soffre
SICURAMENTE di overfitting!
Decido così di aggiungere ai miei intervalli un offset che verrà settato
tramite tecniche di Machine Learning per risolvere il problema dell'overfitting e ottenere un classificatore
migliore.
Lanciando in esecuzione lo script con un basso numero di iterazioni (150) ecco un primissimo risultato:
per type1 classificati 95 su 70
per type2 classificati 59 su 76
per type3 classificati 15 su 17
per type5 classificati 15 su 13
per type6 classificati 7 su 9
per type7 classificati 23 su 29
-0.26 0.92 0.33 0.39
per type1 classificati 77 su 70
per type2 classificati 71 su 76
per type3 classificati 20 su 17
per type5 classificati 16 su 13
per type6 classificati 8 su 9
per type7 classificati 22 su 29
-0.09 0.27 0.24 -0.02
per type1 classificati 79 su 70
per type2 classificati 72 su 76
per type3 classificati 17 su 17
per type5 classificati 16 su 13
per type6 classificati 8 su 9
per type7 classificati 22 su 29
-0.3 0.49 0.17 0.02
per type1 classificati 75 su 70
per type2 classificati 74 su 76
per type3 classificati 19 su 17
per type5 classificati 16 su 13
per type6 classificati 8 su 9
per type7 classificati 22 su 29
-0.21 0.23 0.32 -0.06
per type1 classificati 69 su 70
per type2 classificati 76 su 76
per type3 classificati 23 su 17
per type5 classificati 16 su 13
per type6 classificati 8 su 9
per type7 classificati 22 su 29
-0.82 0.3 0.13 0.06
Notiamo come il classificatore migliori i suoi offset (ultima riga - in questo caso 4) fino ad
aumentare il numero di HIT e abbassare quindi il numero di MISS.
Un caso interessante è come in realtà andiamo a ritroso per il type3, che è davvero
difficile da classificare poichè i vetri di type3 non presentano caratteristiche particolari!
Conclusioni
I discriminanti di Fisher e il mio classificatore MAP costruito con una tecnica di
Machine Learning semi-supervisionata hanno dato risultati soddisfacenti già con un basso numero di
parametri e di iterazioni.
Tutt'altra storia per l'approccio Bayes Naive a cui avevamo dato una sola informazione
disponibile.
Contatto dello sviluppatore:
ciccottandrea@gmail.com

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

R Glass Analysis

  • 1. R Glass Analysis - Data Analysis Project Andrea Ciccotta Introduzione R Glass Analysis è un progetto di analisi dei dati: il suo scopo è quello di analizzare diversi campioni di vetro (disponibili nel package "Glass" di R Studio), costruendo così un algoritmo capace di classificare i vetri a partire dai loro elementi chimici. 1_GlassAnalysis - kmeans, lda, tree Inizialmente esploro il dataset e ottengo le informazioni generali dei vetri: RI Na Mg Al Si K Min. :1.511 Min. :10.73 Min. :0.000 Min. :0.290 Min. :69.81 Min. :0.0000 1st Qu.:1.517 1st Qu.:12.91 1st Qu.:2.115 1st Qu.:1.190 1st Qu.:72.28 1st Qu.:0.1225 Median :1.518 Median :13.30 Median :3.480 Median :1.360 Median :72.79 Median :0.5550 Mean :1.518 Mean :13.41 Mean :2.685 Mean :1.445 Mean :72.65 Mean :0.4971 3rd Qu.:1.519 3rd Qu.:13.82 3rd Qu.:3.600 3rd Qu.:1.630 3rd Qu.:73.09 3rd Qu.:0.6100 Max. :1.534 Max. :17.38 Max. :4.490 Max. :3.500 Max. :75.41 Max. :6.2100 Ca Ba Fe Min. : 5.430 Min. :0.000 Min. :0.00000 1st Qu.: 8.240 1st Qu.:0.000 1st Qu.:0.00000 Median : 8.600 Median :0.000 Median :0.00000 Mean : 8.957 Mean :0.175 Mean :0.05701 3rd Qu.: 9.172 3rd Qu.:0.000 3rd Qu.:0.10000 Max. :16.190 Max. :3.150 Max. :0.51000
  • 2. Provo con un primo plot a capire quali elementi sono più o meno presenti nei vari vetri ("dividendo il plot in 2" per maggior chiarezza):
  • 3.
  • 4. In realtà questo non sembra tornare molto utile, provo quindi con un boxplot: Ecco la prima informazione utile: il silicio è un elemento dominante! Un altra informazione utile è sicuramente la correlazione tra gli elementi e la loro tipologia nota, utilizzo quindi rispettivamente i metodi di Pearson e Spearman: Pearson) RI -0.1642372146 Na 0.5028980423 Mg -0.7449928875 Al 0.5988292084 Si 0.1515652579 K -0.0100544638 Ca 0.0009522246 Ba 0.5751614590 Fe -0.1882775640 Spearman) RI -0.21293648 Na 0.39868242 Mg -0.58985414 Al 0.56014833 Si 0.14932051 K -0.23564177 Ca 0.05288838 Ba 0.50686917 Fe -0.15018589
  • 5. Vedo quindi come si addensano i cluster del dataset tra gli elementi che hanno maggiormente attirato la mia attenzione: Scelgo quindi i miei criteri per la classificazione, saranno A1 = RI * Na values ; A2 = Mg * Al values R1 = Si * K values ; R2 = Ca * Ba values Con questi criteri voglio classificare i vetri, tramite i discriminanti di fisher (provo a distinguere le prime tre tipologie, sarà analogo per gli altri). Matrici di confusione ottenute: Utilizzando A1 e A2 per distinugere Type1 e Type2: analisi_p 1 2 1 25 15 2 45 61 Utilizzando A1 e A2 per distinugere Type2 e Type3: analisi_p 2 3 2 76 17 3 0 0 Utilizzando A1 e A2 per distinugere Type1 e Type3: analisi_p 1 2 3 1 70 0 17 2 0 0 0 3 0 0 0 //Analogo per R1 e R2
  • 6. Ecco quindi l'albero decisionale ottenuto: 2_GlassAnalysis - Bayes Naive Un esempio intuitivo di Bayes Naive è il seguente: P(Maschio/capelliCorti) = [P(capelliCorti/M) * P(M)] / [P(capelliCorti)] Posso quindi di certo ragionare nei seguenti termini: P(Type==1/Mg==4.49) = [P(Mg==4.49/Type==1) * P(Type==1)] / [P(Mg==4.49)] ---> P(Type==1/Mg~=4.49) = [P(Mg~=4.49/Type==1) * P(Type==1)] / [P(Mg~=4.49)] P(Type==1) ---> totType1 / totRecord P(Mg~=4.49) = [N°record( Mg > 4.4 ) U N°record( Mg < 4.6 )] / [N°Tot_record] Voglio quindi creare un classificatore basato sull'elemento Mg, utilizzando la tecnica Bayes Naive. [...] Lanciando l'esperimento si può notare come il risultato sia pessimo, dobbiamo cambiare tecnica!
  • 7. 3_GlassAnalysis - MAP Studiando i miei dati ho notato come alcune colonne abbiano un'alta differenza in termini di varianza e di differenza tra gli estremi sup e inf. Voglio settare manualmente un algoritmo che considerando gli intervalli degli elementi che maggiormente "godono di questa proprietà", creando così un classificatore che ragioni nel seguente modo: "Ha il Magnesio nullo e il Calcio alto? Allora è sicuramente un vetro di tipo X !" [...] Scelti quindi gli intervalli ottengo un classificatore stupido poichè soffre SICURAMENTE di overfitting! Decido così di aggiungere ai miei intervalli un offset che verrà settato tramite tecniche di Machine Learning per risolvere il problema dell'overfitting e ottenere un classificatore migliore. Lanciando in esecuzione lo script con un basso numero di iterazioni (150) ecco un primissimo risultato: per type1 classificati 95 su 70 per type2 classificati 59 su 76 per type3 classificati 15 su 17 per type5 classificati 15 su 13 per type6 classificati 7 su 9 per type7 classificati 23 su 29 -0.26 0.92 0.33 0.39 per type1 classificati 77 su 70 per type2 classificati 71 su 76 per type3 classificati 20 su 17 per type5 classificati 16 su 13 per type6 classificati 8 su 9 per type7 classificati 22 su 29 -0.09 0.27 0.24 -0.02 per type1 classificati 79 su 70 per type2 classificati 72 su 76 per type3 classificati 17 su 17 per type5 classificati 16 su 13 per type6 classificati 8 su 9 per type7 classificati 22 su 29 -0.3 0.49 0.17 0.02 per type1 classificati 75 su 70 per type2 classificati 74 su 76 per type3 classificati 19 su 17 per type5 classificati 16 su 13 per type6 classificati 8 su 9 per type7 classificati 22 su 29 -0.21 0.23 0.32 -0.06 per type1 classificati 69 su 70 per type2 classificati 76 su 76 per type3 classificati 23 su 17 per type5 classificati 16 su 13 per type6 classificati 8 su 9 per type7 classificati 22 su 29 -0.82 0.3 0.13 0.06 Notiamo come il classificatore migliori i suoi offset (ultima riga - in questo caso 4) fino ad aumentare il numero di HIT e abbassare quindi il numero di MISS.
  • 8. Un caso interessante è come in realtà andiamo a ritroso per il type3, che è davvero difficile da classificare poichè i vetri di type3 non presentano caratteristiche particolari! Conclusioni I discriminanti di Fisher e il mio classificatore MAP costruito con una tecnica di Machine Learning semi-supervisionata hanno dato risultati soddisfacenti già con un basso numero di parametri e di iterazioni. Tutt'altra storia per l'approccio Bayes Naive a cui avevamo dato una sola informazione disponibile. Contatto dello sviluppatore: ciccottandrea@gmail.com