求python大神解释下这段代码,没接触过python不会啊

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了求python大神解释下这段代码,没接触过python不会啊相关的知识,希望对你有一定的参考价值。

def __init__(self,
n_estimators=10,
criterion="gini",
max_depth=None,
min_samples_split=2,
min_samples_leaf=1,
min_weight_fraction_leaf=0.,
max_features="auto",
max_leaf_nodes=None,
bootstrap=True,
oob_score=False,
n_jobs=1,
random_state=None,
verbose=0,
warm_start=False,
class_weight=None):
super(RandomForestClassifier, self).__init__(
base_estimator=DecisionTreeClassifier(),
n_estimators=n_estimators,
estimator_params=("criterion", "max_depth", "min_samples_split",
"min_samples_leaf", "min_weight_fraction_leaf",
"max_features", "max_leaf_nodes",
"random_state"),
bootstrap=bootstrap,
oob_score=oob_score,
n_jobs=n_jobs,
random_state=random_state,
verbose=verbose,
warm_start=warm_start,
class_weight=class_weight)

self.criterion = criterion
self.max_depth = max_depth
self.min_samples_split = min_samples_split
self.min_samples_leaf = min_samples_leaf
self.min_weight_fraction_leaf = min_weight_fraction_leaf
self.max_features = max_features
self.max_leaf_nodes = max_leaf_nodes

这就是一段构造函数。
(self,
n_estimators=10,
criterion="gini",
max_depth=None,
min_samples_split=2,
min_samples_leaf=1,
min_weight_fraction_leaf=0.,
max_features="auto",
max_leaf_nodes=None,
bootstrap=True,
oob_score=False,
n_jobs=1,
random_state=None,
verbose=0,
warm_start=False,
class_weight=None):
这是构造函数的参数,有默认值。

super(RandomForestClassifier, self).__init__(
base_estimator=DecisionTreeClassifier(),
n_estimators=n_estimators,
estimator_params=("criterion", "max_depth", "min_samples_split",
"min_samples_leaf", "min_weight_fraction_leaf",
"max_features", "max_leaf_nodes",
"random_state"),
bootstrap=bootstrap,
oob_score=oob_score,
n_jobs=n_jobs,
random_state=random_state,
verbose=verbose,
warm_start=warm_start,
class_weight=class_weight)

supper会调用基类构造函数,你可以认为这一串就是基类构造函数的参数。

self.criterion = criterion
self.max_depth = max_depth
self.min_samples_split = min_samples_split
self.min_samples_leaf = min_samples_leaf
self.min_weight_fraction_leaf = min_weight_fraction_leaf
self.max_features = max_features
self.max_leaf_nodes = max_leaf_nodes

这一串就是属性赋值。追问

你好,十分感谢你的回答,base_estimator=DecisionTreeClassifier(),
这一个代码是什么意思呢请问

参考技术A import re
reader = open('test.txt','r')
for txt in reader.readlines():
p = r'([a-z]+|[A-z]+)'
#print re.findall(p,txt)
pattern =  re.compile(p)
match = pattern.match(txt)
if match:
print match.groups()

谁能解释这段代码到底做了啥?

【中文标题】谁能解释这段代码到底做了啥?【英文标题】:Can anybody explain what this code exactly do?谁能解释这段代码到底做了什么? 【发布时间】:2015-07-08 09:32:58 【问题描述】:

我在我的项目 index.php 文件中找到了这段代码,我确定我从来没有添加过这段代码,我有点担心,请各位大神解释一下这段代码到底是做什么的?

if (preg_match('/\/admin\/Cms_Wysiwyg\/directive\/index\//', $_SERVER['REQUEST_URI'])) 
    if ($_SERVER['REQUEST_METHOD'] == 'POST') 
        if (isset($_REQUEST['___directive']) && isset($_REQUEST['forwarded'])) 
            if (preg_match('/report_search_grid/', base64_decode($_REQUEST['___directive'])))
                $_REQUEST['forwarded'] = $_POST['forwarded'] = $_GET['forwarded'] = $_COOKIE['forwarded'] = null;
            
    

【问题讨论】:

这有什么问题?任何人都可以添加 cmets 吗? 【参考方案1】:

你需要安装Magento security patch

这是网站被入侵的迹象

【讨论】:

以上是关于求python大神解释下这段代码,没接触过python不会啊的主要内容,如果未能解决你的问题,请参考以下文章

AS3 求大神优化下这段代码,这个代码里的if else太多了,但需要去判断关数在返回指定的数组,求大神简化!

Python代码求解释 求大神解释一下这段代码 详细点 最好每句加上注释 谢了

python3.8 tkinter为啥title 没有用,求大神解答!代码如下

关于js中 .map()的问题,希望大神可以帮忙解读下这段代码的实现过程

为啥我的这段python代码运行不出来结果,也没报错,跪求大神指点

这个方法没看懂,求大神解释!