minor fixes
This commit is contained in:
parent
46b5ed42c7
commit
d61d82c919
36
charts.R
36
charts.R
@ -1,12 +1,19 @@
|
||||
library(highcharter)
|
||||
library(tidyr)
|
||||
library(plotly)
|
||||
library(dplyr)
|
||||
basedf<-read.csv("dev/matma_bayes/heart.csv", header = TRUE)
|
||||
siha<-read.csv('dev/matma_bayes/sex_if_heart_attack.csv')
|
||||
df2<-read.csv('dev/matma_bayes/age_sex_heart_attack.csv')
|
||||
chol<-read.csv('dev/matma_bayes/chol_sex_heart_attack.csv')
|
||||
basedf$sex[basedf$sex==1]<-'Man'
|
||||
basedf$sex[basedf$sex==0]<-'Woman'
|
||||
df2$sex[df2$sex==1]<-'Man'
|
||||
df2$sex[df2$sex==0]<-'Woman'
|
||||
chol$sex[chol$sex==1]<-'Man'
|
||||
chol$sex[chol$sex==0]<-'Woman'
|
||||
df2$x<-paste(df2$sex,df2$age)
|
||||
df2$comb<-
|
||||
|
||||
|
||||
basedf%>%
|
||||
count(sex)%>% arrange(n)%>%
|
||||
@ -15,16 +22,10 @@ basedf%>%
|
||||
|
||||
|
||||
siha%>%
|
||||
hchart(type = "pie", hcaes(x=sex, y = Probability, color = Probability, name='Probability')) %>%
|
||||
hchart(type = "pie", hcaes(x=sex, y = Probability, color = Probability), name='Probability') %>%
|
||||
hc_title(text="<b>Sex if heart attack</b>")
|
||||
|
||||
basedf%>%
|
||||
group_by(sex, chol)%>%
|
||||
count()%>%
|
||||
hchart('area', hcaes(x='chol', y='n', group='sex'))%>%
|
||||
hc_xAxis(title=list(text='Cholesterol'))%>%
|
||||
hc_yAxis(title=list(text='Quantity'))%>%
|
||||
hc_title(text="<b>Number of terrorists attacks in each year by region</b>")
|
||||
|
||||
|
||||
|
||||
df2%>%
|
||||
@ -34,3 +35,20 @@ df2%>%
|
||||
hc_yAxis(title=list(text='Probability'))%>%
|
||||
hc_legend(enabled=F)%>%
|
||||
hc_title(text="<b>Probability of heart attack for sex and age group</b>")
|
||||
|
||||
|
||||
chol %>%
|
||||
drop_na(heart.attack)%>%
|
||||
plot_ly(x = ~heart.attack,
|
||||
y = ~sex,
|
||||
type = 'bar',
|
||||
orientation = 'h',
|
||||
color = ~chol,
|
||||
colors ='Spectral',
|
||||
hoverinfo = 'text',
|
||||
text = ~paste('Probability:', heart.attack, '<br> Interval:', chol),
|
||||
xaxis=list(categoryorder='total descending')) %>%
|
||||
layout(title = 'Chol/probability',
|
||||
xaxis = list(title = "Probability"),
|
||||
yaxis = list(title = "Cholesterol"))
|
||||
|
||||
|
31
chol_sex_heart_attack.csv
Normal file
31
chol_sex_heart_attack.csv
Normal file
@ -0,0 +1,31 @@
|
||||
chol,sex,heart attack,no heart attack
|
||||
"[120, 150]",0,0.7900763358778626,0.20992366412213742
|
||||
"[120, 150]",1,0.5057933317569164,0.4942066682430835
|
||||
"[150, 180]",0,0.7150259067357513,0.28497409326424866
|
||||
"[150, 180]",1,0.40557451649601817,0.5944254835039818
|
||||
"[180, 210]",0,0.8168701442841287,0.18312985571587126
|
||||
"[180, 210]",1,0.5481189641089703,0.4518810358910296
|
||||
"[210, 240]",0,0.7900763358778626,0.2099236641221374
|
||||
"[210, 240]",1,0.5057933317569164,0.4942066682430835
|
||||
"[240, 270]",0,0.7594186538732892,0.2405813461267109
|
||||
"[240, 270]",1,0.46189495365602473,0.5381050463439754
|
||||
"[270, 300]",0,0.5654082528533801,0.43459174714661986
|
||||
"[270, 300]",1,0.26132942377673635,0.7386705762232636
|
||||
"[300, 330]",0,0.7553882996920972,0.24461170030790286
|
||||
"[300, 330]",1,0.45644780538550794,0.5435521946144921
|
||||
"[330, 360]",0,0.5564516129032259,0.4435483870967742
|
||||
"[330, 360]",1,0.2543703175169461,0.745629682483054
|
||||
"[360, 390]",0,1.0,0.0
|
||||
"[360, 390]",1,1.0,0.0
|
||||
"[390, 420]",0,0.7150259067357513,0.2849740932642487
|
||||
"[390, 420]",1,0.4055745164960181,0.5944254835039817
|
||||
"[420, 450]",0,nan,nan
|
||||
"[420, 450]",1,nan,nan
|
||||
"[450, 480]",0,nan,nan
|
||||
"[450, 480]",1,nan,nan
|
||||
"[480, 510]",0,nan,nan
|
||||
"[480, 510]",1,nan,nan
|
||||
"[510, 540]",0,nan,nan
|
||||
"[510, 540]",1,nan,nan
|
||||
"[540, 570]",0,1.0,0.0
|
||||
"[540, 570]",1,1.0,0.0
|
|
91
first.py
Normal file
91
first.py
Normal file
@ -0,0 +1,91 @@
|
||||
import pandas as pd
|
||||
|
||||
|
||||
# P(B|A)*P(A)
|
||||
#P(A|B)=-----------
|
||||
# P(B)
|
||||
|
||||
|
||||
data=pd.read_csv('heart.csv')
|
||||
|
||||
print(data)
|
||||
|
||||
men=0
|
||||
for i in range(len(data['sex'])):
|
||||
if data['sex'][i] ==1:
|
||||
men+=1
|
||||
print(men)
|
||||
p_men=men/len(data)
|
||||
print("Prawdopodobieństwo, że mężczyzna",p_men)
|
||||
|
||||
chol=0
|
||||
for i in range(len(data['chol'])):
|
||||
if data['chol'][i] >200:
|
||||
chol+=1
|
||||
print(chol)
|
||||
p_chol=chol/len(data)
|
||||
print("Prawdopodobieństwo, że cholesterol większy niż 200",p_chol)
|
||||
|
||||
age_over_50=0
|
||||
for i in range(len(data['age'])):
|
||||
if data['age'][i] >50:
|
||||
age_over_50+=1
|
||||
print(age_over_50)
|
||||
p_age_over_50=age_over_50/len(data)
|
||||
print("Prawdopodobieństwo, że wiek powyżej 50",p_age_over_50)
|
||||
|
||||
sugar=0
|
||||
for i in range(len(data['fbs'])):
|
||||
if data['fbs'][i] ==1:
|
||||
sugar+=1
|
||||
print(sugar)
|
||||
p_sugar=sugar/len(data)
|
||||
print("Prawdopodobieństwo, że wysoki cukier",p_sugar)
|
||||
|
||||
heart_attack=0
|
||||
for i in range(len(data['target'])):
|
||||
if data['target'][i] ==1:
|
||||
heart_attack+=1
|
||||
print(heart_attack)
|
||||
p_heart_attack=heart_attack/len(data)
|
||||
print("Prawdopodobieństwo dużego ryzyka zawału serca",p_heart_attack) #P(class)
|
||||
|
||||
man_if_heart_attack=0
|
||||
for i in range(len(data['target'])):
|
||||
if data['target'][i] ==1:
|
||||
if data['sex'][i]==1:
|
||||
man_if_heart_attack+=1
|
||||
print(man_if_heart_attack)
|
||||
p_man_if_heart_attack=man_if_heart_attack/len(data)
|
||||
p_man_if_heart_attack=p_man_if_heart_attack/p_heart_attack
|
||||
print("rawdopodobieństwo, że mężczyzna jeśli wystąpił zawał serca",p_man_if_heart_attack)
|
||||
|
||||
over50_if_heart_attack=0
|
||||
for i in range(len(data['target'])):
|
||||
if data['target'][i] ==1:
|
||||
if data['age'][i]>50:
|
||||
over50_if_heart_attack+=1
|
||||
print(over50_if_heart_attack)
|
||||
p_over50_if_heart_attack=over50_if_heart_attack/len(data)
|
||||
p_over50_if_heart_attack=p_over50_if_heart_attack/p_heart_attack
|
||||
print("Prawdopodobieństwo, że powyżej 50 lat jeżeli wystąpił zawał serca",p_over50_if_heart_attack)
|
||||
|
||||
chol_over200_if_heart_attack=0
|
||||
for i in range(len(data['target'])):
|
||||
if data['target'][i] ==1:
|
||||
if data['chol'][i]>200:
|
||||
chol_over200_if_heart_attack+=1
|
||||
print(chol_over200_if_heart_attack)
|
||||
p_chol_over200_if_heart_attack=chol_over200_if_heart_attack/len(data)
|
||||
p_chol_over200_if_heart_attack=p_chol_over200_if_heart_attack/p_heart_attack
|
||||
print("Prawdopodobieństwo, że cholestorol powyżej 200, jezeli wystąpił zawał serca",p_chol_over200_if_heart_attack)
|
||||
|
||||
sugar_if_heart_attack=0
|
||||
for i in range(len(data['target'])):
|
||||
if data['target'][i] ==1:
|
||||
if data['fbs'][i]==1:
|
||||
sugar_if_heart_attack+=1
|
||||
print(sugar_if_heart_attack)
|
||||
p_sugar_if_heart_attack=sugar_if_heart_attack/len(data)
|
||||
p_sugar_if_heart_attack=p_sugar_if_heart_attack/p_heart_attack
|
||||
print("Prawdopodbieństwo, że był wysoki poziom cukru jeżeli wystąpił zawał serca",p_sugar_if_heart_attack)
|
Loading…
Reference in New Issue
Block a user