Numerical Functions Expr
Extension for General Numerical Features/Metrics/Quantities
Miscallaneous Numerical Functions and Transforms.
Functions:
| Name | Description |
|---|---|
add_at |
Creates a zero column of length |
arr_dot |
Calculates the dot product for two array columns. |
arr_l1_dist |
Calculates the L1 distance for two array columns. |
arr_sql2_dist |
Calculates the squared L2 distance for two array columns. |
center |
Centers the column. |
convolve |
Performs a convolution with the given kernel(filter). The current implementation's performance is worse |
detrend |
Detrends self using either linear/mean method. This does not persist. |
digamma |
The diagamma function. |
exp2 |
Returns 2^x. |
expit |
Applies the Expit function to self. Expit(x) = 1 / (1 + e^(-x)) |
fract |
Returns the fractional part of the input values. E.g. fractional part of 1.1 is 0.1 |
gamma |
Applies the gamma function to self. Note, this will return NaN for negative values and inf when x = 0, |
gcd |
Computes GCD of two integer columns. This will try to cast everything to int32. |
haversine |
Computes haversine distance using the naive method. The output unit is km. |
info_value |
Compute Information Value for x with respect to target. This assumes the variable x |
info_value_discrete |
Compute the Information Value for x with respect to target. This assumes x |
integrate_trapz |
Integrate y along x using the trapezoidal rule. If x is not a single |
is_decreasing |
Checks whether the column is monotonically decreasing. |
is_increasing |
Checks whether the column is monotonically increasing. |
isotonic_regression |
Performs isotonic regression on the data. This is the same as scipy.optimize.isotonic_regression. |
jaccard_col |
Computes jaccard similarity column-wise. This will hash entire columns and compares the two |
jaccard_row |
Computes jaccard similarity pairwise between |
l1_horizontal |
Horizontally computes L1 norm. Shorthand for pl.sum_horizontal(pl.col(x).abs() for x in exprs). |
l2_sq_horizontal |
Horizontally computes L2 norm squared. Shorthand for pl.sum_horizontal(pl.col(x).pow(2) for x in exprs). |
l_inf_horizontal |
Horizontally computes L inf norm. Shorthand for pl.max_horizontal(pl.col(x).abs() for x in exprs). |
lcm |
Computes LCM of two integer columns. This will try to cast everything to int32. |
list_amax |
Finds the argmax of the list in this column. This is useful for |
list_dot |
Calculates the dot product for two list columns. |
list_l1_dist |
Calculates the L1 distance for two list columns. |
list_sql2_dist |
Calculates the squared L2 distance for two list columns. |
logit |
Applies the logit function to self. Logit(x) = ln(x/(1-x)). |
next_down |
For any float, return the greatest number smaller than itself (within the precision). |
next_up |
For any float, return the least number greater than itself (within the precision). |
pca |
Finds all singular values as well as the principal vectors. |
principal_components |
Transforms the features to get the first k principal components. This returns NaN if the number |
psi |
Compute the Population Stability Index between x and the reference column (usually x's historical values). |
psi_discrete |
Compute the Population Stability Index between self (actual) and the reference column. The baseline |
psi_w_breakpoints |
Creates a PSI report using the custom breakpoints. |
rfft |
Computes the DFT transform of a real-valued input series using FFT Algorithm. Note that |
singular_values |
Finds all principal values (singular values) for the data matrix formed by the given features |
softmax |
Applies the softmax function to the column, which turns any real valued column into valid probability |
trunc |
Returns the integer part of the input values. E.g. integer part of 1.1 is 1.0 |
woe |
Compute the Weight of Evidence for x with respect to target. This assumes x |
woe_discrete |
Compute the Weight of Evidence for x with respect to target. This assumes x |
xlogy |
Computes x * log(y) so that if x = 0, the product is 0. |
z_normalize |
Z-normalizes the column. |
add_at(indices, values, buffer_size=None)
Creates a zero column of length buffer_size first. Then the j-th value in values
will be added to the j-th index in indices in the buffer. This is the equivalent to
NumPy's add.at.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indices
|
str | Expr
|
Expression or name of a column. Must be castable to u32. |
required |
values
|
str | Expr
|
Expression or name of a column. Must be castable to f64 and have the same length as the indices. |
required |
buffer_size
|
int | Expr | None
|
If this is None, buffer size will be inferred from unique values in indices, which should range from [0..n), where n is the actual buffer size. If this is an integer, then the buffer will have the exact size given here, which might cause out of bounds error if indices are not checked. If this is an expression, only the first element in the represented column will be used. |
None
|
Source code in python/polars_ds/exprs/num.py
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 | |
arr_dot(arr1, arr2)
Calculates the dot product for two array columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr1
|
str | Expr
|
The first array column |
required |
arr2
|
str | Expr
|
The second array column |
required |
Source code in python/polars_ds/exprs/num.py
128 129 130 131 132 133 134 135 136 137 138 139 140 | |
arr_l1_dist(arr1, arr2)
Calculates the L1 distance for two array columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr1
|
str | Expr
|
The first array column |
required |
arr2
|
str | Expr
|
The second array column |
required |
Source code in python/polars_ds/exprs/num.py
143 144 145 146 147 148 149 150 151 152 153 154 155 | |
arr_sql2_dist(arr1, arr2)
Calculates the squared L2 distance for two array columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr1
|
str | Expr
|
The first array column |
required |
arr2
|
str | Expr
|
The second array column |
required |
Source code in python/polars_ds/exprs/num.py
158 159 160 161 162 163 164 165 166 167 168 169 170 | |
center(x)
Centers the column.
This is only a short cut for a standard feature transform, and is not recommended to be used in settings where the means need to be persisted.
Source code in python/polars_ds/exprs/num.py
253 254 255 256 257 258 259 260 261 | |
convolve(x, kernel, fill_value=0.0, method='direct', mode='full', parallel=False)
Performs a convolution with the given kernel(filter). The current implementation's performance is worse than SciPy but offers parallelization within Polars.
For large kernels (usually kernel length > 120), convolving with FFT is faster, but for smaller kernels, convolving with direct method is faster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
str | Expr
|
A column of numbers |
required |
kernel
|
List[float] | ndarray | Series | Expr
|
The filter for the convolution. Anything that can be turned into a Polars Series will work. All non-finite values will be filtered out before the convolution. |
required |
fill_value
|
float | Expr
|
Fill null values in |
0.0
|
method
|
ConvMethod
|
Either |
'direct'
|
mode
|
ConvMode
|
Please check the reference. One of |
'full'
|
parallel
|
bool
|
Only applies when method is |
False
|
Reference
https://brianmcfee.net/dstbook-site/content/ch03-convolution/Modes.html https://en.wikipedia.org/wiki/Convolution
Source code in python/polars_ds/exprs/num.py
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 | |
detrend(x, method='linear')
Detrends self using either linear/mean method. This does not persist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
DetrendMethod
|
Either |
'linear'
|
Source code in python/polars_ds/exprs/num.py
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 | |
digamma(x)
The diagamma function.
Source code in python/polars_ds/exprs/num.py
1167 1168 1169 1170 1171 1172 1173 1174 1175 | |
exp2(x)
Returns 2^x.
Source code in python/polars_ds/exprs/num.py
961 962 963 964 965 966 967 968 969 | |
expit(x)
Applies the Expit function to self. Expit(x) = 1 / (1 + e^(-x))
Source code in python/polars_ds/exprs/num.py
938 939 940 941 942 943 944 945 946 | |
fract(x)
Returns the fractional part of the input values. E.g. fractional part of 1.1 is 0.1
Source code in python/polars_ds/exprs/num.py
972 973 974 975 976 977 978 979 980 | |
gamma(x)
Applies the gamma function to self. Note, this will return NaN for negative values and inf when x = 0, whereas SciPy's gamma function will return inf for all x <= 0.
Source code in python/polars_ds/exprs/num.py
926 927 928 929 930 931 932 933 934 935 | |
gcd(x, y)
Computes GCD of two integer columns. This will try to cast everything to int32.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
str | Expr
|
An integer column |
required |
y
|
int | str | Expr
|
Either an int, or another integer column |
required |
Source code in python/polars_ds/exprs/num.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
haversine(x_lat, x_long, y_lat, y_long)
Computes haversine distance using the naive method. The output unit is km.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_lat
|
str | Expr
|
Column representing latitude in x |
required |
x_long
|
str | Expr
|
Column representing longitude in x |
required |
y_lat
|
float | str | Expr
|
Column representing latitude in y |
required |
y_long
|
float | str | Expr
|
Column representing longitude in y |
required |
Source code in python/polars_ds/exprs/num.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
info_value(x, target, n_bins=10, return_sum=True)
Compute Information Value for x with respect to target. This assumes the variable x is continuous. A value of 1 is added to all events/non-events (goods/bads) to smooth the computation.
Currently only quantile binning strategy is implemented.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
str | Expr
|
The feature. Must be numeric. |
required |
target
|
str | expr | Iterable[float]
|
The target column. Should be 0s and 1s. |
required |
n_bins
|
int
|
The number of bins to bin x. |
10
|
return_sum
|
bool
|
If false, the output is a struct containing the ranges and the corresponding IVs. If true, it is the sum of the individual information values. |
True
|
Reference
https://www.listendata.com/2015/03/weight-of-evidence-woe-and-information.html
Source code in python/polars_ds/exprs/num.py
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 | |
info_value_discrete(x, target, return_sum=True)
Compute the Information Value for x with respect to target. This assumes x is discrete and castable to String. A value of 1 is added to all events/non-events (goods/bads) to smooth the computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
str | Expr
|
The feature. The column must be castable to String |
required |
target
|
str | Expr | Iterable[int]
|
The target variable. Should be 0s and 1s. |
required |
return_sum
|
bool
|
If false, the output is a struct containing the categories and the corresponding IVs. If true, it is the sum of the individual information values. |
True
|
Reference
https://www.listendata.com/2015/03/weight-of-evidence-woe-and-information.html
Source code in python/polars_ds/exprs/num.py
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 | |
integrate_trapz(y, x)
Integrate y along x using the trapezoidal rule. If x is not a single value, then x should be sorted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
str | Expr
|
A column of numbers |
required |
x
|
float | Expr
|
If it is a single float, it must be positive and it will represent a uniform distance between points. If it is an expression, it must be sorted, does not contain null, and have the same length as self. |
required |
Source code in python/polars_ds/exprs/num.py
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 | |
is_decreasing(x, strict=False)
Checks whether the column is monotonically decreasing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
str | Expr
|
A numerical column |
required |
strict
|
bool
|
Whether the check should be strict |
False
|
Source code in python/polars_ds/exprs/num.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
is_increasing(x, strict=False)
Checks whether the column is monotonically increasing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
str | Expr
|
A numerical column |
required |
strict
|
bool
|
Whether the check should be strict |
False
|
Source code in python/polars_ds/exprs/num.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
isotonic_regression(y, weights=None, increasing=True)
Performs isotonic regression on the data. This is the same as scipy.optimize.isotonic_regression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
str | Expr
|
The response variable |
required |
weights
|
str | Expr | None
|
The weights for the response |
None
|
increasing
|
bool
|
If true, output will be monotonically inreasing. If false, it will be monotonically decreasing. |
True
|
Source code in python/polars_ds/exprs/num.py
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 | |
jaccard_col(a, b, count_null=False)
Computes jaccard similarity column-wise. This will hash entire columns and compares the two hashsets. Note: only integer/str columns can be compared.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
str | Expr
|
A column with a hashable type |
required |
b
|
str | Expr
|
A column with a hashable type |
required |
count_null
|
bool
|
Whether to count null as a distinct element. |
False
|
Source code in python/polars_ds/exprs/num.py
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | |
jaccard_row(a, b)
Computes jaccard similarity pairwise between a and b column. The type of
each column must be list and the lists must have the same inner type. The inner type
must either be integer or string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
str | Expr
|
A list column with a hashable inner type |
required |
b
|
str | Expr
|
A list column with a hashable inner type |
required |
Source code in python/polars_ds/exprs/num.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
l1_horizontal(*v, normalize=False)
Horizontally computes L1 norm. Shorthand for pl.sum_horizontal(pl.col(x).abs() for x in exprs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*v
|
str | Expr
|
Expressions to compute horizontal L1. |
()
|
normalize
|
bool
|
Whether to divide by the dimension |
False
|
Source code in python/polars_ds/exprs/num.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
l2_sq_horizontal(*v, normalize=False)
Horizontally computes L2 norm squared. Shorthand for pl.sum_horizontal(pl.col(x).pow(2) for x in exprs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*v
|
str | Expr
|
Expressions to compute horizontal L2. |
()
|
normalize
|
bool
|
Whether to divide by the dimension |
False
|
Source code in python/polars_ds/exprs/num.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
l_inf_horizontal(*v, normalize=False)
Horizontally computes L inf norm. Shorthand for pl.max_horizontal(pl.col(x).abs() for x in exprs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*v
|
str | Expr
|
Expressions to compute horizontal L infinity. |
()
|
normalize
|
bool
|
Whether to divide by the dimension |
False
|
Source code in python/polars_ds/exprs/num.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
lcm(x, y)
Computes LCM of two integer columns. This will try to cast everything to int32.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
str | Expr
|
An integer column |
required |
y
|
int | str | Expr
|
Either an int, or another integer column |
required |
Source code in python/polars_ds/exprs/num.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
list_amax(list_col)
Finds the argmax of the list in this column. This is useful for
(1) Turning sparse multiclass target into dense target. (2) Finding the max probability class of a multiclass classification output. (3) As a shortcut for expr.list.eval(pl.element().arg_max()).
Source code in python/polars_ds/exprs/num.py
915 916 917 918 919 920 921 922 923 | |
list_dot(list1, list2)
Calculates the dot product for two list columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list1
|
str | Expr
|
The first array column |
required |
list2
|
str | Expr
|
The second array column |
required |
Source code in python/polars_ds/exprs/num.py
173 174 175 176 177 178 179 180 181 182 183 184 185 | |
list_l1_dist(list1, list2)
Calculates the L1 distance for two list columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list1
|
str | Expr
|
The first array column |
required |
list2
|
str | Expr
|
The second array column |
required |
Source code in python/polars_ds/exprs/num.py
188 189 190 191 192 193 194 195 196 197 198 199 200 | |
list_sql2_dist(list1, list2)
Calculates the squared L2 distance for two list columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list1
|
str | Expr
|
The first array column |
required |
list2
|
str | Expr
|
The second array column |
required |
Source code in python/polars_ds/exprs/num.py
203 204 205 206 207 208 209 210 211 212 213 214 215 | |
logit(x)
Applies the logit function to self. Logit(x) = ln(x/(1-x)). Note that logit(0) = -inf, logit(1) = inf, and logit(p) for p < 0 or p > 1 yields nan.
Source code in python/polars_ds/exprs/num.py
949 950 951 952 953 954 955 956 957 958 | |
next_down(x)
For any float, return the greatest number smaller than itself (within the precision). Intergers will be treated as f32. E.g. The next value down for 0.1 is 0.09999999999999999. This is useful when you need to make extremely small changes to certain values and you don't want to add random noise.
Source code in python/polars_ds/exprs/num.py
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 | |
next_up(x)
For any float, return the least number greater than itself (within the precision). Intergers will be treated as f32. E.g. The next value up for 0.1 is 0.10000000000000002 because of precision issues. This is useful when you need to make extremely small changes to certain values and you don't want to add random noise.
Source code in python/polars_ds/exprs/num.py
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 | |
pca(*features, center=True)
Finds all singular values as well as the principal vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
str | Expr
|
Feature columns |
()
|
center
|
bool
|
Whether to center the data or not. If you want to standard normalize, set this to False, and do it for input features by hand. |
True
|
Source code in python/polars_ds/exprs/num.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
principal_components(*features, k=2, center=True)
Transforms the features to get the first k principal components. This returns NaN if the number
of rows is less than k.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
str | Expr
|
Feature columns |
()
|
k
|
int
|
The number of principal components to return |
2
|
center
|
bool
|
Whether to center the data or not. If you want to standard normalize, set this to False, and do it for input features by hand. |
True
|
Source code in python/polars_ds/exprs/num.py
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
psi(new, baseline, n_bins=10, return_report=False)
Compute the Population Stability Index between x and the reference column (usually x's historical values). The reference column will be divided into n_bins quantile bins which will be used as basis of comparison.
Note this assumes values in self and ref are continuous. This will also remove all infinite, null, NA. values.
Also note that it will try to create n_bins many unique breakpoints. If input data has < n_bins
unique breakpoints, the repeated breakpoints will be grouped together, and the computation will be done
with < n_bins many bins. This happens when a single value appears too many times in data. This also
differs from the reference implementation by treating breakpoints as right-closed intervals with -inf
and inf being the first and last values of the intervals. This is because we need to accommodate all data
in the case when actual data's min and the reference data's min are not the same, which is common in reality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new
|
str | Expr | Iterable[float]
|
An expression or any iterable that can be turned into a Polars series that represents newly arrived feature values |
required |
baseline
|
str | Expr | Iterable[float]
|
An expression or any iterable that can be turned into a Polars series. Usually this should be the feature's historical values |
required |
n_bins
|
int, > 1
|
The number of quantile bins to use |
10
|
return_report
|
bool
|
Whether to return a PSI report or not. |
False
|
Reference
https://github.com/mwburke/population-stability-index/blob/master/psi.py https://www.listendata.com/2015/05/population-stability-index.html
Source code in python/polars_ds/exprs/num.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 | |
psi_discrete(new, baseline, return_report=False)
Compute the Population Stability Index between self (actual) and the reference column. The baseline column will be used as categories which are the basis of comparison.
Note this assumes values in new and ref baseline discrete columns (e.g. str categories). This will treat each value as a distinct category and null will be treated as a category by itself. If a category exists in new but not in baseline, the percentage will be imputed by 0.0001. If you do not wish to include new distinct values in PSI calculation, you can still compute the PSI by generating the report and filtering.
Also note that discrete columns must have the same type in order to be considered the same.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new
|
str | Expr | Iterable[float]
|
The feature |
required |
baseline
|
str | Expr | Iterable[float]
|
An expression, or any iterable that can be turned into a Polars series. Usually this should be the historical values |
required |
return_report
|
bool
|
Whether to return a PSI report or not. |
False
|
Reference
https://www.listendata.com/2015/05/population-stability-index.html
Source code in python/polars_ds/exprs/num.py
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 | |
psi_w_breakpoints(new, baseline, breakpoints)
Creates a PSI report using the custom breakpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new
|
str | expr | Iterable[float]
|
The data representing the new observed data. Any sequence of numerical values that can be turned into a Polars'series, or an expression representing a column will work |
required |
baseline
|
str | expr | Iterable[float]
|
The data representing the baseline data. Any sequence of numerical values that can be turned into a Polars'series, or an expression representing a column will work |
required |
breakpoints
|
List[float]
|
The data that represents breakpoints. Input must be sorted, distinct, finite numeric values. This function will not cleanse the breakpoints for the user. E.g. [0.1, 0.5, 0.9] will create four bins: (-inf. 0.1], (0.1, 0.5], (0.5, 0.9] and (0.9, inf). Please do not pass inf or NaN values as breakpoints. |
required |
Source code in python/polars_ds/exprs/num.py
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 | |
rfft(series, n=None, return_full=False)
Computes the DFT transform of a real-valued input series using FFT Algorithm. Note that by default a series of length (length // 2 + 1) will be returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
series
|
str | Expr
|
Input real series |
required |
n
|
int | None
|
The number of points to use. If n is smaller than the length of the input, the input is cropped. If it is larger, the input is padded with zeros. If n is not given, the length of the input is used. |
None
|
return_full
|
bool
|
If true, output will have the same length as determined by n. |
False
|
Source code in python/polars_ds/exprs/num.py
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 | |
sinc(x)
Computes the sinc function normalized by pi.
Source code in python/polars_ds/exprs/num.py
994 995 996 997 998 999 1000 | |
singular_values(*features, center=True, as_explained_var=False, as_ratio=False)
Finds all principal values (singular values) for the data matrix formed by the given features and returns them in descending order.
Note: if a row has null values, it will be dropped.
Paramters
features Feature columns center Whether to center the data or not. If you want to standard-normalize, set this to False, and do it for input features by hand. as_explained_var If true, return the explained variance, which is singular_value ^ 2 / (n_samples - 1) as_ratio If true, normalize output to between 0 and 1.
Source code in python/polars_ds/exprs/num.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
softmax(x)
Applies the softmax function to the column, which turns any real valued column into valid probability values. This is simply a shorthand for x.exp() / x.exp().sum() for expressions x.
Paramters
x Either a str represeting a column name or a Polars expression
Source code in python/polars_ds/exprs/num.py
277 278 279 280 281 282 283 284 285 286 287 288 | |
target_encode(s, target, min_samples_leaf=20, smoothing=10.0)
Compute information necessary to target encode a string column.
Note: nulls will be encoded as well.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str | Expr
|
The string column to encode |
required |
target
|
str | Expr | Iterable[int]
|
The target column. Should be 0s and 1s. |
required |
min_samples_leaf
|
int
|
A regularization factor |
20
|
smoothing
|
float
|
Smoothing effect to balance categorical average vs prior |
10.0
|
Reference
https://contrib.scikit-learn.org/category_encoders/targetencoder.html
Source code in python/polars_ds/exprs/num.py
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 | |
trunc(x)
Returns the integer part of the input values. E.g. integer part of 1.1 is 1.0
Source code in python/polars_ds/exprs/num.py
983 984 985 986 987 988 989 990 991 | |
woe(x, target, n_bins=10)
Compute the Weight of Evidence for x with respect to target. This assumes x is continuous. A value of 1 is added to all events/non-events (goods/bads) to smooth the computation.
Currently only quantile binning strategy is implemented.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
str | Expr
|
The feature |
required |
target
|
str | expr | Iterable[float]
|
The target variable. Should be 0s and 1s. |
required |
n_bins
|
int
|
The number of bins to bin the variable. |
10
|
Reference
https://www.listendata.com/2015/03/weight-of-evidence-woe-and-information.html
Source code in python/polars_ds/exprs/num.py
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 | |
woe_discrete(x, target)
Compute the Weight of Evidence for x with respect to target. This assumes x is discrete and castable to String. A value of 1 is added to all events/non-events (goods/bads) to smooth the computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
str | Expr
|
The feature |
required |
target
|
str | Expr | Iterable[int]
|
The target variable. Should be 0s and 1s. |
required |
Reference
https://www.listendata.com/2015/03/weight-of-evidence-woe-and-information.html
Source code in python/polars_ds/exprs/num.py
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 | |
xlogy(x, y)
Computes x * log(y) so that if x = 0, the product is 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
str | Expr
|
A numerical column |
required |
y
|
str | Expr
|
A numerical column |
required |
Source code in python/polars_ds/exprs/num.py
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 | |
z_normalize(x)
Z-normalizes the column.
This is only a short cut for a standard feature transform, and is not recommended to be used in settings where the means/stds need to be persisted.
Source code in python/polars_ds/exprs/num.py
264 265 266 267 268 269 270 271 272 273 274 | |