Nosferican / Econometrics.jl

Econometrics in Julia
https://nosferican.github.io/Econometrics.jl/dev
ISC License
69 stars 19 forks source link

Implement `predict(mod, newdata)` #15

Open Nosferican opened 5 years ago

Nosferican commented 5 years ago

Implement predict(mod::EconometricModel, newdata::Any). This should help integrate with the MLJ API.

DilumAluthge commented 4 years ago

Bump. @Nosferican Any update on this? In particular, I need to be able to do predict(mod::EconometricModel{<:NominalResponse}, newdata::DataFrame).

Nosferican commented 4 years ago

I was going to leave it as a GSOC part of a project but I think I can take a look at it... Shouldn't be too bad to add.

DilumAluthge commented 4 years ago

Let's consider the example of NominalResponse. Once you have your features in the form of the model matrix X, then getting the probabilities is very straightforward:

function predict(model::EconometricModel{<:NominalResponse}, new_X::AbstractMatrix)
    n, p = size(new_X)
    probs = hcat(zeros(n), new_X * reshape( m.β, (p, m.estimator.categories - 1) )
    for i = 1:n
        probs[i, :] .= StatsFuns.softmax(probs[i, :])
    end
    return probs
end

The problem is: how does Econometrics turn a DataFrame into a Matrix? If I want to call predict(model::EconometricModel{<:NominalResponse}, new_data::AbstractDataFrame), then I need to use that exact same process to turn my new_data::AbstractDataFrame into new_X::AbstractMatrix.

Nosferican commented 4 years ago

Aye. I had a talk with @kleinschmidt back in February about various strategies for handling the cases of rank deficient and instrumental variables. I think I will just keep a formula for prediction that does the transformations from original to suitable for prediction. In the case of the ologit, I am envisioning returning a NamedTuple{(:response, :probs), (:Symbol, Matrix{Float64})}.

DilumAluthge commented 4 years ago

Bump.