-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwalkthrough.qmd
136 lines (88 loc) · 2.64 KB
/
walkthrough.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---
title: "Quarto Sample"
format: html
---
## Markdown
Quarto has the same feel and function as an RMarkdown (but it can also run Python and bash!)
- It's _plain text_ so works well with version control
- It can be **rendered** into HTML, PDF, and more
- Learn more at: <https://quarto.org/docs/authoring/>
## Quarto Running Python Code Cells
```{python}
import os
os.cpu_count()
```
## Equation
Use LaTeX to write equations:
$$
\chi' = \sum_{i=1}^n k_i s_i^2
$$
Here is a logistic regression example
```{python}
import numpy as np
import matplotlib.pyplot as plt
def sig(x):
return 1/(1 + np.exp(-x))
x = np.linspace(-10, 10, 50)
print(x)
p = sig(x)
plt.xlabel("x")
plt.ylabel("Sigmoid(x)")
plt.plot(x, p)
plt.show()
```
## Using What the Previous Exercise Created
Let's plot what we have in target_subset.csv
We need pandas, numpy, and matplotlib to be installed.
```{python}
import pandas
import numpy as np
import matplotlib.pyplot as plt
sample_compound_df = pandas.read_csv('./target_subset.csv')
x = sample_compound_df['Compound_Concentration']
y = sample_compound_df['Counts']
# calculate polynomial
z = np.polyfit(x, y, 2)
f = np.poly1d(z)
# calculate new x's and y's
x_new = np.linspace(min(x), max(x), 1000)
y_new = f(x_new)
plt.plot(x, y, 'o', label='data')
plt.plot(x_new, y_new, label='fit')
plt.legend(loc='best')
# plt.legend()
plt.show()
```
Let's plot every compound within df_for_tutorial.csv
```{python}
import pandas
import numpy as np
from matplotlib import pyplot as plt
sample_compound_df = pandas.read_csv('./df_for_tutorial.csv')
# Get all available compound IDs within 'Compound_ID' column
col_names = sample_compound_df['Compound_ID'].unique()
# We don't want 'BG' or 'NEG'
col_names = col_names[2:]
# For creating these plots we'd have to loop
for comp_id in col_names:
df_subset_for_plot = sample_compound_df[sample_compound_df['Compound_ID'] == comp_id]
df_subset_for_plot = df_subset_for_plot[df_subset_for_plot['Compound_Concentration'].notna()]
if df_subset_for_plot.empty:
next
else:
print(df_subset_for_plot.head())
filename_to_use = comp_id + '_scatter_with_fit.png'
x = df_subset_for_plot['Compound_Concentration']
y = df_subset_for_plot['Counts']
# calculate polynomial
# z = np.polyfit(x, y, 2)
# f = np.poly1d(z)
# calculate new x's and y's
# x_new = np.linspace(min(x), max(x), 1000)
# y_new = f(x_new)
plt.plot(x, y, 'o', label=comp_id)
# plt.plot(x_new, y_new, label='fit')
plt.legend()
plt.savefig(filename_to_use)
plt.close()
```