@tpmjs/tools-logistic-regression
Perform binary logistic regression using gradient descent. Fits a model to predict binary outcomes (0 or 1) from feature variables. Returns coefficients, predictions, and accuracy metrics.
Test @tpmjs/tools-logistic-regression (logisticRegressionTool) with AI-powered execution
0/2000 characters
Install this tool and use it with the AI SDK
npm install @tpmjs/tools-logistic-regressionpnpm add @tpmjs/tools-logistic-regressionyarn add @tpmjs/tools-logistic-regressionbun add @tpmjs/tools-logistic-regressiondeno add npm:@tpmjs/tools-logistic-regressionimport { logisticRegressionTool } from '@tpmjs/tools-logistic-regression';import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { logisticRegressionTool } from '@tpmjs/tools-logistic-regression';
const result = await generateText({
model: openai('gpt-4o'),
tools: { logisticRegressionTool },
prompt: 'Your prompt here...',
});
console.log(result.text);Available configuration options
xarrayFeature matrix where each row is a sample and each column is a feature
yarrayBinary target labels (must be 0 or 1)
iterationsnumberNumber of gradient descent iterations (default: 1000)
learningRatenumberLearning rate for gradient descent (default: 0.1)
Schema extracted: 1/1/2026, 8:18:23 AM
Simple binary logistic regression implementation using gradient descent optimization.
npm install @tpmjs/tools-logistic-regression
import { logisticRegressionTool } from '@tpmjs/tools-logistic-regression'; // Example: Predict binary outcome from features const result = await logisticRegressionTool.execute({ x: [ [1.0, 2.0], [2.0, 3.0], [3.0, 4.0], [4.0, 5.0], ], y: [0, 0, 1, 1], iterations: 1000, }); console.log(result); // { // coefficients: [0.5, 0.3, -0.2], // [intercept, feature1, feature2] // predictions: [0, 0, 1, 1], // accuracy: 1.0, // iterations: 1000, // convergence: { // finalLoss: 0.123, // converged: true // } // }
number[][] where each row is a samplenumber[] (must be 0 or 1)Uses gradient descent to minimize binary cross-entropy loss:
The sigmoid function maps linear combinations to probabilities [0, 1].
MIT
Downloads/month
0
Quality Score