ref: exlude notebooks from stats

This commit is contained in:
Anton Nesterov 2024-09-29 16:32:23 +02:00
parent f8cde668cd
commit 868bf08a07
No known key found for this signature in database
GPG key ID: 59121E8AE2851FB5
5 changed files with 18 additions and 13 deletions

4
.gitattributes vendored Normal file
View file

@ -0,0 +1,4 @@
notebooks/* linguist-vendored
lib/* linguist-vendored
Makefile linguist-vendored
*.json linguist-vendored

View file

@ -1,9 +1,10 @@
// deno-lint-ignore-file no-explicit-any
import pl from "npm:nodejs-polars"; import pl from "npm:nodejs-polars";
export function oneHotEncoding(dataframe: pl.DataFrame): pl.DataFrame { export function oneHotEncoding(dataframe: pl.DataFrame): pl.DataFrame {
let df = pl.DataFrame(); let df = pl.DataFrame();
for (const columnName of dataframe.columns) { for (const columnName of dataframe.columns) {
const column = dataframe[columnName]; const column = (dataframe as any)[columnName];
if (!column.isNumeric()) { if (!column.isNumeric()) {
df = df.hstack(column.toDummies()); df = df.hstack(column.toDummies());
} else { } else {
@ -19,7 +20,7 @@ export function polynomialTransform(
interaction_only = false, interaction_only = false,
include_bias = true, include_bias = true,
): pl.DataFrame { ): pl.DataFrame {
let polyRecords: number[][] = []; const polyRecords: number[][] = [];
dataframe.map((X: number[]) => { dataframe.map((X: number[]) => {
polyRecords.push( polyRecords.push(
polynomialFeatures(X, degree, interaction_only, include_bias), polynomialFeatures(X, degree, interaction_only, include_bias),
@ -38,7 +39,7 @@ export function polynomialFeatures(
let prev_chunk = [...X]; let prev_chunk = [...X];
const indices = Array.from({ length: X.length }, (_, i) => i); const indices = Array.from({ length: X.length }, (_, i) => i);
for (let d = 1; d < degree; d++) { for (let d = 1; d < degree; d++) {
const new_chunk: any[] = []; const new_chunk: number[] = [];
for (let i = 0; i < (interaction_only ? X.length - d : X.length); i++) { for (let i = 0; i < (interaction_only ? X.length - d : X.length); i++) {
const v = X[i]; const v = X[i];
const next_index = new_chunk.length; const next_index = new_chunk.length;
@ -71,13 +72,13 @@ export function augmentMeanForward(
df: pl.DataFrame, df: pl.DataFrame,
interval = 100, interval = 100,
) { ) {
let sorted = df.sort(feature); const sorted = df.sort(feature);
let featIdx = sorted.findIdxByName(feature); const featIdx = sorted.findIdxByName(feature);
let result = sorted.head(1); let result = sorted.head(1);
for (let i = 0; i < sorted.height; i++) { for (let i = 0; i < sorted.height; i++) {
let p1 = sorted.row(i).at(featIdx); const p1 = sorted.row(i).at(featIdx);
let k = (i + 1) % sorted.height; const k = (i + 1) % sorted.height;
let p2 = sorted.row(k).at(featIdx); const p2 = sorted.row(k).at(featIdx);
if (p2 - p1 > interval) { if (p2 - p1 > interval) {
for (let j = 0; j < Math.round((p2 - p1) / interval) - 1; j++) { for (let j = 0; j < Math.round((p2 - p1) / interval) - 1; j++) {
result = pl.concat([ result = pl.concat([

View file

@ -24,8 +24,8 @@
"const ys = [];\n", "const ys = [];\n",
"\n", "\n",
"for (let i = 0; i < 100; i++) {\n", "for (let i = 0; i < 100; i++) {\n",
" xs.push(i);\n", " xs.push(i);\n",
" ys.push((1 + 3 * i) + Math.random());\n", " ys.push((1 + 3 * i) + Math.random());\n",
"}\n", "}\n",
"\n", "\n",
"const linreg = stats.LinearRegression(xs, ys, [], false);\n", "const linreg = stats.LinearRegression(xs, ys, [], false);\n",
@ -34,7 +34,7 @@
"console.log(\"\\nLinear Regression Line:\");\n", "console.log(\"\\nLinear Regression Line:\");\n",
"console.log(\"\\tEstimated offset is: \", linreg.alpha.toFixed(6));\n", "console.log(\"\\tEstimated offset is: \", linreg.alpha.toFixed(6));\n",
"console.log(\"\\tEstimated slope is: \", linreg.beta.toFixed(6));\n", "console.log(\"\\tEstimated slope is: \", linreg.beta.toFixed(6));\n",
"console.log(\"\\tR^2 is: \", r.toFixed(6));\n" "console.log(\"\\tR^2 is: \", r.toFixed(6));"
] ]
} }
], ],