本文整理汇总了Python中sklearn.utils.metaestimators._safe_split方法的典型用法代码示例。如果您正苦于以下问题:Python metaestimators._safe_split方法的具体用法?Python metaestimators._safe_split怎么用?Python metaestimators._safe_split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.utils.metaestimators
的用法示例。
在下文中一共展示了metaestimators._safe_split方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_safe_split_with_precomputed_kernel
# 需要导入模块: from sklearn.utils import metaestimators [as 别名]
# 或者: from sklearn.utils.metaestimators import _safe_split [as 别名]
def test_safe_split_with_precomputed_kernel():
clf = SVC()
clfp = SVC(kernel="precomputed")
iris = datasets.load_iris()
X, y = iris.data, iris.target
K = np.dot(X, X.T)
cv = ShuffleSplit(test_size=0.25, random_state=0)
train, test = list(cv.split(X))[0]
X_train, y_train = _safe_split(clf, X, y, train)
K_train, y_train2 = _safe_split(clfp, K, y, train)
assert_array_almost_equal(K_train, np.dot(X_train, X_train.T))
assert_array_almost_equal(y_train, y_train2)
X_test, y_test = _safe_split(clf, X, y, test, train)
K_test, y_test2 = _safe_split(clfp, K, y, test, train)
assert_array_almost_equal(K_test, np.dot(X_test, X_train.T))
assert_array_almost_equal(y_test, y_test2)
示例2: split_with_schemas
# 需要导入模块: from sklearn.utils import metaestimators [as 别名]
# 或者: from sklearn.utils.metaestimators import _safe_split [as 别名]
def split_with_schemas(estimator, all_X, all_y, indices, train_indices=None):
subset_X, subset_y = _safe_split(
estimator, all_X, all_y, indices, train_indices)
if hasattr(all_X, 'json_schema'):
n_rows = subset_X.shape[0]
schema = {
'type': 'array', 'minItems': n_rows, 'maxItems': n_rows,
'items': all_X.json_schema['items']}
lale.datasets.data_schemas.add_schema(subset_X, schema)
if hasattr(all_y, 'json_schema'):
n_rows = subset_y.shape[0]
schema = {
'type': 'array', 'minItems': n_rows, 'maxItems': n_rows,
'items': all_y.json_schema['items']}
lale.datasets.data_schemas.add_schema(subset_y, schema)
return subset_X, subset_y
示例3: _permutation_test_score
# 需要导入模块: from sklearn.utils import metaestimators [as 别名]
# 或者: from sklearn.utils.metaestimators import _safe_split [as 别名]
def _permutation_test_score(estimator, X, y, groups, cv, scorer):
"""Auxiliary function for permutation_test_score"""
avg_score = []
for train, test in cv.split(X, y, groups):
X_train, y_train = _safe_split(estimator, X, y, train)
X_test, y_test = _safe_split(estimator, X, y, test, train)
estimator.fit(X_train, y_train)
avg_score.append(scorer(estimator, X_test, y_test))
return np.mean(avg_score)
示例4: _partial_fit_and_score
# 需要导入模块: from sklearn.utils import metaestimators [as 别名]
# 或者: from sklearn.utils.metaestimators import _safe_split [as 别名]
def _partial_fit_and_score(
self,
estimator, # type: BaseEstimator
train, # type: List[int]
test, # type: List[int]
partial_fit_params, # type: Dict[str, Any]
):
# type: (...) -> List[Number]
X_train, y_train = _safe_split(estimator, self.X, self.y, train)
X_test, y_test = _safe_split(estimator, self.X, self.y, test, train_indices=train)
start_time = time()
try:
estimator.partial_fit(X_train, y_train, **partial_fit_params)
except Exception as e:
if self.error_score == "raise":
raise e
elif isinstance(self.error_score, Number):
fit_time = time() - start_time
test_score = self.error_score
score_time = 0.0
if self.return_train_score:
train_score = self.error_score
else:
raise ValueError("error_score must be 'raise' or numeric.")
else:
fit_time = time() - start_time
test_score = self.scoring(estimator, X_test, y_test)
score_time = time() - fit_time - start_time
if self.return_train_score:
train_score = self.scoring(estimator, X_train, y_train)
# Required for type checking but is never expected to fail.
assert isinstance(fit_time, Number)
assert isinstance(score_time, Number)
ret = [test_score, fit_time, score_time]
if self.return_train_score:
ret.insert(0, train_score)
return ret