Skip to content

Instantly share code, notes, and snippets.

View grahamharrison68's full-sized avatar

Graham Harrison grahamharrison68

  • Lincoln College
View GitHub Profile
def normal_distribution_ci(confidence, x_bar, sigma, n):
z_score = stats.norm.interval(confidence)[1]
sigma_over_root_n = sigma / np.sqrt(n)
ci = [x_bar - z_score * sigma_over_root_n, x_bar + z_score * sigma_over_root_n]
return ci
def binomial_distribution_ci(confidence, p_hat, n):
z_score = stats.norm.interval(confidence)[1]
rhs = z_score * np.sqrt(p_hat*(1-p_hat))/n
ci = [p_hat - rhs, p_hat + rhs]
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
import scipy.stats as stats
import numpy as np
import pandas as pd
pd.set_option("max_colwidth", 150)
df_wine_balanced['label'].value_counts(normalize=True)
red_wines = df_merged_wine[df_merged_wine['label'] == 1]
all_white_wines = df_merged_wine[df_merged_wine['label'] == 0]
white_wines = all_white_wines.sample(n=red_wines.shape[0], random_state=24)
df_wine_balanced = pd.concat([red_wines, white_wines])
df_wine_balanced
df_merged_wine['label'].value_counts(normalize=True)
import pandas as pd
import numpy as np
import graphviz
import pydotplus
import matplotlib.image as mpimg
import io
import random
from matplotlib import pyplot as plt
from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor
import pandas as pd
import numpy as np
import graphviz
import pydotplus
import matplotlib.image as mpimg
import io
import random
from matplotlib import pyplot as plt
from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor
# %% Remove the outliers and re-display the box-and-whisker and the histogram
df_normal = remove_all_outliers(df_normal, 'Col0')
box_and_whisker(df_normal, 'Col0')
df_normal['Col0'].hist()
box_and_whisker(df_normal, 'Col0')
# %% Add some outliers and re-plot
s[600] = 6
s[700] = 6.5
s[800] = 6.57
s[900] = 6.8
df_normal = pd.DataFrame({'Col0': s})
df_normal['Col0'].hist()