<jupyter_start><jupyter_text>Baseline Subtraction and Area under the Curve import the libraries<jupyter_code>import numpy
import peakutils
from scipy.integrate import trapz
from peakutils.plot import plot as pplot
from matplotlib import pyplot
from sklearn import metrics
%matplotlib inline<jupyter_output><empty_output><jupyter_text>generat the plots and curves<jupyter_code>centers = (30.5, 72.3)
x = numpy.linspace(0, 120, 121)
y = (peakutils.gaussian(x, 5, centers[0], 3) +
peakutils.gaussian(x, 7, centers[1], 10) +
numpy.random.rand(x.size))
y2 = y + numpy.polyval([0.002,-0.08,5], x)
pyplot.figure(figsize=(10,6))
pyplot.plot(x, y2)
pyplot.title("Data with baseline")<jupyter_output><empty_output><jupyter_text>evaluate the baseline using `peakutils.baseline()`<jupyter_code>baseline_values = peakutils.baseline(y2)
pyplot.figure(figsize=(10,6))
pyplot.plot(x, y2,x,baseline_values);<jupyter_output><empty_output><jupyter_text>subtract the baseline from y-values<jupyter_code>y3 = y2 - baseline_values
pyplot.figure(figsize=(10,6))
pyplot.plot(x, y3);
pyplot.grid()<jupyter_output><empty_output><jupyter_text>Now use `sklearn` and ` trapz()` to calculate the area under the whole curve.<jupyter_code>metrics.auc(x,y3)
trapz(y3,x)<jupyter_output><empty_output><jupyter_text>Next step is to calculate the area under one curve. Find out the limits of the peak<jupyter_code>pyplot.figure(figsize=(5,5))
pyplot.plot(x[20:40], y3[20:40],'r-',x,y3,'.');
pyplot.grid()
metrics.auc()<jupyter_output><empty_output><jupyter_text>calculate the area under the curve with `scipy` with syntax `trapz(y, x)`<jupyter_code>trapz(y3[20:40],x[20:40])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14037192561487702, 'fraction_numerical': 0.04019196160767846, 'mean_word_length': 8.75438596491228, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '267758', 'license': 'MIT', 'n_tokens_mistral': 688, 'n_tokens_neox': 648, 'n_words': 125, 'path': 'Baseline_and_Area_und_the_Curve.ipynb', 'repo_name': 'fawadkarimi/JupyterNotebooks2', 'size': '1667'}