# Python

You can run python code here! See bellow for Lean Six Sigma Examples. Copy a paste the code to the Python window bellow.

### Binomial Test

A car manufacturer claims that no more than 10% of their cars are unsafe. 15 cars are inspected for safety, 3 were found to be unsafe. Test the manufacturer’s claim:

``````from scipy import stats

b = stats.binom_test(3 , n=15, p=0.1, alternative='greater')

print(b)``````

### One-sample T-Test

https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.ttest_1samp.html#scipy.stats.ttest_1samp

The literature says that men of a fictional tribe of the Eagles have an average height of 175 cm.

The anthropologist that visited the tribe measured ten men selected by random these were the heights measured.

Based on the measured sample, decide if the literature is right or not.

``````from scipy import stats

eagles = [153, 156, 156, 167, 166, 167, 168, 174, 175, 181]

p = stats.ttest_1samp(eagles,175)

print(p)
``````

### Sign Test

Bank of America West Palm Beach, FL branch manager indicates
that the median number of savings account customers per day is 64.
A clerk from the same branch claims that it was more than 64.
Clerk collected the number of savings account customers per day data for 10 random days.
Can we reject the branch manager’s claim at 95% significance level?

``````from scipy import stats

customer = [60,66,65,70,68,72,46,76,77,75]

expectedmedian = 64

lower=0

for i in customer:
if i<expectedmedian:
lower = lower + 1

signtest = stats.binom_test(lower , n=len(customer), p=0.5, alternative='less')

print(signtest)``````

### Two-Sample T-Test

https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.ttest_ind.html

The literature says that men of a fictional tribe of the Eagles have the same average height as the fictional tribe of the Bulls.
The researcher measured 10 random men from each tribe and want to conclude that height of tribes is the same, on 95% level of significance (alpha = 5%) Is it the same?

``````from scipy import stats

eagles = [153, 156, 156, 161, 166, 167, 168, 174, 175, 181]
bulls = [160, 165, 168, 170, 171, 174, 176, 181, 181, 183]

p = stats.ttest_ind(eagles,bulls)

print(p)
``````

### Correlation test

https://docs.scipy.org/doc/scipy/reference/stats.html

An HR manager wants to understand the perception of the hiring process among new hires. They ran a survey rating where 0 = awful 20 = wonderful experience. The manager want to see if the rating is correlated with the numbers of days to hire.

``````from scipy import stats

daystohire = [38,32,41,48,47,50,27,39,47,33,36,30]
satisfaction = [9,15,13,12,7,4,15,9,7,16,7,11]

k = stats.pearsonr(daystohire,satisfaction)
print(k)``````

### Histogram

Draws a histogram from data.

``````import numpy as np
import matplotlib.pyplot as plt

sample = [40,42,45,42,46,47,50,44,46.5,43.1,43,46,43.5,44,48,44.5,44,45,41,46,41,47.7,44,45,43.2,42,44,45,45,44]

plt.hist(sample, density=False,bins=10)
plt.show()``````