我正在尝试在 Julia 中对以下数据集执行岭回归,任何人都可以共享资源以在代码中执行岭回归吗?
I'm trying to perform ridge regression on the following dataset in Julia, Can anyone share resources to perform ridge regression in code?
x={10.9, 12.4, 13.5, 14.6, 14.8, 15.6, 16.2, 17.5, 18.3, 18.6} 和 y={24.8, 30.0, 31.0, 29.3, 35.9, 36.9, 42.5, 37.9, 38.9, 40.5}.
我已经使用代码执行了线性回归:
using DataFrames, CSV
using PyPlot
using Plots
using GLM
x = [10.9, 12.4, 13.5, 14.6, 14.8, 15.6, 16.2, 17.5, 18.3, 18.6] #x-values
y = [24.8, 30.0, 31.0, 29.3, 35.9, 36.9, 42.5, 37.9, 38.9, 40.5] #Y-values
data = DataFrame(X=x, Y=y)
linearRegressor = lm(@formula(Y ~ X), data)
println(linearRegressor)
linearFit = predict(linearRegressor)
(plot!(x, linearFit,))
display(scatter!(x, y))
按照 Bogumil 在评论中的建议使用 MLJLinearModels
julia> x = [10.9, 12.4, 13.5, 14.6, 14.8, 15.6, 16.2, 17.5, 18.3, 18.6];
julia> y = [24.8, 30.0, 31.0, 29.3, 35.9, 36.9, 42.5, 37.9, 38.9, 40.5];
julia> xₘ = reshape(x, length(x), 1); # since MLJ will expect x to be a Matrix (2d array)
julia> using MLJLinearModels
julia> fit(RidgeRegression(), xₘ, y)
2-element Vector{Float64}:
2.2488474986814606
0.24878206004726794
x={10.9, 12.4, 13.5, 14.6, 14.8, 15.6, 16.2, 17.5, 18.3, 18.6} 和 y={24.8, 30.0, 31.0, 29.3, 35.9, 36.9, 42.5, 37.9, 38.9, 40.5}.
我已经使用代码执行了线性回归:
using DataFrames, CSV
using PyPlot
using Plots
using GLM
x = [10.9, 12.4, 13.5, 14.6, 14.8, 15.6, 16.2, 17.5, 18.3, 18.6] #x-values
y = [24.8, 30.0, 31.0, 29.3, 35.9, 36.9, 42.5, 37.9, 38.9, 40.5] #Y-values
data = DataFrame(X=x, Y=y)
linearRegressor = lm(@formula(Y ~ X), data)
println(linearRegressor)
linearFit = predict(linearRegressor)
(plot!(x, linearFit,))
display(scatter!(x, y))
按照 Bogumil 在评论中的建议使用 MLJLinearModels
julia> x = [10.9, 12.4, 13.5, 14.6, 14.8, 15.6, 16.2, 17.5, 18.3, 18.6];
julia> y = [24.8, 30.0, 31.0, 29.3, 35.9, 36.9, 42.5, 37.9, 38.9, 40.5];
julia> xₘ = reshape(x, length(x), 1); # since MLJ will expect x to be a Matrix (2d array)
julia> using MLJLinearModels
julia> fit(RidgeRegression(), xₘ, y)
2-element Vector{Float64}:
2.2488474986814606
0.24878206004726794