本文整理匯總了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