简体   繁体   English

Scikit-学习导入约定

[英]Scikit-learn import convention

I'm beginning to do some machine learning in Python, and I'm just starting to use the sklearn package. 我开始用Python做一些机器学习,而我刚刚开始使用sklearn包。 In my experience with Python data science programming, there are conventions for naming imported packages; 根据我使用Python数据科学编程的经验,有一些命令用于命名导入的包; for example, import pandas as pd , or import numpy as np . 例如, import pandas as pd ,或import numpy as np

Thus far, I've only ever seen code where a single function, etc. is imported from sklearn, rather than the entirety of the package. 到目前为止,我只见过从sklearn导入单个函数等的代码,而不是整个包。 If I were to import sklearn, what convention would be used. 如果我要导入sklearn,将使用什么约定。 In other words, import sklearn as --what? 换句话说, import sklearn as - 是什么?

(Of course, if I haven't seen it yet, it's entirely possible that it means that convention is specifically to not import the entirety of sklearn at a time.... If that's the case, please let me know that too. Thanks.) (当然,如果我还没有看到它,那么完全有可能这意味着约定是专门不是一次导入整个sklearn ......如果是这样的话,请让我知道。谢谢。)

Import just the classes that you need. 只导入您需要的类。 Unlike with numpy, it is likely to be a pretty small subset and slower-changing subset of the module. 与numpy不同,它可能是一个非常小的子集和模块中变化较慢的子集。 For example 例如

from sklearn.ensemble import RandomForestClassifier
...
est = RandomForestClassifier()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM