Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def spearman_similar_correlation(self, column,
correlation_lower_bound,
pvalue_threshold=0.05,
num_rounds=3):
correlation_info = stats.spearmanr(self.new_data[column],
self.historical_data[column])
p_value = permutation_test(
self.new_data[column],
self.historical_data[column],
method="approximate",
num_rounds=num_rounds,
func=lambda x, y: stats.spearmanr(x, y).correlation,
seed=0)
if p_value > pvalue_threshold:
return False
if correlation_info.correlation < correlation_lower_bound:
return False
return True
def mann_whitney_u_similar_distribution(self, column,
pvalue_threshold=0.05,
num_rounds=3):
p_value = permutation_test(
self.new_data[column],
self.historical_data[column],
method="approximate",
num_rounds=num_rounds,
func=lambda x, y: stats.mannwhitneyu(x, y).statistic,
seed=0)
if p_value < pvalue_threshold:
return False
return True
def kruskal_similar_distribution(self, column,
pvalue_threshold=0.05,
num_rounds=3):
p_value = permutation_test(
self.new_data[column],
self.historical_data[column],
method="approximate",
num_rounds=num_rounds,
func=lambda x, y: stats.kruskal(x, y).statistic,
seed=0)
if p_value < pvalue_threshold:
return False
return True
def test_predict_2():
X = np.array([[1], [2], [3]])
est = _BaseEstimator(print_progress=0, random_seed=1)
est.fit(X)
est.predict(X)
def test_init():
est = _BaseEstimator(print_progress=0, random_seed=1)
assert hasattr(est, 'print_progress')
assert hasattr(est, 'random_seed')
def test_multivariate_gradient_descent():
gd_lr = LinearRegression(eta=0.001, epochs=500, solver='gd', random_seed=0)
gd_lr.fit(X_rm_lstat_std, y_std)
assert_almost_equal(gd_lr.w_, expect_rm_lstat_std, decimal=3)
def test_univariate_stochastic_gradient_descent():
sgd_lr = LinearRegression(solver='sgd', eta=0.0001, epochs=100, random_seed=0)
sgd_lr.fit(X_rm_std, y_std)
assert_almost_equal(sgd_lr.w_, expect_rm_std, decimal=2)
def test_univariate_normal_equation_std():
ne_lr = LinearRegression(solver='normal_equation')
ne_lr.fit(X_rm_std, y_std)
assert_almost_equal(ne_lr.w_, expect_rm_std, decimal=3)
def test_multivariate_normal_equation():
ne_lr = LinearRegression(solver='normal_equation')
ne_lr.fit(X_rm_lstat, y)
assert_almost_equal(ne_lr.w_, expect_rm_lstat, decimal=3)
def test_multivariate_stochastic_gradient_descent():
sgd_lr = LinearRegression(eta=0.0001, epochs=500, solver='sgd', random_seed=0)
sgd_lr.fit(X_rm_lstat_std, y_std)
assert_almost_equal(sgd_lr.w_, expect_rm_lstat_std, decimal=2)