<jupyter_start><jupyter_text>Splines<jupyter_code>import matplotlib.pyplot as plt
from scipy.interpolate import UnivariateSpline
rng = np.random.default_rng()
x = np.linspace(-3, 3, 50)
y = np.exp(-x**2) + 0.1 * rng.standard_normal(50)
plt.plot(x, y, 'ro', ms=5)
spl = UnivariateSpline(x, y)
xs = np.linspace(-3, 3, 1000)
plt.plot(xs, spl(xs), 'g', lw=3)
spl.set_smoothing_factor(0.5)
plt.plot(xs, spl(xs), 'b', lw=3)
plt.show()
#np.random.choice(a, 100)

import numpy as np
import statsmodels.api as sm

lowess = sm.nonparametric.lowess
b1 = np.array([-0.4, 0.4, 0.4, 0.6, 1. , 1. , 1. , 1. ])
b2 = np.array([-1, 0.4, 0.4, 0.6, 0.9, 0.9, 0.9, 0.9])
lowess(b1, a)

np.trapz(b, a)
from statsmodels.nonparametric.kernel_regression import KernelReg

a = np.array([0 , 0. , 0.2, 0.2, 0.2, 0.4, 0.8, 1. ])

b = np.array([0 , 0.4, 0.4, 0.6, 1. , 1. , 1. , 1. ])

fig = plt.figure(figsize=(6,6))
ax = fig.gca()
ax.set_xticks(np.arange(0, 1.1, 0.2))
ax.set_yticks(np.arange(0, 1.1, 0.2))
plt.plot(a,b, marker='D', label = 'Original data')

kr = KernelReg(b,a,'c')
#plt.plot(x, y, '+')
y_pred, y_std = kr.fit(a)

plt.plot(a, y_pred, label = 'Kernel regression')
plt.plot(lowess(b1, a)[:,0], lowess(b1, a)[:,1], label = 'Lowess regression')

plt.legend()
plt.xlabel('False positive rate')
plt.ylabel('True positive rate')

plt.grid()
plt.show()
a = 0; b = 1; n = 100

S = []

for i in range(1, len(tpr) + 1):
#for i in range(0, len(tpr)):
    if i < len(tpr):
        try:
            d_x = (tpr[i] - tpr[i-1])/(len(tpr) + 1)
            x_i = a + i*d_x
            s = d_x * sin(x_i)
        except:
            s = 1
    print(d_x)
    print(x_i)
   

    S = S + [s]

sum(S)


#tpr = tpr[::-1]
#fpr = fpr[::-1]

#tpr
#j
import numpy as np
fpr = np.array([0, 0, 0.2, 0.2, 0.2, 0.4, 0.8, 1])
tpr = np.array([0, 0.4, 0.4, 0.6, 1, 1, 1, 1])

print(np.trapz(tpr, fpr))
def riemann_sum(f,a,b,N,method='midpoint'):
    '''Compute the Riemann sum of f(x) over the interval [a,b].

    Parameters
    ----------
    f : function
        Vectorized function of one variable
    a , b : numbers
        Endpoints of the interval [a,b]
    N : integer
        Number of subintervals of equal length in the partition of [a,b]
    method : string
        Determines the kind of Riemann sum:
        right : Riemann sum using right endpoints
        left : Riemann sum using left endpoints
        midpoint (default) : Riemann sum using midpoints

    Returns
    -------
    float
        Approximation of the integral given by the Riemann sum.
    '''
    dx = (b - a)/N
    x = np.linspace(a,b,N+1)

    if method == 'left':
        x_left = x[:-1]
        return np.sum(f(x_left)*dx)
    elif method == 'right':
        x_right = x[1:]
        return np.sum(f(x_right)*dx)
    elif method == 'midpoint':
        x_mid = (x[:-1] + x[1:])/2
        return np.sum(f(x_mid)*dx)
    else:
        raise ValueError("Method must be 'left', 'right' or 'midpoint'.")

riemann_sum(np.exp, 0,1,len(tpr),'left')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.187977416140817, 'fraction_numerical': 0.04583194951843241, 'mean_word_length': 2.6731707317073172, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '316572', 'license': 'MIT', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1298, 'n_words': 325, 'path': 'docs/pages/roc_analysis/roc-auc.ipynb', 'repo_name': 'aysuvorov/clinstats', 'size': '3011'}