Python sklearn.linear_model.RidgeClassifierCV() Examples
The following are 9
code examples of sklearn.linear_model.RidgeClassifierCV().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sklearn.linear_model
, or try the search function
.
Example #1
Source File: TermDocMatrix.py From scattertext with Apache License 2.0 | 6 votes |
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
Example #2
Source File: test_sklearn_glm_classifier_converter.py From sklearn-onnx with MIT License | 6 votes |
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')", )
Example #3
Source File: test_sklearn_glm_classifier_converter.py From sklearn-onnx with MIT License | 6 votes |
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')", )
Example #4
Source File: test_sklearn_glm_classifier_converter.py From sklearn-onnx with MIT License | 6 votes |
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')", )
Example #5
Source File: test_sklearn_glm_classifier_converter.py From sklearn-onnx with MIT License | 6 votes |
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')", )
Example #6
Source File: test_sklearn_glm_classifier_converter.py From sklearn-onnx with MIT License | 6 votes |
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')", )
Example #7
Source File: test_Rocket.py From sktime with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #8
Source File: test_linear_model.py From pandas-ml with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #9
Source File: reproduce_experiments_bakeoff.py From rocket with GNU General Public License v3.0 | 4 votes |
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 =========================================