本文整理汇总了Python中sklearn.linear_model.RidgeClassifierCV方法的典型用法代码示例。如果您正苦于以下问题:Python linear_model.RidgeClassifierCV方法的具体用法?Python linear_model.RidgeClassifierCV怎么用?Python linear_model.RidgeClassifierCV使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.linear_model
的用法示例。
在下文中一共展示了linear_model.RidgeClassifierCV方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_logistic_regression_coefs_l2
# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import RidgeClassifierCV [as 别名]
def get_logistic_regression_coefs_l2(self, category,
clf=RidgeClassifierCV()):
''' Computes l2-penalized logistic regression score.
Parameters
----------
category : str
category name to score
category : str
category name to score
Returns
-------
(coefficient array, accuracy, majority class baseline accuracy)
'''
try:
from sklearn.cross_validation import cross_val_predict
except:
from sklearn.model_selection import cross_val_predict
y = self._get_mask_from_category(category)
X = TfidfTransformer().fit_transform(self._X)
clf.fit(X, y)
y_hat = cross_val_predict(clf, X, y)
acc, baseline = self._get_accuracy_and_baseline_accuracy(y, y_hat)
return clf.coef_[0], acc, baseline
示例2: test_model_ridge_classifier_cv_binary
# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import RidgeClassifierCV [as 别名]
def test_model_ridge_classifier_cv_binary(self):
model, X = fit_classification_model(
linear_model.RidgeClassifierCV(), 2)
model_onnx = convert_sklearn(
model,
"binary ridge classifier cv",
[("input", FloatTensorType([None, X.shape[1]]))],
)
self.assertIsNotNone(model_onnx)
dump_data_and_model(
X,
model,
model_onnx,
basename="SklearnRidgeClassifierCVBin",
allow_failure="StrictVersion(onnxruntime.__version__)"
" <= StrictVersion('0.2.1')",
)
示例3: test_model_ridge_classifier_cv_int
# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import RidgeClassifierCV [as 别名]
def test_model_ridge_classifier_cv_int(self):
model, X = fit_classification_model(
linear_model.RidgeClassifierCV(), 2, is_int=True)
model_onnx = convert_sklearn(
model,
"binary ridge classifier cv",
[("input", Int64TensorType([None, X.shape[1]]))],
)
self.assertIsNotNone(model_onnx)
dump_data_and_model(
X,
model,
model_onnx,
basename="SklearnRidgeClassifierCVInt",
allow_failure="StrictVersion(onnxruntime.__version__)"
" <= StrictVersion('0.2.1')",
)
示例4: test_model_ridge_classifier_cv_bool
# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import RidgeClassifierCV [as 别名]
def test_model_ridge_classifier_cv_bool(self):
model, X = fit_classification_model(
linear_model.RidgeClassifierCV(), 2, is_bool=True)
model_onnx = convert_sklearn(
model,
"binary ridge classifier cv",
[("input", BooleanTensorType([None, X.shape[1]]))],
)
self.assertIsNotNone(model_onnx)
dump_data_and_model(
X,
model,
model_onnx,
basename="SklearnRidgeClassifierCVBool",
allow_failure="StrictVersion(onnxruntime.__version__)"
" <= StrictVersion('0.2.1')",
)
示例5: test_model_ridge_classifier_cv_multi_class
# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import RidgeClassifierCV [as 别名]
def test_model_ridge_classifier_cv_multi_class(self):
model, X = fit_classification_model(
linear_model.RidgeClassifierCV(), 5)
model_onnx = convert_sklearn(
model,
"multi-class ridge classifier cv",
[("input", FloatTensorType([None, X.shape[1]]))],
)
self.assertIsNotNone(model_onnx)
dump_data_and_model(
X,
model,
model_onnx,
basename="SklearnRidgeClassifierCVMulti",
allow_failure="StrictVersion(onnxruntime.__version__)"
" <= StrictVersion('0.2.1')",
)
示例6: test_model_ridge_classifier_cv_multilabel
# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import RidgeClassifierCV [as 别名]
def test_model_ridge_classifier_cv_multilabel(self):
model, X_test = fit_multilabel_classification_model(
linear_model.RidgeClassifierCV(random_state=42))
model_onnx = convert_sklearn(
model,
"scikit-learn RidgeClassifierCV",
[("input", FloatTensorType([None, X_test.shape[1]]))],
)
self.assertTrue(model_onnx is not None)
dump_data_and_model(
X_test,
model,
model_onnx,
basename="SklearnRidgeClassifierCVMultiLabel",
allow_failure="StrictVersion("
"onnxruntime.__version__)<= StrictVersion('0.2.1')",
)
示例7: test_rocket_on_gunpoint
# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import RidgeClassifierCV [as 别名]
def test_rocket_on_gunpoint():
# load training data
X_training, Y_training = load_gunpoint(split="train", return_X_y=True)
# 'fit' ROCKET -> infer data dimensions, generate random kernels
ROCKET = Rocket(num_kernels=10_000)
ROCKET.fit(X_training)
# transform training data
X_training_transform = ROCKET.transform(X_training)
# test shape of transformed training data -> (number of training
# examples, num_kernels * 2)
np.testing.assert_equal(X_training_transform.shape,
(len(X_training), 20_000))
# fit classifier
classifier = RidgeClassifierCV(alphas=np.logspace(-3, 3, 10),
normalize=True)
classifier.fit(X_training_transform, Y_training)
# load test data
X_test, Y_test = load_gunpoint(split="test", return_X_y=True)
# transform test data
X_test_transform = ROCKET.transform(X_test)
# test shape of transformed test data -> (number of test examples,
# num_kernels * 2)
np.testing.assert_equal(X_test_transform.shape, (len(X_test), 20_000))
# predict (alternatively: 'classifier.score(X_test_transform, Y_test)')
predictions = classifier.predict(X_test_transform)
accuracy = accuracy_score(predictions, Y_test)
# test predictions (on Gunpoint, should be 100% accurate)
assert accuracy == 1.0
示例8: test_objectmapper
# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import RidgeClassifierCV [as 别名]
def test_objectmapper(self):
df = pdml.ModelFrame([])
self.assertIs(df.linear_model.ARDRegression, lm.ARDRegression)
self.assertIs(df.linear_model.BayesianRidge, lm.BayesianRidge)
self.assertIs(df.linear_model.ElasticNet, lm.ElasticNet)
self.assertIs(df.linear_model.ElasticNetCV, lm.ElasticNetCV)
self.assertIs(df.linear_model.HuberRegressor, lm.HuberRegressor)
self.assertIs(df.linear_model.Lars, lm.Lars)
self.assertIs(df.linear_model.LarsCV, lm.LarsCV)
self.assertIs(df.linear_model.Lasso, lm.Lasso)
self.assertIs(df.linear_model.LassoCV, lm.LassoCV)
self.assertIs(df.linear_model.LassoLars, lm.LassoLars)
self.assertIs(df.linear_model.LassoLarsCV, lm.LassoLarsCV)
self.assertIs(df.linear_model.LassoLarsIC, lm.LassoLarsIC)
self.assertIs(df.linear_model.LinearRegression, lm.LinearRegression)
self.assertIs(df.linear_model.LogisticRegression, lm.LogisticRegression)
self.assertIs(df.linear_model.LogisticRegressionCV, lm.LogisticRegressionCV)
self.assertIs(df.linear_model.MultiTaskLasso, lm.MultiTaskLasso)
self.assertIs(df.linear_model.MultiTaskElasticNet, lm.MultiTaskElasticNet)
self.assertIs(df.linear_model.MultiTaskLassoCV, lm.MultiTaskLassoCV)
self.assertIs(df.linear_model.MultiTaskElasticNetCV, lm.MultiTaskElasticNetCV)
self.assertIs(df.linear_model.OrthogonalMatchingPursuit, lm.OrthogonalMatchingPursuit)
self.assertIs(df.linear_model.OrthogonalMatchingPursuitCV, lm.OrthogonalMatchingPursuitCV)
self.assertIs(df.linear_model.PassiveAggressiveClassifier, lm.PassiveAggressiveClassifier)
self.assertIs(df.linear_model.PassiveAggressiveRegressor, lm.PassiveAggressiveRegressor)
self.assertIs(df.linear_model.Perceptron, lm.Perceptron)
self.assertIs(df.linear_model.RandomizedLasso, lm.RandomizedLasso)
self.assertIs(df.linear_model.RandomizedLogisticRegression, lm.RandomizedLogisticRegression)
self.assertIs(df.linear_model.RANSACRegressor, lm.RANSACRegressor)
self.assertIs(df.linear_model.Ridge, lm.Ridge)
self.assertIs(df.linear_model.RidgeClassifier, lm.RidgeClassifier)
self.assertIs(df.linear_model.RidgeClassifierCV, lm.RidgeClassifierCV)
self.assertIs(df.linear_model.RidgeCV, lm.RidgeCV)
self.assertIs(df.linear_model.SGDClassifier, lm.SGDClassifier)
self.assertIs(df.linear_model.SGDRegressor, lm.SGDRegressor)
self.assertIs(df.linear_model.TheilSenRegressor, lm.TheilSenRegressor)
示例9: run
# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import RidgeClassifierCV [as 别名]
def run(training_data, test_data, num_runs = 10, num_kernels = 10_000):
results = np.zeros(num_runs)
timings = np.zeros([4, num_runs]) # training transform, test transform, training, test
Y_training, X_training = training_data[:, 0].astype(np.int), training_data[:, 1:]
Y_test, X_test = test_data[:, 0].astype(np.int), test_data[:, 1:]
for i in range(num_runs):
input_length = X_training.shape[1]
kernels = generate_kernels(input_length, num_kernels)
# -- transform training ------------------------------------------------
time_a = time.perf_counter()
X_training_transform = apply_kernels(X_training, kernels)
time_b = time.perf_counter()
timings[0, i] = time_b - time_a
# -- transform test ----------------------------------------------------
time_a = time.perf_counter()
X_test_transform = apply_kernels(X_test, kernels)
time_b = time.perf_counter()
timings[1, i] = time_b - time_a
# -- training ----------------------------------------------------------
time_a = time.perf_counter()
classifier = RidgeClassifierCV(alphas = 10 ** np.linspace(-3, 3, 10), normalize = True)
classifier.fit(X_training_transform, Y_training)
time_b = time.perf_counter()
timings[2, i] = time_b - time_a
# -- test --------------------------------------------------------------
time_a = time.perf_counter()
results[i] = classifier.score(X_test_transform, Y_test)
time_b = time.perf_counter()
timings[3, i] = time_b - time_a
return results, timings
# == run through the bake off datasets =========================================