本文整理匯總了Python中sklearn.covariance.EllipticEnvelope方法的典型用法代碼示例。如果您正苦於以下問題:Python covariance.EllipticEnvelope方法的具體用法?Python covariance.EllipticEnvelope怎麽用?Python covariance.EllipticEnvelope使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sklearn.covariance
的用法示例。
在下文中一共展示了covariance.EllipticEnvelope方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_elliptic_envelope
# 需要導入模塊: from sklearn import covariance [as 別名]
# 或者: from sklearn.covariance import EllipticEnvelope [as 別名]
def test_elliptic_envelope():
rnd = np.random.RandomState(0)
X = rnd.randn(100, 10)
clf = EllipticEnvelope(contamination=0.1)
assert_raises(NotFittedError, clf.predict, X)
assert_raises(NotFittedError, clf.decision_function, X)
clf.fit(X)
y_pred = clf.predict(X)
scores = clf.score_samples(X)
decisions = clf.decision_function(X)
assert_array_almost_equal(
scores, -clf.mahalanobis(X))
assert_array_almost_equal(clf.mahalanobis(X), clf.dist_)
assert_almost_equal(clf.score(X, np.ones(100)),
(100 - y_pred[y_pred == -1].size) / 100.)
assert(sum(y_pred == -1) == sum(decisions < 0))
示例2: initialize_fact_model
# 需要導入模塊: from sklearn import covariance [as 別名]
# 或者: from sklearn.covariance import EllipticEnvelope [as 別名]
def initialize_fact_model(self):
# Extract all RASA training sentences for all facts
rasa_fact_paths = glob.glob(self.RASA_FACT_DIR + '*.json')
all_sentences = []
for fact_path in rasa_fact_paths:
with open(fact_path, 'r') as f:
file_json = json.loads(f.read().encode('utf-8'))
for example in file_json['rasa_nlu_data']['common_examples']:
all_sentences.append(example['text'].lower())
# TF-IDF model
tfidf_vectorizer = TfidfVectorizer(ngram_range=self.NGRAM_RANGE, strip_accents='ascii')
X_tfidf = tfidf_vectorizer.fit_transform(all_sentences)
# Fit to robust covariance estimation
outlier_estimator = EllipticEnvelope(contamination=self.CONTAMINATION)
outlier_estimator.fit(X_tfidf.toarray())
# Binarize for future use
with open(self.TFIFD_PICKLE_FILE, 'wb') as f:
joblib.dump(tfidf_vectorizer, f, compress=True)
with open(self.OUTLIER_PICKLE_FILE, 'wb') as f:
joblib.dump(outlier_estimator, f, compress=True)
示例3: fit_pipe
# 需要導入模塊: from sklearn import covariance [as 別名]
# 或者: from sklearn.covariance import EllipticEnvelope [as 別名]
def fit_pipe(self, X, y=None):
self.elliptic_envelope_ = EllipticEnvelope(**self.get_params())
self.elliptic_envelope_.fit(X)
return self.transform_pipe(X, y)
示例4: __init__
# 需要導入模塊: from sklearn import covariance [as 別名]
# 或者: from sklearn.covariance import EllipticEnvelope [as 別名]
def __init__(self, _id, _config):
super(EllipticEnvelope, self).__init__(_id, _config)
self._nb_samples = int(_config['nb_samples'])
示例5: get_default_config
# 需要導入模塊: from sklearn import covariance [as 別名]
# 或者: from sklearn.covariance import EllipticEnvelope [as 別名]
def get_default_config():
return {
'module': EllipticEnvelope.__name__,
'nb_samples': N_SAMPLES
}
示例6: _get_best_detector
# 需要導入模塊: from sklearn import covariance [as 別名]
# 或者: from sklearn.covariance import EllipticEnvelope [as 別名]
def _get_best_detector(self, train):
detector = covariance.EllipticEnvelope()
detector.fit(train)
return detector
示例7: setUp
# 需要導入模塊: from sklearn import covariance [as 別名]
# 或者: from sklearn.covariance import EllipticEnvelope [as 別名]
def setUp(self):
super(TestEllipticEnvelope, self).setUp()
self.ee_sml = elliptic_envelope.EllipticEnvelope(
"fakeid", {"module": "fake", "nb_samples": 1000})
示例8: test_learn_structure
# 需要導入模塊: from sklearn import covariance [as 別名]
# 或者: from sklearn.covariance import EllipticEnvelope [as 別名]
def test_learn_structure(self):
data = self.get_testing_data()
clf = self.ee_sml.learn_structure(data)
self.assertIsInstance(clf, covariance.EllipticEnvelope)
示例9: test_score_samples
# 需要導入模塊: from sklearn import covariance [as 別名]
# 或者: from sklearn.covariance import EllipticEnvelope [as 別名]
def test_score_samples():
X_train = [[1, 1], [1, 2], [2, 1]]
clf1 = EllipticEnvelope(contamination=0.2).fit(X_train)
clf2 = EllipticEnvelope().fit(X_train)
assert_array_equal(clf1.score_samples([[2., 2.]]),
clf1.decision_function([[2., 2.]]) + clf1.offset_)
assert_array_equal(clf2.score_samples([[2., 2.]]),
clf2.decision_function([[2., 2.]]) + clf2.offset_)
assert_array_equal(clf1.score_samples([[2., 2.]]),
clf2.score_samples([[2., 2.]]))
示例10: test_raw_values_deprecation
# 需要導入模塊: from sklearn import covariance [as 別名]
# 或者: from sklearn.covariance import EllipticEnvelope [as 別名]
def test_raw_values_deprecation():
X = [[0.0], [1.0]]
clf = EllipticEnvelope().fit(X)
assert_warns_message(DeprecationWarning,
"raw_values parameter is deprecated in 0.20 and will"
" be removed in 0.22.",
clf.decision_function, X, raw_values=True)
示例11: test_threshold_deprecation
# 需要導入模塊: from sklearn import covariance [as 別名]
# 或者: from sklearn.covariance import EllipticEnvelope [as 別名]
def test_threshold_deprecation():
X = [[0.0], [1.0]]
clf = EllipticEnvelope().fit(X)
assert_warns_message(DeprecationWarning,
"threshold_ attribute is deprecated in 0.20 and will"
" be removed in 0.22.",
getattr, clf, "threshold_")
示例12: test_objectmapper
# 需要導入模塊: from sklearn import covariance [as 別名]
# 或者: from sklearn.covariance import EllipticEnvelope [as 別名]
def test_objectmapper(self):
df = pdml.ModelFrame([])
self.assertIs(df.covariance.EmpiricalCovariance, covariance.EmpiricalCovariance)
self.assertIs(df.covariance.EllipticEnvelope, covariance.EllipticEnvelope)
self.assertIs(df.covariance.GraphLasso, covariance.GraphLasso)
self.assertIs(df.covariance.GraphLassoCV, covariance.GraphLassoCV)
self.assertIs(df.covariance.LedoitWolf, covariance.LedoitWolf)
self.assertIs(df.covariance.MinCovDet, covariance.MinCovDet)
self.assertIs(df.covariance.OAS, covariance.OAS)
self.assertIs(df.covariance.ShrunkCovariance, covariance.ShrunkCovariance)
self.assertIs(df.covariance.shrunk_covariance, covariance.shrunk_covariance)
self.assertIs(df.covariance.graph_lasso, covariance.graph_lasso)