This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def mySqrt(self, x: int) -> int: | |
| high = x | |
| low = 0 | |
| while low <= high: | |
| mid = low + (high-low)//2 | |
| if mid * mid == x: | |
| return mid | |
| if mid * mid < x and (mid+1)*(mid+1) > x: | |
| return mid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # estimate sample size via power analysis | |
| # We will use the statsmodels library to calculate the sample size. | |
| from statsmodels.stats.power import TTestIndPower | |
| # define parameters | |
| effectsize = 0.1 | |
| alpha = 0.05 | |
| power = 0.8 | |
| # Statistical Power calculations for t-test for two independent sample | |
| model = TTestIndPower() | |
| samplesize = model.solve_power(effectsize, power=power, nobs1=None, ratio=1.0, alpha=alpha) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| from wordcloud import WordCloud | |
| import urllib3 | |
| import re | |
| urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | |
| artist = input('Input artist name (default = Michael Jackson): ') or "Michael Jackson" | |
| song = input('Input song name (default = Bad): ') or "Bad" | |
| artist = artist.replace(' ','%2520') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| from scipy.stats import norm | |
| X_plot = np.linspace(130, 210, 1000)[:, np.newaxis] | |
| mu1 = 178 | |
| mu2 = 163 | |
| sigma1 = 7.7 | |
| sigma2 = 7.3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| import imageio | |
| from scipy.stats import norm | |
| def plot_for_offset(mu1, y_max): | |
| X_plot = np.linspace(-2, 12, 1000)[:, np.newaxis] | |
| mu2 = 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import scipy.stats | |
| from random import uniform | |
| p = scipy.stats.norm(0,1) | |
| n = 50000 | |
| int_val = [0]*n | |
| mean_val = [0]*n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import scipy.stats | |
| f_x = scipy.stats.randint(1,7) | |
| def g_x(x): | |
| return (7-x)/10/2.1 | |
| E_g = np.dot(np.linspace(1,6,6),g_x(np.linspace(1,6,6))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| z = scipy.stats.norm.ppf(1-(1-0.95)/2) | |
| print(f'Z-score for 95% confidence interval = {z:0.3f}') | |
| moe = z*std_err | |
| print (f'Margin of error={moe:.3f}') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| max_x_mean = np.mean(max_x) | |
| std_err = np.std(max_x)/n**0.5 | |
| conf_int = np.percentile(max_x, [2.5,97.5]) | |
| print (f'mean of theta = {max_x_mean:.4f}') | |
| print (f'Standard error of theta = {std_err:.4f}') | |
| print (f'95% Confidence interval of theta = {conf_int}') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| max_x = [] | |
| for iter in range(1000): | |
| sample = rv.rvs(n) | |
| n1 = sum(sample == 0) | |
| n2 = n - n1 | |
| x = np.linspace(0,1,100) | |
| L = x**n2 * (1-x)**n1 | |
| curr_max_x = scipy.optimize.fmin(lambda x: -(x**n2 * (1-x)**n1), 0, disp=False) | |
| max_x.append(curr_max_x[0]) |
NewerOlder