使用 JavaScript 将逻辑回归拟合到数据集并获得 beta 系数?
Using JavaScript to fit logistic regressions to datasets and obtaining beta-coefficients?
背景
使用 JavaScript,我需要将逻辑回归拟合到我生成的数据集。具体来说,我需要拟合多变量逻辑回归,并且我想获得模型的 beta 系数。如何在 JavaScript 中编写此功能?
我试过的
解决方案
坚持使用 js-regression
后,我深入研究了它的源代码,发现我错误地设置了训练数据的结构。本质上,使用 fit()
函数生成的模型的 theta
属性是您的系数列表。
代码
let model = logistic.fit(training_dataset); // Generate the model
console.log(model); // Log the model
这输出:
{
theta: [ ... ], // These were my coefficients
threshold: 1,
cost: ...,
config: { alpha: 0.001, lambda: 0, iterations: 10000 }
}
背景
使用 JavaScript,我需要将逻辑回归拟合到我生成的数据集。具体来说,我需要拟合多变量逻辑回归,并且我想获得模型的 beta 系数。如何在 JavaScript 中编写此功能?
我试过的
解决方案
坚持使用 js-regression
后,我深入研究了它的源代码,发现我错误地设置了训练数据的结构。本质上,使用 fit()
函数生成的模型的 theta
属性是您的系数列表。
代码
let model = logistic.fit(training_dataset); // Generate the model
console.log(model); // Log the model
这输出:
{
theta: [ ... ], // These were my coefficients
threshold: 1,
cost: ...,
config: { alpha: 0.001, lambda: 0, iterations: 10000 }
}