本文整理汇总了Python中sklearn.utils.validation.check_X_y函数的典型用法代码示例。如果您正苦于以下问题:Python check_X_y函数的具体用法?Python check_X_y怎么用?Python check_X_y使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_X_y函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: self_tune
def self_tune(self, X, y, verbose=False):
# fix random seed for reproducibility
seed = 5
np.random.seed(seed)
# define k-fold cross validation test harness
kfold = StratifiedKFold(y=y, n_folds=self.tuning_csp_num_folds, shuffle=True, random_state=seed)
# init scores
cvscores = {}
for i in xrange(1,self.num_spatial_filters):
cvscores[i+1] = 0
for i, (train, test) in enumerate(kfold):
# calculate CSP spatial filters
csp = CSP(n_components=self.num_spatial_filters)
csp.fit(X[train], y[train])
# try all filters, from the given num down to 2
# (1 is too often found to be overfitting)
for j in xrange(2,self.num_spatial_filters):
num_filters_to_try = j
# calculate spatial filters
csp.n_components = num_filters_to_try
# apply CSP filters to train data
tuning_train_LDA_features = csp.transform(X[train])
np.nan_to_num(tuning_train_LDA_features)
check_X_y(tuning_train_LDA_features, y[train])
# apply CSP filters to test data
tuning_test_LDA_features = csp.transform(X[test])
np.nan_to_num(tuning_test_LDA_features)
check_X_y(tuning_test_LDA_features, y[test])
# train LDA
lda = LinearDiscriminantAnalysis()
prediction_score = lda.fit(tuning_train_LDA_features, y[train]).score(tuning_test_LDA_features, y[test])
cvscores[num_filters_to_try] += prediction_score
if verbose:
print "prediction score", prediction_score, "with",num_filters_to_try,"spatial filters"
best_num = max(cvscores, key=cvscores.get)
best_score = cvscores[best_num] / i+1
if verbose:
print "best num filters:", best_num, "(average accuracy ",best_score,")"
print "average scores per filter num:"
for k in cvscores:
print k,":", cvscores[k]/i+1
return [best_num, best_score]
开发者ID:octopicorn,项目名称:bcikit,代码行数:54,代码来源:offline_analysis_grid.py
示例2: fit
def fit(self, X, y, random_state=np.random):
"""Create constraints from labels and learn the LSML model.
Parameters
----------
X : (n x d) matrix
Input data, where each row corresponds to a single instance.
y : (n) array-like
Data labels.
random_state : numpy.random.RandomState, optional
If provided, controls random number generation.
"""
X, y = check_X_y(X, y)
num_constraints = self.num_constraints
if num_constraints is None:
num_classes = len(np.unique(y))
num_constraints = 20 * num_classes**2
c = Constraints.random_subset(y, self.num_labeled,
random_state=random_state)
pairs = c.positive_negative_pairs(num_constraints, same_length=True,
random_state=random_state)
return LSML.fit(self, X, pairs, weights=self.weights)
开发者ID:svecon,项目名称:metric-learn,代码行数:25,代码来源:lsml.py
示例3: fit
def fit(self, X, y):
# Convert data
X, y = check_X_y(X, y,
accept_sparse=("csr", "csc"),
multi_output=True,
y_numeric=True)
return self
开发者ID:ZIP97,项目名称:scikit-learn,代码行数:7,代码来源:test_estimator_checks.py
示例4: fit
def fit(self, X, y):
"""
X: data matrix, (n x d)
y: scalar labels, (n)
"""
X, labels = check_X_y(X, y)
n, d = X.shape
num_dims = self.num_dims
if num_dims is None:
num_dims = d
# Initialize A to a scaling matrix
A = np.zeros((num_dims, d))
np.fill_diagonal(A, 1./(np.maximum(X.max(axis=0)-X.min(axis=0), EPS)))
# Run NCA
dX = X[:,None] - X[None] # shape (n, n, d)
tmp = np.einsum('...i,...j->...ij', dX, dX) # shape (n, n, d, d)
masks = labels[:,None] == labels[None]
for it in xrange(self.max_iter):
for i, label in enumerate(labels):
mask = masks[i]
Ax = A.dot(X.T).T # shape (n, num_dims)
softmax = np.exp(-((Ax[i] - Ax)**2).sum(axis=1)) # shape (n)
softmax[i] = 0
softmax /= softmax.sum()
t = softmax[:, None, None] * tmp[i] # shape (n, d, d)
d = softmax[mask].sum() * t.sum(axis=0) - t[mask].sum(axis=0)
A += self.learning_rate * A.dot(d)
self.X_ = X
self.A_ = A
self.n_iter_ = it
return self
开发者ID:svecon,项目名称:metric-learn,代码行数:35,代码来源:nca.py
示例5: reduce_data
def reduce_data(self, X, y):
X, y = check_X_y(X, y, accept_sparse="csr")
if self.classifier == None:
self.classifier = KNeighborsClassifier(n_neighbors=self.n_neighbors)
prots_s = []
labels_s = []
classes = np.unique(y)
self.classes_ = classes
for cur_class in classes:
mask = y == cur_class
insts = X[mask]
prots_s = prots_s + [insts[np.random.randint(0, insts.shape[0])]]
labels_s = labels_s + [cur_class]
self.classifier.fit(prots_s, labels_s)
for sample, label in zip(X, y):
if self.classifier.predict(sample) != [label]:
prots_s = prots_s + [sample]
labels_s = labels_s + [label]
self.classifier.fit(prots_s, labels_s)
self.X_ = np.asarray(prots_s)
self.y_ = np.asarray(labels_s)
self.reduction_ = 1.0 - float(len(self.y_))/len(y)
return self.X_, self.y_
开发者ID:antonlarin,项目名称:scikit-protopy,代码行数:31,代码来源:cnn.py
示例6: setUp
def setUp(self):
# Define data file and read X and y
# Generate some data if the source data is missing
this_directory = path.abspath(path.dirname(__file__))
mat_file = 'pima.mat'
try:
mat = loadmat(path.join(*[this_directory, 'data', mat_file]))
except TypeError:
print('{data_file} does not exist. Use generated data'.format(
data_file=mat_file))
X, y = generate_data(train_only=True) # load data
except IOError:
print('{data_file} does not exist. Use generated data'.format(
data_file=mat_file))
X, y = generate_data(train_only=True) # load data
else:
X = mat['X']
y = mat['y'].ravel()
X, y = check_X_y(X, y)
self.X_train, self.X_test, self.y_train, self.y_test = \
train_test_split(X, y, test_size=0.4, random_state=42)
self.clf = XGBOD(random_state=42)
self.clf.fit(self.X_train, self.y_train)
self.roc_floor = 0.8
开发者ID:flaviassantos,项目名称:pyod,代码行数:28,代码来源:test_xgbod.py
示例7: reduce_data
def reduce_data(self, X, y):
X, y = check_X_y(X, y, accept_sparse="csr")
if self.classifier == None:
self.classifier = KNeighborsClassifier(n_neighbors=self.n_neighbors)
if self.classifier.n_neighbors != self.n_neighbors:
self.classifier.n_neighbors = self.n_neighbors
classes = np.unique(y)
self.classes_ = classes
# loading inicial groups
self.groups = []
for label in classes:
mask = y == label
self.groups = self.groups + [_Group(X[mask], label)]
self._main_loop()
self._generalization_step()
self._merge()
self._pruning()
self.X_ = np.asarray([g.rep_x for g in self.groups])
self.y_ = np.asarray([g.label for g in self.groups])
self.reduction_ = 1.0 - float(len(self.y_))/len(y)
return self.X_, self.y_
开发者ID:antonlarin,项目名称:scikit-protopy,代码行数:25,代码来源:sgp.py
示例8: reduce_data
def reduce_data(self, X, y):
if self.classifier == None:
self.classifier = KNeighborsClassifier(n_neighbors=self.n_neighbors)
if self.classifier.n_neighbors != self.n_neighbors:
self.classifier.n_neighbors = self.n_neighbors
X, y = check_X_y(X, y, accept_sparse="csr")
classes = np.unique(y)
self.classes_ = classes
if self.n_neighbors >= len(X):
self.X_ = np.array(X)
self.y_ = np.array(y)
self.reduction_ = 0.0
return self.X_, self.y_
mask = np.zeros(y.size, dtype=bool)
tmp_m = np.ones(y.size, dtype=bool)
for i in xrange(y.size):
tmp_m[i] = not tmp_m[i]
self.classifier.fit(X[tmp_m], y[tmp_m])
sample, label = X[i], y[i]
if self.classifier.predict(sample) == [label]:
mask[i] = not mask[i]
tmp_m[i] = not tmp_m[i]
self.X_ = np.asarray(X[mask])
self.y_ = np.asarray(y[mask])
self.reduction_ = 1.0 - float(len(self.y_)) / len(y)
return self.X_, self.y_
开发者ID:antonlarin,项目名称:scikit-protopy,代码行数:34,代码来源:enn.py
示例9: fit
def fit(self, X, y):
'''Fit the model.
Parameters
----------
X : (n, d) array-like
Input data.
y : (n,) array-like
Class labels, one per point of data.
'''
X, y = check_X_y(X, y)
# Inject parameters into all fitness functions
for f in self._fitness:
f.inject_params(
random_state=self.random_state,
)
# Inject parameters into Strategy
self._strategy.inject_params(
n_dim=self._transformer.individual_size(X.shape[1]),
fitness=self._fitness,
transformer=self._transformer,
random_state=self.random_state,
verbose=self.verbose,
)
# transformer functions using strategy by optimising _fitnesses
self._strategy.fit(X, y)
# Fit (fill) transformer with the weights from the best individual
self._transformer.fit(X, y, self._strategy.best_individual())
return self
开发者ID:svecon,项目名称:metric-learn,代码行数:34,代码来源:evolution.py
示例10: threshold_fit
def threshold_fit(X, y, alpha, n_class, mode='AE',
max_iter=1000, verbose=False, tol=1e-12):
"""
Solve the general threshold-based ordinal regression model
using the logistic loss as surrogate of the 0-1 loss
Parameters
----------
mode : string, one of {'AE', '0-1'}
"""
X, y = check_X_y(X, y, accept_sparse='csr')
unique_y = np.sort(np.unique(y))
if not np.all(unique_y == np.arange(unique_y.size)):
raise ValueError(
'Values in y must be %s, got instead %s'
% (unique_y, np.arange(unique_y.size)))
y = np.asarray(y) # XXX check its made of integers
n_samples, n_features = X.shape
# convert from c to theta
L = np.zeros((n_class - 1, n_class - 1))
L[np.tril_indices(n_class-1)] = 1.
if mode == 'AE':
# loss forward difference
loss_fd = np.ones((n_class, n_class - 1))
elif mode == '0-1':
loss_fd = np.diag(np.ones(n_class - 1)) + \
np.diag(np.ones(n_class - 2), k=-1)
loss_fd = np.vstack((loss_fd, np.zeros(n_class - 1)))
loss_fd[-1, -1] = 1 # border case
elif mode == 'SE':
a = np.arange(n_class-1)
b = np.arange(n_class)
loss_fd = np.abs((a - b[:, None])**2 - (a - b[:, None]+1)**2)
else:
raise NotImplementedError
x0 = np.zeros(n_features + n_class - 1)
x0[X.shape[1]:] = np.arange(n_class - 1)
options = {'maxiter' : max_iter, 'disp': verbose}
if n_class > 2:
bounds = [(None, None)] * (n_features + 1) + \
[(0, None)] * (n_class - 3) + [(1, 1)]
bounds = [(None, None)] * (n_features + 1) + \
[(0, None)] * (n_class - 2)
else:
bounds = None
sol = optimize.minimize(obj_margin, x0, method='L-BFGS-B',
jac=grad_margin, args=(X, y, alpha, n_class, loss_fd, L),
bounds=bounds, options=options, tol=tol)
if not sol.success:
print(sol.message)
print(sol.message)
w, c = sol.x[:X.shape[1]], sol.x[X.shape[1]:]
theta = L.dot(c)
return w, theta
开发者ID:ancache,项目名称:mord,代码行数:59,代码来源:threshold_based.py
示例11: fit
def fit(self, X, y, sample_weight=None):
# Convert data
X, y = check_X_y(X, y, accept_sparse=("csr", "csc"), multi_output=True, y_numeric=True)
# Function is only called after we verify that pandas is installed
from pandas import Series
if isinstance(sample_weight, Series):
raise ValueError("Estimator does not accept 'sample_weight'" "of type pandas.Series")
return self
开发者ID:nelson-liu,项目名称:scikit-learn,代码行数:9,代码来源:test_estimator_checks.py
示例12: check_X_y
def check_X_y(self, X, y):
from sklearn.utils.validation import check_X_y
if X.shape[0] > self.max_train_size_:
raise Exception("X_train size cannot exceed {} ({})"
.format(self.max_train_size_, X.shape[0]))
return check_X_y(X, y, multi_output=True,
allow_nd=True, y_numeric=True,
estimator="GPRNP")
开发者ID:FullStackHan,项目名称:ottertune,代码行数:9,代码来源:gp.py
示例13: fit
def fit(self, X, y, sample_weight=None):
"""
Build a classifier from the training set (X, y).
Parameters
----------
X : array-like or sparse matrix of shape = [n_samples, n_features]
The training input samples.
y : array-like, shape = [n_samples]
The target values (class labels in classification).
sample_weight : array-like, shape = [n_samples] or None
Individual weights for each sample.
Returns
-------
self : object
Returns self.
"""
self._validate_params(**self.get_params())
X, y = check_X_y(X, y, accept_sparse=True)
if sp.isspmatrix(X):
self._is_sparse_train_X = True
else:
self._is_sparse_train_X = False
self._n_samples, self._n_features = X.shape
sample_weight = self._get_sample_weight(sample_weight)
check_consistent_length(X, y, sample_weight)
check_classification_targets(y)
self._classes = sorted(np.unique(y))
self._n_classes = len(self._classes)
self._classes_map = {}
self._set_params_with_dependencies()
params = self._get_params()
if self._n_classes == 2:
self._classes_map[0] = self._classes[0]
self._classes_map[1] = self._classes[1]
self._estimators = [None]
y = (y == self._classes[0]).astype(int)
self._fit_binary_task(X, y, sample_weight, params)
elif self._n_classes > 2:
if sp.isspmatrix_dok(X):
X = X.tocsr().tocoo() # Fix to avoid scipy 7699 issue
self._estimators = [None] * self._n_classes
self._fit_multiclass_task(X, y, sample_weight, params)
else:
raise ValueError("Classifier can't predict when only one class is present.")
self._fitted = True
return self
开发者ID:fukatani,项目名称:rgf_python,代码行数:55,代码来源:utils.py
示例14: fit
def fit(self, X, y):
# Check data
X, y = np.array(X), np.array(y)
X, y = check_X_y(X, y)
# Split to grow cascade and validate
mask = np.random.random(y.shape[0]) < self.validation_fraction
X_tr, X_vl = X[mask], X[~mask]
y_tr, y_vl = y[mask], y[~mask]
self.classes_ = unique_labels(y)
self.layers_, inp_tr, inp_vl = [], X_tr, X_vl
self.scores_ = []
# First layer
forests = [RandomForestClassifier(max_features=1, n_estimators=self.n_estimators, min_samples_split=10, criterion='gini', n_jobs=-1), # Complete random
RandomForestClassifier(max_features=1, n_estimators=self.n_estimators, min_samples_split=10, criterion='gini', n_jobs=-1), # Complete random
RandomForestClassifier(n_estimators=self.n_estimators, n_jobs=-1),
RandomForestClassifier(n_estimators=self.n_estimators, n_jobs=-1)]
_ = [f.fit(inp_tr, y_tr) for f in forests]
p_vl = [f.predict_proba(inp_vl) for f in forests]
labels = [self.classes_[i] for i in np.argmax(np.array(p_vl).mean(axis=0), axis=1)]
score = self.scoring(y_vl, labels)
self.layers_.append(forests)
self.scores_.append(score)
p_tr = [cross_val_predict(f, inp_tr, y_tr, cv=self.cv, method='predict_proba') for f in forests]
# Fit other layers
last_score = score
inp_tr, inp_vl = np.concatenate([X_tr]+p_tr, axis=1), np.concatenate([X_vl]+p_vl, axis=1)
while True: # Grow cascade
forests = [RandomForestClassifier(max_features=1, n_estimators=self.n_estimators, min_samples_split=10, criterion='gini', n_jobs=-1), # Complete random
RandomForestClassifier(max_features=1, n_estimators=self.n_estimators, min_samples_split=10, criterion='gini', n_jobs=-1), # Complete random
RandomForestClassifier(n_estimators=self.n_estimators, n_jobs=-1),
RandomForestClassifier(n_estimators=self.n_estimators, n_jobs=-1)]
_ = [forest.fit(inp_tr, y_tr) for forest in forests] # Fit the forest
p_vl = [forest.predict_proba(inp_vl) for forest in forests]
labels = [self.classes_[i] for i in np.argmax(np.array(p_vl).mean(axis=0), axis=1)]
score = self.scoring(y_vl, labels)
if score - last_score > self.tolerance:
self.layers_.append(forests)
p_tr = [cross_val_predict(f, inp_tr, y_tr, cv=self.cv, method='predict_proba') for f in forests]
inp_tr, inp_vl = np.concatenate([X_tr]+p_tr, axis=1), np.concatenate([X_vl]+p_vl, axis=1)
self.scores_.append(score)
last_score = score
print(self.scores_)
else:
break
# Retrain on entire dataset
inp_ = X
for forests in self.layers_:
_ = [f.fit(inp_, y) for f in forests]
p = [cross_val_predict(f, inp_, y, cv=self.cv, method='predict_proba') for f in forests]
inp_ = np.concatenate([X]+p, axis=1)
return self
开发者ID:sig-ml,项目名称:bleedml,代码行数:55,代码来源:classifiers.py
示例15: fit
def fit(self, X, y):
check_X_y(X, y, accept_sparse=['csc', 'csr', 'coo', 'dok',
'bsr', 'lil', 'dia'])
check_array(X, accept_sparse=['csc', 'csr', 'coo', 'dok',
'bsr', 'lil', 'dia'])
self.X_ = X
check_classification_targets(y)
classes = np.nonzero(y)
n_samples, n_classes = len(y), len(classes)
# create diagonal matrix of degree of nodes
if sparse.isspmatrix(self.X_):
B_ = self.X_.copy().astype(np.float)
D = np.array(csr_matrix.sum(self.X_, axis=1), dtype=np.float).T[0]
else:
B_ = np.copy(self.X_).astype(np.float)
D = np.array(np.sum(self.X_, axis=1), dtype=np.float)
# if (- self.sigma) and (self.sigma - 1) doesn't equals we have different diagonal matrix at the left and right sides
if (- self.sigma) == (self.sigma - 1):
D_left = D_right = np.power(D, - self.sigma)
else:
D_left = np.power(D, - self.sigma)
D_right = np.power(self.sigma - 1)
# M_ = D_left.dot(B_)
for i, d in enumerate(D_left):
B_[i, :] *= d
# B_ = M_.dot(D_right)
for i, d in enumerate(D_right):
B_[:, i] *= d
# create labeled data Z
dimension = (n_samples, n_classes)
labels = np.nonzero(y)
ans_y = np.zeros(dimension)
for l in labels[0]:
ans_y[l][y[l] - 1] = 1
Z_ = (self.sigma / (1 + self.sigma)) * ans_y
self.initial_vector_ = np.ones(dimension) / n_classes
self._get_method_(B_, Z_)
return self
开发者ID:KamalovMikhail,项目名称:semi_supervise,代码行数:42,代码来源:graph_base_semi_supervise.py
示例16: fit
def fit(self, X, y):
"""Fit the RVR to the training data."""
X, y = check_X_y(X, y)
n_samples, n_features = X.shape
self.phi = self._apply_kernel(X, X)
n_basis_functions = self.phi.shape[1]
self.relevance_ = X
self.y = y
self.alpha_ = self.alpha * np.ones(n_basis_functions)
self.beta_ = self.beta
self.m_ = np.zeros(n_basis_functions)
self.alpha_old = self.alpha_
for i in range(self.n_iter):
self._posterior()
self.gamma = 1 - self.alpha_*np.diag(self.sigma_)
self.alpha_ = self.gamma/(self.m_ ** 2)
if not self.beta_fixed:
self.beta_ = (n_samples - np.sum(self.gamma))/(
np.sum((y - np.dot(self.phi, self.m_)) ** 2))
self._prune()
if self.verbose:
print("Iteration: {}".format(i))
print("Alpha: {}".format(self.alpha_))
print("Beta: {}".format(self.beta_))
print("Gamma: {}".format(self.gamma))
print("m: {}".format(self.m_))
print("Relevance Vectors: {}".format(self.relevance_.shape[0]))
print()
delta = np.amax(np.absolute(self.alpha_ - self.alpha_old))
if delta < self.tol and i > 1:
break
self.alpha_old = self.alpha_
if self.bias_used:
self.bias = self.m_[-1]
else:
self.bias = None
return self
开发者ID:SuixueWang,项目名称:scikit-rvm,代码行数:54,代码来源:rvm.py
示例17: path_calc
def path_calc(X, y, X_holdout, y_holdout, alphas, paramgrid, colname = 'CV', yname = '', method = 'Elastic Net'):
#make a copy of the parameters before popping things off
copy_params = copy.deepcopy(paramgrid)
fit_intercept = copy_params.pop('fit_intercept')
precompute = copy_params.pop('precompute')
copy_X = copy_params.pop('copy_X')
normalize = False
# this code adapted from sklearn ElasticNet fit function, which unfortunately doesn't accept multiple alphas at once
X, y = check_X_y(X, y, accept_sparse='csc',
order='F', dtype=[np.float64, np.float32],
copy=copy_X and fit_intercept,
multi_output=True, y_numeric=True)
y = check_array(y, order='F', copy=False, dtype=X.dtype.type,
ensure_2d=False)
#this is the step that gives the data to find intercept if fit_intercept is true.
X, y, X_offset, y_offset, X_scale, precompute, Xy = _pre_fit(X, y, None, precompute, normalize,
fit_intercept, copy=False)
y = np.squeeze(y)
#do the path calculation, and tell how long it took
print('Calculating path...')
start_t = time.time()
if method == 'Elastic Net':
path_alphas, path_coefs, path_gaps, path_iters = enet_path(X, y, alphas=alphas, return_n_iter = True,
**copy_params)
if method == 'LASSO':
path_alphas, path_coefs, path_gaps, path_iters = lasso_path(X, y, alphas=alphas, return_n_iter=True,
**copy_params)
dt = time.time() - start_t
print('Took ' + str(dt) + ' seconds')
#create some empty arrays to store the result
y_pred_holdouts = np.empty(shape=(len(alphas),len(y_holdout)))
intercepts = np.empty(shape=(len(alphas)))
rmses = np.empty(shape=(len(alphas)))
cvcols = []
for j in list(range(len(path_alphas))):
coef_temp = path_coefs[:, j]
if fit_intercept:
coef_temp = coef_temp / X_scale
intercept = y_offset - np.dot(X_offset, coef_temp.T)
else:
intercept = 0.
y_pred_holdouts[j,:] = np.dot(X_holdout, path_coefs[:, j]) + intercept
intercepts[j] = intercept
rmses[j] = RMSE(y_pred_holdouts[j,:], y_holdout)
cvcols.append(('predict','"'+ method + ' - ' + yname + ' - ' + colname + ' - Alpha:' + str(path_alphas[j]) + ' - ' + str(paramgrid) + '"'))
return path_alphas, path_coefs, intercepts, path_iters, y_pred_holdouts, rmses, cvcols
开发者ID:USGS-Astrogeology,项目名称:PySAT,代码行数:54,代码来源:cv.py
示例18: fit
def fit(self, x, y):
# y = y.values
x, y = check_X_y(x, y, accept_sparse=True)
def pr(x, y_i, y):
p = x[y==y_i].sum(0)
return (p+1) / ((y==y_i).sum()+1)
self._r = sparse.csr_matrix(np.log(pr(x,1,y) / pr(x,0,y)))
x_nb = x.multiply(self._r)
self._clf = LogisticRegression(C=self.C, dual=self.dual, n_jobs=self.n_jobs).fit(x_nb, y)
return self
开发者ID:xiabofei,项目名称:python_details,代码行数:12,代码来源:model_nbsvm.py
示例19: fit
def fit(self, X, y):
"""Fit Gaussian process classification model
Parameters
----------
X : array-like, shape = (n_samples, n_features)
Training data
y : array-like, shape = (n_samples,)
Target values, must be binary
Returns
-------
self : returns an instance of self.
"""
X, y = check_X_y(X, y, multi_output=False)
self.base_estimator_ = _BinaryGaussianProcessClassifierLaplace(
self.kernel, self.optimizer, self.n_restarts_optimizer,
self.max_iter_predict, self.warm_start, self.copy_X_train,
self.random_state)
self.classes_ = np.unique(y)
self.n_classes_ = self.classes_.size
if self.n_classes_ == 1:
raise ValueError("GaussianProcessClassifier requires 2 or more "
"distinct classes; got %d class (only class %s "
"is present)"
% (self.n_classes_, self.classes_[0]))
if self.n_classes_ > 2:
if self.multi_class == "one_vs_rest":
self.base_estimator_ = \
OneVsRestClassifier(self.base_estimator_,
n_jobs=self.n_jobs)
elif self.multi_class == "one_vs_one":
self.base_estimator_ = \
OneVsOneClassifier(self.base_estimator_,
n_jobs=self.n_jobs)
else:
raise ValueError("Unknown multi-class mode %s"
% self.multi_class)
self.base_estimator_.fit(X, y)
if self.n_classes_ > 2:
self.log_marginal_likelihood_value_ = np.mean(
[estimator.log_marginal_likelihood()
for estimator in self.base_estimator_.estimators_])
else:
self.log_marginal_likelihood_value_ = \
self.base_estimator_.log_marginal_likelihood()
return self
开发者ID:AlexisMignon,项目名称:scikit-learn,代码行数:53,代码来源:gpc.py
示例20: fit
def fit(self, X, y):
X, y = check_X_y(X, y)
self.classes_ = unique_labels(y)
self.X_ = DynamicBayesianClassifier._first_col(X)
self.y_ = y
self.size_ = self.X_.size
for i in range(self.X_.size):
if y[i] not in self.dbayesmode_major_.keys():
self.dbayesmode_major_[y[i]] = scalgoutil.DBayesMode(y[i])
self.dbayesmode_major_[y[i]].update(self.X_[i])
self.update_priors()
return self
开发者ID:KeyboardNerd,项目名称:PredictiveServer,代码行数:12,代码来源:scestimator.py
注:本文中的sklearn.utils.validation.check_X_y函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论