我正在寻找一个Ruby gem或库,用于进行对数回归(将曲线拟合到对数方程)。我已经尝试了statsample(http://ruby-statsample.rubyforge.org/),但它似乎没有我需要的功能。有人有什么建议吗?
我正在寻找一个Ruby gem或库,用于进行对数回归(将曲线拟合到对数方程)。我已经尝试了statsample(http://ruby-statsample.rubyforge.org/),但它似乎没有我需要的功能。有人有什么建议吗?
尝试使用 "statsample" 宝石。您可以使用类似的方法执行指数、对数、幂、正弦或任何其他转换。希望这可以帮助您。
require 'statsample'
# Independent Variable
x_data = [Math.exp(1), Math.exp(2), Math.exp(3), Math.exp(4), Math.exp(5)]
# Dependent Variable
y_data = [3, 5, 7, 9, 11]
# Logarithmic Transformation of X data
# Math.log in Ruby has the base of Euler's number 'e' ~= '2.71828',
# instead of the base '10'. Just a note.
log_x_data = x_data.map { |x| Math.log(x) }
# Linear Regression using the Logarithmic Transformation
x_vector = log_x_data.to_vector(:scale)
y_vector = y_data.to_vector(:scale)
ds = {'x'=>x_vector,'y'=>y_vector}.to_dataset
mlr = Statsample::Regression.multiple(ds,'y')
# Prints a statistical summary of the regression
print mlr.summary
# Lists the value of the y-intercept
p mlr.constant
# Lists the coefficients of each casual variable. In this case, we have only one--'x'.
p mlr.coeffs
# The regression output produces the line y = 1 + 2*x, but
# considering that we transformed x earlier, it really produces
# y = 1 + 2*ln(x).
# Bonus: The command below lists the methods contained in the instance variable, so that
# you can get the R^2, SSE, coefficients, and t-values. I'll leave it commented out for now.
# p mlr.methods
我目前正在寻找类似的东西,并发现了这个回答。
与Ruby交互的三个gem:
用于Ruby的LR的另一个gem:
虽然我还没尝试过,但我正在调查在Ruby中进行多元线性回归的选项。
试试Rumale和Numo::NArray https://github.com/yoshoku/rumale
Rumale(Ruby机器学习)是一个Ruby语言的机器学习库。Rumale提供了类似于Python中Scikit-Learn的机器学习算法接口。Rumale支持线性/核支持向量机、逻辑回归、线性回归、岭回归、Lasso回归、分解机、朴素贝叶斯、决策树、AdaBoost、梯度树提升、随机森林、Extra-Trees、K最近邻分类器、K-Means、K-Medoids、高斯混合模型、DBSCAN、幂迭代聚类、多维缩放、t-SNE、主成分分析和非负矩阵分解等机器学习算法。