cstjean / ScikitLearn.jl

Julia implementation of the scikit-learn API https://cstjean.github.io/ScikitLearn.jl/dev/
Other
546 stars 75 forks source link

Question: Is there sample weight support? #64

Closed ablaom closed 4 years ago

ablaom commented 4 years ago

Sorry for the spam, but I've had no reply at this Discourse thread: https://discourse.julialang.org/t/does-scikitlearn-support-sample-weights-for-scikit-learn-models-that-do/30815

cstjean commented 4 years ago

It seems to be sample_weight, without s. See https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html

Let me know if it works, I've never tried it. ScikitLearn is a thin wrapper around sklearn. Their docs are much more complete and useful than I could ever achieve.

ablaom commented 4 years ago

Thanks, this appears to work:

using ScikitLearn, Random

@sk_import linear_model: SGDRegressor
model = SGDRegressor()
model.random_state = 1

X = randn(100, 4)
y = X[:,1] - 2X[:,2] + 0.05*randn(100)
w = rand(100)

fit!(model, X, y)
p1 = predict(model, X)
fit!(model, X, y)
p2 = predict(model, X)
p1 ≈ p2 # true

fit!(model, X, y, sample_weight=w)
p3 = predict(model, X)
!(p1 ≈ p3) # true