Skip to content

Commit ee80d5b

Browse files
authored
Merge pull request #29 from tusharrworkk-lab/readme-examples
Add recipe-style usage examples to the README
2 parents 39561ae + df32623 commit ee80d5b

1 file changed

Lines changed: 113 additions & 0 deletions

File tree

README.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,119 @@ One import, one line. A clean, sorted DataFrame you can read or feed into the ne
8181

8282
## Examples
8383

84+
These are short, recipe-style examples that go beyond the one-liner above and are intentionally not covered in the [documentation](https://data-centt.github.io/percentify/documentation/). The docs show each function in isolation; these show how to chain them into a real workflow.
85+
86+
### A 30-second data-quality gate
87+
88+
Drop this into CI to block training on a dataset that isn't ready:
89+
90+
```python
91+
import pandas as pd
92+
from percentify import profiler
93+
94+
df = pd.read_parquet("train.parquet")
95+
report = profiler(df, target="label")
96+
97+
assert report.errors.empty, report.to_frame()
98+
assert report.health >= 80, f"health too low: {report.health}"
99+
```
100+
101+
### Rank correlations by significance
102+
103+
Pull the pairs that are both strong *and* unlikely to be noise:
104+
105+
```python
106+
import pandas as pd
107+
from percentify import correlate
108+
109+
df = pd.DataFrame({
110+
"x": range(50),
111+
"y": [v * 0.9 + (v % 3) for v in range(50)],
112+
"z": [v * 0.05 for v in range(50)],
113+
"w": [v % 7 for v in range(50)],
114+
})
115+
116+
print(correlate(df).sort_values("p_value").head(5))
117+
```
118+
119+
### Build a transform pipeline from `skew_report`
120+
121+
Let `skew_report` tell you what to apply, then apply it:
122+
123+
```python
124+
import numpy as np
125+
import pandas as pd
126+
from percentify import skew_report
127+
128+
df = pd.DataFrame({
129+
"income": [30_000, 35_000, 1_200_000, 40_000, 28_000],
130+
"visits": [1, 1, 1, 50, 2],
131+
})
132+
133+
plan = skew_report(df)
134+
print(plan[["feature", "skew", "suggested_transform"]])
135+
# feature skew suggested_transform
136+
# 0 income 2.27 log1p
137+
# 1 visits 2.19 log1p
138+
139+
df["income_log"] = np.log1p(df["income"]) # numpy / pandas, not percentify
140+
df["visits_log"] = np.log1p(df["visits"])
141+
```
142+
143+
### Interpret PCA with both calls
144+
145+
Variance tells you *how much* of the signal each axis carries; loadings tell you *what it means*:
146+
147+
```python
148+
import pandas as pd
149+
from percentify import pca_variance, pca_loadings
150+
151+
df = pd.DataFrame({
152+
"height_cm": [160, 170, 180, 175, 165],
153+
"weight_kg": [55, 68, 82, 74, 60],
154+
"age": [25, 35, 45, 30, 28],
155+
})
156+
157+
print(pca_variance(df)) # PC1 carries most of the variance
158+
print(pca_loadings(df)) # PC1 = (height, weight) with similar signs
159+
```
160+
161+
### Drop collinear columns before modelling
162+
163+
Use `vif` with a threshold to get a drop-list you can feed straight into `df.drop`:
164+
165+
```python
166+
import pandas as pd
167+
from percentify import vif
168+
169+
df = pd.DataFrame({
170+
"price": [10, 12, 11, 13, 9, 14, 8, 12],
171+
"cost": [ 6, 7, 7, 8, 5, 8, 4, 7], # tracks price
172+
"margin": [ 4, 5, 4, 5, 4, 6, 4, 5], # = price - cost
173+
"stock": [100, 80, 90, 70, 110, 60, 120, 85],
174+
})
175+
176+
to_drop = vif(df, flag=5.0)["feature"].tolist()
177+
print(to_drop) # e.g. ['cost', 'margin']
178+
clean = df.drop(columns=to_drop)
179+
```
180+
181+
### Month-over-month KPI table
182+
183+
`change` over a DataFrame applies period-over-period growth to every numeric column at once:
184+
185+
```python
186+
import pandas as pd
187+
from percentify import change
188+
189+
kpis = pd.DataFrame({
190+
"revenue": [100, 120, 150, 135, 180],
191+
"signups": [400, 420, 470, 460, 510],
192+
}, index=["Jan", "Feb", "Mar", "Apr", "May"])
193+
194+
print(change(kpis))
195+
```
196+
84197
- [Worked examples for every function](https://data-centt.github.io/percentify/documentation/)
85198
- [Project documentation](https://data-centt.github.io/percentify/)
86199

0 commit comments

Comments
 (0)