Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #24 from IBM/new_amlpbase
Browse files Browse the repository at this point in the history
New amlpbase
  • Loading branch information
ppalmes authored Apr 21, 2021
2 parents 01707e4 + a12a99d commit 58fa034
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Lale"
uuid = "25676c37-aa2f-4f14-ad5b-b63670ababff"
authors = ["Paulito Palmes <[email protected]>", "Martin Hirzel", "Avraham Shinnar", "Kiran Kate"]
version = "0.1.2"
version = "0.1.3"

[deps]
AMLPipelineBase = "e3c3008a-8869-4d53-9f34-c96f99c8a2b6"
Expand Down
7 changes: 4 additions & 3 deletions src/Lale.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using PyCall
# load abstract super-types and utils
using AMLPipelineBase
using AMLPipelineBase.AbsTypes
export fit!, transform!,fit_transform!
export fit, fit!, transform, transform!, fit_transform!

using AMLPipelineBase
using AMLPipelineBase: AbsTypes, Utils, BaselineModels, Pipelines
Expand Down Expand Up @@ -41,8 +41,9 @@ module LaleAbsTypes
export LaleOperator, fit, transform, predict, lalepropertynames

abstract type LaleOperator <: Learner end
fit(o::Machine, x::DataFrame, y::Vector=Vector()) = fit!(o,x,y)
transform(o::Machine, x::DataFrame) = transform!(o,x)

#fit(o::Machine, x::DataFrame, y::Vector=Vector()) = fit!(o,x,y)
#transform(o::Machine, x::DataFrame) = transform!(o,x)
predict(o::Machine, x::DataFrame) = transform!(o,x)

lalepropertynames(o::PyObject) = ispynull(o) ? Symbol[] : map(x->Symbol(first(x)), PyIterator{PyObject}(pycall(inspect."getmembers", PyObject, o)))
Expand Down
25 changes: 13 additions & 12 deletions src/lalelibop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ using ..AbsTypes
using ..Utils
using ..LaleAbsTypes

import ..AbsTypes: fit!, transform!
import ..LaleAbsTypes: fit, transform, predict
import ..AbsTypes: fit, fit!, transform, transform!
import ..LaleAbsTypes: predict

export fit!, transform!
export fit, transform, predict
export fit, fit!, transform, transform!, predict

import Base: >>,|,+,|>,&
export >>,|,+,|>,&
Expand Down Expand Up @@ -107,28 +106,30 @@ function lalepipeoptimizers()
println("Note: Consult Lale online help for more details about the auto_configure arguments.")
end

function fit!(lopt::LalePipeOptimizer, xx::DataFrame, y::Vector=Vector())
function fit!(lopt::LalePipeOptimizer, xx::DataFrame, y::Vector=Vector())::Nothing
Xpd = Pandas.DataFrame(xx).pyo
Ypd = Pandas.DataFrame(y).pyo
margs = lopt.model[:impl_args]
pipe = lopt.model[:lalepipe]
hyperopt = LALELIBS.Hyperopt(estimator=pipe; margs...)
trained = hyperopt.fit(Xpd,Ypd)
lopt.model[:trained] = trained
return nothing
end

function transform!(lopt::LalePipeOptimizer, xx::DataFrame)
Xpd = Pandas.DataFrame(xx).pyo
trainedmodel = lopt.model[:trained]
trainedmodel.predict(Xpd) |> Pandas.DataFrame |> DataFrame |> x -> x[:,1]
end

function fit(lopt::LalePipeOptimizer, xx::DataFrame, y::Vector=Vector())
function fit(lopt::LalePipeOptimizer, xx::DataFrame, y::Vector=Vector())::LalePipeOptimizer
fit!(lopt,xx,y)
loptcopy = deepcopy(lopt)
return loptcopy
end

function transform!(lopt::LalePipeOptimizer, xx::DataFrame)::Vector
Xpd = Pandas.DataFrame(xx).pyo
trainedmodel = lopt.model[:trained]
trainedmodel.predict(Xpd) |> Pandas.DataFrame |> DataFrame |> x -> x[:,1] |> collect
end


transform(lopt::LalePipeOptimizer, xx::DataFrame) = transform!(lopt,xx)
predict(lopt::LalePipeOptimizer, xx::DataFrame) = transform!(lopt,xx)

Expand Down
25 changes: 14 additions & 11 deletions src/laleop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ using ..AbsTypes
using ..LaleAbsTypes
using ..Utils

import ..AbsTypes: fit!, transform!
import ..LaleAbsTypes: fit, transform, predict
import ..AbsTypes: fit, fit!, transform, transform!
import ..LaleAbsTypes: predict

export fit!, transform!, fit, transform, predict
export LaleOp, skops, autogenops, lalelibops
Expand Down Expand Up @@ -168,7 +168,7 @@ function lalelibops()
println("Note: Consult Scikitlearn's online help for more details about the learner's arguments.")
end

function fit!(lale::LaleOp, xx::DataFrame, y::Vector=Vector())
function fit!(lale::LaleOp, xx::DataFrame, y::Vector=Vector())::Nothing
x = xx |> Array
impl_args = copy(lale.model[:impl_args])
learner = lale.model[:learner]
Expand All @@ -195,9 +195,16 @@ function fit!(lale::LaleOp, xx::DataFrame, y::Vector=Vector())
end
lale.model[:laleobj] = trained
lale.model[:impl_args] = impl_args
return nothing
end

function transform!(lale::LaleOp, xx::DataFrame)
function fit(lale::LaleOp, xx::DataFrame, y::Vector=Vector())::LaleOp
fit!(lale,xx,y)
lcopy =deepcopy(lale)
return lcopy
end

function transform!(lale::LaleOp, xx::DataFrame)::Union{DataFrame, Vector}
x = deepcopy(xx)|> Array
laleobj = lale.model[:laleobj]
# transform is predict for learners
Expand All @@ -210,14 +217,10 @@ function transform!(lale::LaleOp, xx::DataFrame)
end
end

function fit(lale::LaleOp, xx::DataFrame, y::Vector=Vector())
fit!(lale,xx,y)
lcopy =deepcopy(lale)
return lcopy
function transform(lale::LaleOp, xx::DataFrame)::Union{DataFrame, Vector}
return transform!(lale,xx)
end

transform(lale::LaleOp, xx::DataFrame) = transform!(lale,xx)
predict(lale::LaleOp, xx::DataFrame) = transform!(lale,xx)
predict(lale::LaleOp, xx::DataFrame) = transform!(lale,xx)

end

2 comments on commit 58fa034

@ppalmes
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/34897

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.3 -m "<description of version>" 58fa034b9648d29439563c86da17cf3a1c579327
git push origin v0.1.3

Please sign in to comment.