# ScikitLearnBase.jl **Repository Path**: juliaprog/ScikitLearnBase.jl ## Basic Information - **Project Name**: ScikitLearnBase.jl - **Description**: Abstract interface of ScikitLearn.jl - **Primary Language**: Julia - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-08-01 - **Last Updated**: 2024-05-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ScikitLearnBase.jl ------------ 该包来自于GitHub中的[ScikitLearnBase.jl](https://github.com/cstjean/ScikitLearnBase.jl.git),暴露了scikit-learn的接口,能够对接Julia的另外一个包[ScikitLearn.jl](https://github.com/cstjean/ScikitLearn.jl)的各种功能,包括管道、交叉验证、超级参数调优(hyperparameter tuning)等。 这是一个极为简单的库(仅有一个源文件),没有依赖。其他机器学习库使用`import ScikitLearnBase`引入该包时,无需引入`ScikitLearn`的各种依赖包。 简述 ----- 文档包括[API概览](http://scikitlearnjl.readthedocs.org/en/latest/api/)及[详细说明](docs/API.md)。 对已有的机器学习包,有以下两个实现策略: - *声明新类型以封装存在的类型*. 新类型通常可以完整地进行使用,无需进行修改,使得在开发中有更高的自由度,并保持了ScikitLearn.jl接口的一致性。DecisionTree.jl中的[scikitlearnAPI.jl](https://github.com/cstjean/DecisionTree.jl/blob/2722950c8f0c5e5c62204364308e28d4123383cb/src/scikitlearnAPI.jl)就是使用该库的一个具体例子。 - *使用存在的类型*. 这种方式代码量少一些,对于模型中已经包括超级参数(hyperparameters)/拟合(Fitting)参数时更为合适。 示例 ----- 对于有些简单的超级参数的模型,一般可如下处理: ```julia import ScikitLearnBase type NaiveBayes # 模型的超级参数(不从数据中学习确定,通常由经验确定) bias::Float64 # 由数据学习确定的参数 counts::Matrix{Int} # 一个接受超级参数作为键值参数的构造函数,并给了合理的默认值 NaiveBayes(; bias=0.0f0) = new(bias) end # 以下的用法可同时定义出`clone`、`set_params!`和`get_params`接口 ScikitLearnBase.@declare_hyperparameters(NaiveBayes, [:bias]) # 朴素贝叶斯分类器 ScikitLearnBase.is_classifier(::NaiveBayes) = true # 无需特别的转换 function ScikitLearnBase.fit!(model::NaiveBayes, X, y) # X的维度应为:(n_sample, n_feature) ... # 修改 model.counts 等语句 return model end function ScikitLearnBase.predict(model::NaiveBayes, X) .... # 返回一个包含预测结果(类别)的vector类型 end ``` 包含了更多复杂超级参数的模型应显式地实现`clone`、`get_params` 和 `set_params!` 而不是使用`@declare_hyperparameters`宏。 还可以参考更多的例子,包括[GaussianMixtures.jl](https://github.com/davidavdav/GaussianMixtures.jl/pull/18/files), [GaussianProcesses.jl](https://github.com/STOR-i/GaussianProcesses.jl/pull/17/files), [DecisionTree.jl](https://github.com/bensadeghi/DecisionTree.jl/pull/29/files), [LowRankModels.jl](https://github.com/madeleineudell/LowRankModels.jl/pull/56/files) 说明:对于非监督学习模型,实现 `transform`以替代`predict`接口。 如果在库中使用该API,可以将问题提交到[issue/PR](https://github.com/cstjean/ScikitLearn.jl/issues),并可将其增加到[模型列表](http://scikitlearnjl.readthedocs.io/en/latest/models/#julia-models)中。