Monty  Boehm

Monty Boehm

1658637360

ScikitLearnBase.jl: Abstract interface of ScikitLearn.jl

ScikitLearnBase.jl

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.

Overview

The docs contain an overview of the API and a more thorough specification.

There are two implementation strategies for an existing machine learning package:

  • Create a new type that wraps the existing type. The new type can usually be written entirely on top of the existing codebase (i.e. without modifying it). This gives more implementation freedom, and a more consistent interface amongst the various ScikitLearn.jl models. Here's an example from DecisionTree.jl
  • Use the existing type. This requires less code, and is usually better when the model type already contains the hyperparameters / fitting arguments.

Example

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

#julia #interface 

What is GEEK

Buddha Community

ScikitLearnBase.jl: Abstract interface of ScikitLearn.jl

Abstract class & Abstract method in C# | OOP in C# Part-24

https://youtu.be/vonwoaUl0Hw

#oop #abstract #abstract method #abstract class #what is abstract

Monty  Boehm

Monty Boehm

1658637360

ScikitLearnBase.jl: Abstract interface of ScikitLearn.jl

ScikitLearnBase.jl

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.

Overview

The docs contain an overview of the API and a more thorough specification.

There are two implementation strategies for an existing machine learning package:

  • Create a new type that wraps the existing type. The new type can usually be written entirely on top of the existing codebase (i.e. without modifying it). This gives more implementation freedom, and a more consistent interface amongst the various ScikitLearn.jl models. Here's an example from DecisionTree.jl
  • Use the existing type. This requires less code, and is usually better when the model type already contains the hyperparameters / fitting arguments.

Example

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

#julia #interface 

When to use `Abstract` Base Class vs `Interface`

When devising the architecture of your classes, a few concerns will pop up:

  • How its instances are going to be used
  • Discover common properties and patterns
  • Foresee how this class is going to be extended in the future

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.


What is an abstract class?

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

Eve  Klocko

Eve Klocko

1596202920

Abstract Classes Java

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?

Modifiers

There are two types of modifiers, used to control the access mechanism and provide class functionalities to JVM.

  1. Access modifiers

Used to facilitate the encapsulation of components.

  • public
  • private
  • protected

#abstraction #interfaces #java

Difference between abstract class and interface | OOP in C# | C# OOP Bangla Tutorial

https://youtu.be/OTQrF2GBub0

#oop in c# #object oriented programming #object oriented concept in c# #learn oop concept #different between abstract class and interface