1658637360
This package exposes the scikit-learn interface. Packages that implement this interface can be used in conjunction with ScikitLearn.jl (pipelines, cross-validation, hyperparameter tuning, ...)
This is an intentionally slim package (~100 LOC, no dependencies). That way, ML libraries can import ScikitLearnBase
without dragging along all of ScikitLearn
's dependencies.
The docs contain an overview of the API and a more thorough specification.
There are two implementation strategies for an existing machine learning package:
For models with simple hyperparameters, it boils down to this:
import ScikitLearnBase
mutable struct NaiveBayes
# The model hyperparameters (not learned from data)
bias::Float64
# The parameters learned from data
counts::Matrix{Int}
# A constructor that accepts the hyperparameters as keyword arguments
# with sensible defaults
NaiveBayes(; bias=0.0f0) = new(bias)
end
# This will define `clone`, `set_params!` and `get_params` for the model
ScikitLearnBase.@declare_hyperparameters(NaiveBayes, [:bias])
# NaiveBayes is a classifier
ScikitLearnBase.is_classifier(::NaiveBayes) = true # not required for transformers
function ScikitLearnBase.fit!(model::NaiveBayes, X, y)
# X should be of size (n_sample, n_feature)
.... # modify model.counts here
return model
end
function ScikitLearnBase.predict(model::NaiveBayes, X)
.... # returns a vector of predicted classes here
end
Models with more complex hyperparameter specifications should implement clone
, get_params
and set_params!
explicitly instead of using @declare_hyperparameters
.
More examples of PRs that implement the interface: GaussianMixtures.jl, GaussianProcesses.jl, DecisionTree.jl, LowRankModels.jl
Note: if the model performs unsupervised learning, implement transform
instead of predict
.
Once your library implements the API, file an issue/PR to add it to the list of models.
Author: cstjean
Source Code: https://github.com/cstjean/ScikitLearnBase.jl
License: View license
1590188020
#oop #abstract #abstract method #abstract class #what is abstract
1658637360
This package exposes the scikit-learn interface. Packages that implement this interface can be used in conjunction with ScikitLearn.jl (pipelines, cross-validation, hyperparameter tuning, ...)
This is an intentionally slim package (~100 LOC, no dependencies). That way, ML libraries can import ScikitLearnBase
without dragging along all of ScikitLearn
's dependencies.
The docs contain an overview of the API and a more thorough specification.
There are two implementation strategies for an existing machine learning package:
For models with simple hyperparameters, it boils down to this:
import ScikitLearnBase
mutable struct NaiveBayes
# The model hyperparameters (not learned from data)
bias::Float64
# The parameters learned from data
counts::Matrix{Int}
# A constructor that accepts the hyperparameters as keyword arguments
# with sensible defaults
NaiveBayes(; bias=0.0f0) = new(bias)
end
# This will define `clone`, `set_params!` and `get_params` for the model
ScikitLearnBase.@declare_hyperparameters(NaiveBayes, [:bias])
# NaiveBayes is a classifier
ScikitLearnBase.is_classifier(::NaiveBayes) = true # not required for transformers
function ScikitLearnBase.fit!(model::NaiveBayes, X, y)
# X should be of size (n_sample, n_feature)
.... # modify model.counts here
return model
end
function ScikitLearnBase.predict(model::NaiveBayes, X)
.... # returns a vector of predicted classes here
end
Models with more complex hyperparameter specifications should implement clone
, get_params
and set_params!
explicitly instead of using @declare_hyperparameters
.
More examples of PRs that implement the interface: GaussianMixtures.jl, GaussianProcesses.jl, DecisionTree.jl, LowRankModels.jl
Note: if the model performs unsupervised learning, implement transform
instead of predict
.
Once your library implements the API, file an issue/PR to add it to the list of models.
Author: cstjean
Source Code: https://github.com/cstjean/ScikitLearnBase.jl
License: View license
1592905748
When devising the architecture of your classes, a few concerns will pop up:
You can leverage your implementations by using abstract base classes and interfaces. Often these two raise a lot of confusion since they are similar, however, they actually have different implementations.
Let’s find out when to use each. For this, we will see examples using different programming languages (Kotlin, TypeScript, Java), but the theory applies to all of them.
A class can be declared abstract when you want common methods or properties to be extended by other classes (or other abstract classes).
When an abstract class defines an abstract method, this method must be overridden by the extending subclass — unless the abstract class is extended by another abstract class, in which case you’ll get a cascading inheritance.
These abstract methods, defined in the abstract class, are created having only their signature. They shouldn’t have a body at this point, that will be defined in the overridden method.
Likewise, you can define concrete (non-abstract) methods that will be inherited by the extending class.
#programming #theory #abstract #object-oriented #interfaces
1596202920
In previous articles, we discussed Inheritance, Polymorphism, and Encapsulation. You can get the idea of OOP concepts by going through those articles. Today we are going to discuss another vital OOP concept called Abstract Classes and methods in Java.
Abstract class vs Interface
The abstraction of data is the process of hiding certain information and showing only essential information to the user. Abstraction can be achieved with abstract classes as well as interfaces. abstract
the keyword that we are using is a non-access modifier. What are modifiers?
There are two types of modifiers, used to control the access mechanism and provide class functionalities to JVM.
Used to facilitate the encapsulation of components.
#abstraction #interfaces #java
1591229617
#oop in c# #object oriented programming #object oriented concept in c# #learn oop concept #different between abstract class and interface