本文整理汇总了Python中sklearn.linear_model.ridge.RidgeClassifierCV.fit方法的典型用法代码示例。如果您正苦于以下问题:Python RidgeClassifierCV.fit方法的具体用法?Python RidgeClassifierCV.fit怎么用?Python RidgeClassifierCV.fit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.linear_model.ridge.RidgeClassifierCV
的用法示例。
在下文中一共展示了RidgeClassifierCV.fit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_class_weights_cv
# 需要导入模块: from sklearn.linear_model.ridge import RidgeClassifierCV [as 别名]
# 或者: from sklearn.linear_model.ridge.RidgeClassifierCV import fit [as 别名]
def test_class_weights_cv():
# Test class weights for cross validated ridge classifier.
X = np.array([[-1.0, -1.0], [-1.0, 0], [-0.8, -1.0], [1.0, 1.0], [1.0, 0.0]])
y = [1, 1, 1, -1, -1]
clf = RidgeClassifierCV(class_weight=None, alphas=[0.01, 0.1, 1])
clf.fit(X, y)
# we give a small weights to class 1
clf = RidgeClassifierCV(class_weight={1: 0.001}, alphas=[0.01, 0.1, 1, 10])
clf.fit(X, y)
assert_array_equal(clf.predict([[-0.2, 2]]), np.array([-1]))
示例2: _test_ridge_classifiers
# 需要导入模块: from sklearn.linear_model.ridge import RidgeClassifierCV [as 别名]
# 或者: from sklearn.linear_model.ridge.RidgeClassifierCV import fit [as 别名]
def _test_ridge_classifiers(filter_):
n_classes = np.unique(y_iris).shape[0]
n_features = X_iris.shape[1]
for reg in (RidgeClassifier(), RidgeClassifierCV()):
reg.fit(filter_(X_iris), y_iris)
assert_equal(reg.coef_.shape, (n_classes, n_features))
y_pred = reg.predict(filter_(X_iris))
assert_greater(np.mean(y_iris == y_pred), .79)
cv = KFold(5)
reg = RidgeClassifierCV(cv=cv)
reg.fit(filter_(X_iris), y_iris)
y_pred = reg.predict(filter_(X_iris))
assert_true(np.mean(y_iris == y_pred) >= 0.8)
示例3: _test_ridge_classifiers
# 需要导入模块: from sklearn.linear_model.ridge import RidgeClassifierCV [as 别名]
# 或者: from sklearn.linear_model.ridge.RidgeClassifierCV import fit [as 别名]
def _test_ridge_classifiers(filter_):
n_classes = np.unique(y_iris).shape[0]
n_features = X_iris.shape[1]
for clf in (RidgeClassifier(), RidgeClassifierCV()):
clf.fit(filter_(X_iris), y_iris)
assert_equal(clf.coef_.shape, (n_classes, n_features))
y_pred = clf.predict(filter_(X_iris))
assert_greater(np.mean(y_iris == y_pred), .79)
n_samples = X_iris.shape[0]
cv = KFold(n_samples, 5)
clf = RidgeClassifierCV(cv=cv)
clf.fit(filter_(X_iris), y_iris)
y_pred = clf.predict(filter_(X_iris))
assert_true(np.mean(y_iris == y_pred) >= 0.8)
示例4: test_ridge_classifier_cv_store_cv_values
# 需要导入模块: from sklearn.linear_model.ridge import RidgeClassifierCV [as 别名]
# 或者: from sklearn.linear_model.ridge.RidgeClassifierCV import fit [as 别名]
def test_ridge_classifier_cv_store_cv_values():
x = np.array([[-1.0, -1.0], [-1.0, 0], [-.8, -1.0],
[1.0, 1.0], [1.0, 0.0]])
y = np.array([1, 1, 1, -1, -1])
n_samples = x.shape[0]
alphas = [1e-1, 1e0, 1e1]
n_alphas = len(alphas)
r = RidgeClassifierCV(alphas=alphas, cv=None, store_cv_values=True)
# with len(y.shape) == 1
n_targets = 1
r.fit(x, y)
assert r.cv_values_.shape == (n_samples, n_targets, n_alphas)
# with len(y.shape) == 2
y = np.array([[1, 1, 1, -1, -1],
[1, -1, 1, -1, 1],
[-1, -1, 1, -1, -1]]).transpose()
n_targets = y.shape[1]
r.fit(x, y)
assert r.cv_values_.shape == (n_samples, n_targets, n_alphas)