Untitled 4
Untitled 4
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
import warnings
warnings.filterwarnings("ignore")
from scipy.stats import ttest_ind, ttest_rel
from scipy import stats
import data
data = pd.read_csv("https://gitlab.com/andreass.bayu/file-
directory/-/raw/main/adult.csv")
data.head(10)
Age
i. distribusi
data['age'].hist(figsize=(8,8))
plt.show()
ii. deskripsi
data[data["age"]>70].shape
(868, 15)
Income
i. distribusi
plt.figure(figsize=(7,7))
total = float(len(data) )
ax = sns.countplot(x="income", data=data)
for p in ax.patches:
height = p.get_height()
ax.text(p.get_x()+p.get_width()/2.,
height + 3,
'{:1.2f}'.format((height/total)*100),
ha="center")
plt.show()
income age
1 >50K 44.275178
0 <=50K 36.872184
income_1 = data[data['income']=='<=50K']['age']
income_0 = data[data['income']=='>50K']['age']
income_0 = income_0.values.tolist()
income_0 = random.sample(income_0, 100)
income_1 = income_1.values.tolist()
income_1 = random.sample(income_1, 100)
if pval <0.05:
print("null hypothesis ditolak")
else:
print("null hypothesis diterima")
ttest -3.690070133020414
p value 0.00029878818647073786
null hypothesis ditolak
Income
i. Distribusi
plt.figure(figsize=(7,7))
total = float(len(data) )
ax = sns.countplot(x="income", data=data)
for p in ax.patches:
height = p.get_height()
ax.text(p.get_x()+p.get_width()/2.,
height + 3,
'{:1.2f}'.format((height/total)*100),
ha="center")
plt.show()
ii. deskripsi
# Berdasarkan diagram diatas tidak seimbang, sekitar 23,96% masuk ke
dalam kelompok pendapatan lebih dari 50.000 dolar dan sekitar 76%
masuk ke dalam kelompok pendapatan kurang ari 50.000 dolar.
Bivariate analysis
fig = plt.figure(figsize=(10,10))
sns.boxplot(x="income", y="hours-per-week", data=data)
plt.show()
ii. deskripsi
# Rata - rata usia untuk kelompok kurang dari 50.000 dolar adalah 36,8
tahun dengan median 34 dan untuk kelompok diatas 50.000 dolar adalah
44,2 tahun dengan median 42.