Ruby Curve Fitting (логарифмическая регрессия) пакет - PullRequest
8 голосов
/ 08 октября 2010

Я ищу рубиновый гем или библиотеку, которая выполняет логарифмическую регрессию (кривая, подходящая к логарифмическому уравнению). Я пробовал statsample (http://ruby -statsample.rubyforge.org / ), но, похоже, он не соответствует тому, что я ищу. У кого-нибудь есть предложения?

Ответы [ 2 ]

11 голосов
/ 21 декабря 2011

Попробуйте использовать гем '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
4 голосов
/ 09 марта 2011

Я сейчас ищу что-то похожее и наткнулся на этот ответ .

Три драгоценных камня для взаимодействия с R из Ruby:

Еще один драгоценный камень для LR в Ruby:

Я еще ничего не пробовал, но я изучаю, какие есть варианты для MLR в Ruby.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...