本文整理汇总了Python中model_base.ModelBase._get_metrics方法的典型用法代码示例。如果您正苦于以下问题:Python ModelBase._get_metrics方法的具体用法?Python ModelBase._get_metrics怎么用?Python ModelBase._get_metrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model_base.ModelBase
的用法示例。
在下文中一共展示了ModelBase._get_metrics方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: totss
# 需要导入模块: from model_base import ModelBase [as 别名]
# 或者: from model_base.ModelBase import _get_metrics [as 别名]
def totss(self, train=False, valid=False, xval=False):
"""
Get the total sum of squares.
If all are False (default), then return the training metric value.
If more than one options is set to True, then return a dictionary of metrics where
the keys are "train", "valid", and "xval".
Parameters
----------
train : bool, optional
If True, then return the total sum of squares value for the training
data.
valid : bool, optional
If True, then return the total sum of squares value for the validation
data.
xval : bool, optional
If True, then return the total sum of squares value for each of the
cross-validated splits.
Returns
-------
Returns the total sum of squares values for the specified key(s).
"""
tm = ModelBase._get_metrics(self, train, valid, xval)
m = {}
for k, v in zip(tm.keys(), tm.values()):
m[k] = None if v is None else v._metric_json["totss"]
return m.values()[0] if len(m) == 1 else m
示例2: size
# 需要导入模块: from model_base import ModelBase [as 别名]
# 或者: from model_base.ModelBase import _get_metrics [as 别名]
def size(self, train=False, valid=False, xval=False):
"""
Get the sizes of each cluster.
If all are False (default), then return the training metric value.
If more than one options is set to True, then return a dictionary of metrics where
the keys are "train", "valid", and "xval"
Parameters
----------
train : bool, optional
If True, then return cluster sizes for the training data.
valid : bool, optional
If True, then return the cluster sizes for the validation data.
xval : bool, optional
If True, then return the cluster sizes for each of the cross-validated splits.
Returns
-------
Returns the cluster sizes for the specified key(s).
"""
tm = ModelBase._get_metrics(self, train, valid, xval)
m = {}
for k, v in zip(tm.keys(), tm.values()):
m[k] = None if v is None else [v[2] for v in v._metric_json["centroid_stats"].cell_values]
return m.values()[0] if len(m) == 1 else m
示例3: find_threshold_by_max_metric
# 需要导入模块: from model_base import ModelBase [as 别名]
# 或者: from model_base.ModelBase import _get_metrics [as 别名]
def find_threshold_by_max_metric(self,metric,train=False, valid=False, xval=False):
"""
If all are False (default), then return the training metric value.
If more than one options is set to True, then return a dictionary of metrics where the keys are "train", "valid",
and "xval"
:param train: If train is True, then return the threshold_by_max_metric value for the training data.
:param valid: If valid is True, then return the threshold_by_max_metric value for the validation data.
:param xval: If xval is True, then return the threshold_by_max_metric value for the cross validation data.
:return: The threshold_by_max_metric for this binomial model.
"""
tm = ModelBase._get_metrics(self, train, valid, xval)
m = {}
for k,v in zip(tm.keys(),tm.values()): m[k] = None if v is None else v.find_threshold_by_max_metric(metric)
return m.values()[0] if len(m) == 1 else m
示例4: F0point5
# 需要导入模块: from model_base import ModelBase [as 别名]
# 或者: from model_base.ModelBase import _get_metrics [as 别名]
def F0point5(self, thresholds=None, train=False, valid=False, xval=False):
"""Get the F0.5 for a set of thresholds.
If all are False (default), then return the training metric value.
If more than one options is set to True, then return a dictionary of metrics where the keys are "train", "valid",
and "xval"
:param thresholds: thresholds parameter must be a list (i.e. [0.01, 0.5, 0.99]). If None, then the thresholds in this set of metrics will be used.
:param train: If train is True, then return the F0point5 value for the training data.
:param valid: If valid is True, then return the F0point5 value for the validation data.
:param xval: If xval is True, then return the F0point5 value for the cross validation data.
:return: The F0point5 for this binomial model.
"""
tm = ModelBase._get_metrics(self, train, valid, xval)
m = {}
for k,v in zip(tm.keys(),tm.values()): m[k] = None if v is None else v.metric("f0point5", thresholds=thresholds)
return m.values()[0] if len(m) == 1 else m
示例5: find_idx_by_threshold
# 需要导入模块: from model_base import ModelBase [as 别名]
# 或者: from model_base.ModelBase import _get_metrics [as 别名]
def find_idx_by_threshold(self,threshold,train=False, valid=False, xval=False):
"""
Retrieve the index in this metric's threshold list at which the given threshold is located.
If all are False (default), then return the training metric value.
If more than one options is set to True, then return a dictionary of metrics where the keys are "train", "valid",
and "xval"
:param train: If train is True, then return the idx_by_threshold for the training data.
:param valid: If valid is True, then return the idx_by_threshold for the validation data.
:param xval: If xval is True, then return the idx_by_threshold for the cross validation data.
:return: The idx_by_threshold for this binomial model.
"""
tm = ModelBase._get_metrics(self, train, valid, xval)
m = {}
for k,v in zip(tm.keys(),tm.values()): m[k] = None if v is None else v.find_idx_by_threshold(threshold)
return m.values()[0] if len(m) == 1 else m
示例6: hit_ratio_table
# 需要导入模块: from model_base import ModelBase [as 别名]
# 或者: from model_base.ModelBase import _get_metrics [as 别名]
def hit_ratio_table(self, train=False, valid=False, xval=False):
"""
Retrieve the Hit Ratios
If all are False (default), then return the training metric value.
If more than one options is set to True, then return a dictionary of metrics where the keys are "train", "valid",
and "xval"
:param train: If train is True, then return the R^2 value for the training data.
:param valid: If valid is True, then return the R^2 value for the validation data.
:param xval: If xval is True, then return the R^2 value for the cross validation data.
:return: The R^2 for this regression model.
"""
tm = ModelBase._get_metrics(self, train, valid, xval)
m = {}
for k,v in zip(tm.keys(),tm.values()): m[k] = None if v is None else v.hit_ratio_table()
return m.values()[0] if len(m) == 1 else m
示例7: gains_lift
# 需要导入模块: from model_base import ModelBase [as 别名]
# 或者: from model_base.ModelBase import _get_metrics [as 别名]
def gains_lift(self, train=False, valid=False, xval=False):
"""
Get the Gains/Lift table for the specified metrics
If all are False (default), then return the training metric Gains/Lift table.
If more than one options is set to True, then return a dictionary of metrics where the keys are "train", "valid",
and "xval"
:param train: If train is True, then return the Gains/Lift table for the training data.
:param valid: If valid is True, then return the Gains/Lift table for the validation data.
:param xval: If xval is True, then return the Gains/Lift table for the cross validation data.
:return: The Gains/Lift table for this binomial model.
"""
tm = ModelBase._get_metrics(self, train, valid, xval)
m = {}
for k, v in zip(tm.keys(), tm.values()):
m[k] = None if v is None else v.gains_lift()
return m.values()[0] if len(m) == 1 else m
示例8: confusion_matrix
# 需要导入模块: from model_base import ModelBase [as 别名]
# 或者: from model_base.ModelBase import _get_metrics [as 别名]
def confusion_matrix(self, metrics=None, thresholds=None, train=False, valid=False, xval=False):
"""
Get the confusion matrix for the specified metrics/thresholds
If all are False (default), then return the training metric value.
If more than one options is set to True, then return a dictionary of metrics where the keys are "train", "valid",
and "xval"
:param metrics: A string (or list of strings) in {"min_per_class_accuracy", "absolute_MCC", "tnr", "fnr", "fpr", "tpr", "precision", "accuracy", "f0point5", "f2", "f1"}
:param thresholds: thresholds parameter must be a list (i.e. [0.01, 0.5, 0.99]). If None, then the thresholds in this set of metrics will be used.
:param train: If train is True, then return the confusion matrix value for the training data.
:param valid: If valid is True, then return the confusion matrix value for the validation data.
:param xval: If xval is True, then return the confusion matrix value for the cross validation data.
:return: The confusion matrix for this binomial model.
"""
tm = ModelBase._get_metrics(self, train, valid, xval)
m = {}
for k,v in zip(tm.keys(),tm.values()): m[k] = None if v is None else v.confusion_matrix(metrics=metrics, thresholds=thresholds)
return m.values()[0] if len(m) == 1 else m
示例9: roc
# 需要导入模块: from model_base import ModelBase [as 别名]
# 或者: from model_base.ModelBase import _get_metrics [as 别名]
def roc(self, train=False, valid=False, xval=False):
"""
Return the coordinates of the ROC curve for a given set of data,
as a two-tuple containing the false positive rates as a list and true positive
rates as a list.
If all are False (default), then return is the training data.
If more than one ROC curve is requested, the data is returned as a dictionary
of two-tuples.
:param train: If train is true, then return the ROC coordinates for the training data.
:param valid: If valid is true, then return the ROC coordinates for the validation data.
:param xval: If xval is true, then return the ROC coordinates for the cross validation data.
:return rocs_cooridinates: the true cooridinates of the roc curve.
"""
tm = ModelBase._get_metrics(self, train, valid, xval)
m = {}
for k,v in zip(tm.keys(),tm.values()):
if v is not None:
m[k] = (v.fprs, v.tprs)
return m.values()[0] if len(m) == 1 else m
示例10: F1
# 需要导入模块: from model_base import ModelBase [as 别名]
# 或者: from model_base.ModelBase import _get_metrics [as 别名]
def F1(self, thresholds=None, train=False, valid=False, xval=False):
"""Get the F1 value for a set of thresholds
If all are False (default), then return the training metric value.
If more than one options is set to True, then return a dictionary of metrics where
the keys are "train", "valid", and "xval".
Parameters
----------
thresholds : list, optional
If None, then the thresholds in this set of metrics will be used.
train : bool, optional
If True, return the F1 value for the training data.
valid : bool, optional
If True, return the F1 value for the validation data.
xval : bool, optional
If True, return the F1 value for each of the cross-validated splits.
Returns
-------
The F1 values for the specified key(s).
Examples
--------
>>> import h2o as ml
>>> from h2o.estimators.gbm import H2OGradientBoostingEstimator
>>> ml.init()
>>> rows=[[1,2,3,4,0],[2,1,2,4,1],[2,1,4,2,1],[0,1,2,34,1],[2,3,4,1,0]]*50
>>> fr = ml.H2OFrame(rows)
>>> fr[4] = fr[4].asfactor()
>>> model = H2OGradientBoostingEstimator(ntrees=10, max_depth=10, nfolds=4)
>>> model.train(x=range(4), y=4, training_frame=fr)
>>> model.F1(train=True)
"""
tm = ModelBase._get_metrics(self, train, valid, xval)
m = {}
for k,v in tm.iteritems():
m[k] = None if v is None else v.metric("f1", thresholds=thresholds)
return m.values()[0] if len(m) == 1 else m