当前位置: 首页>>代码示例>>Python>>正文


Python EllipticEnvelope.predict方法代码示例

本文整理汇总了Python中sklearn.covariance.EllipticEnvelope.predict方法的典型用法代码示例。如果您正苦于以下问题:Python EllipticEnvelope.predict方法的具体用法?Python EllipticEnvelope.predict怎么用?Python EllipticEnvelope.predict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.covariance.EllipticEnvelope的用法示例。


在下文中一共展示了EllipticEnvelope.predict方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: plot

# 需要导入模块: from sklearn.covariance import EllipticEnvelope [as 别名]
# 或者: from sklearn.covariance.EllipticEnvelope import predict [as 别名]
def plot(X, y):
    proj = TSNE().fit_transform(X)
    e = EllipticEnvelope(assume_centered=True, contamination=.25) # Outlier detection
    e.fit(X)

    good = np.where(e.predict(X) == 1)
    X = X[good]
    y = y[good]

    scatter(proj, y)
开发者ID:vortext,项目名称:DeepOntology,代码行数:12,代码来源:experiment.py

示例2: test_outlier_detection

# 需要导入模块: from sklearn.covariance import EllipticEnvelope [as 别名]
# 或者: from sklearn.covariance.EllipticEnvelope import predict [as 别名]
def test_outlier_detection():
    """

    """
    rnd = np.random.RandomState(0)
    X = rnd.randn(100, 10)
    clf = EllipticEnvelope(contamination=0.1)
    clf.fit(X)
    y_pred = clf.predict(X)

    assert_array_almost_equal(clf.decision_function(X, raw_mahalanobis=True), clf.mahalanobis(X - clf.location_))
    assert_almost_equal(clf.score(X, np.ones(100)), (100 - y_pred[y_pred == -1].size) / 100.0)
开发者ID:nellaivijay,项目名称:scikit-learn,代码行数:14,代码来源:test_robust_covariance.py

示例3: transform

# 需要导入模块: from sklearn.covariance import EllipticEnvelope [as 别名]
# 或者: from sklearn.covariance.EllipticEnvelope import predict [as 别名]
def transform( features, labels ):

#    for ff, ll in zip(features, labels):
#        print ll, ff
#    for rr in range(0, len(features) ):
#        features[rr] = scaler.fit_transform( features[rr] )

    print "transforming features via pca"
    pca = PCA(n_components = 30)
    features = pca.fit_transform( features )

    envelope = EllipticEnvelope()
    envelope.fit( features )
    print envelope.predict( features )

    scaler = MinMaxScaler()
    features = scaler.fit_transform( features )



    return features, labels
开发者ID:cmmalone,项目名称:um_detector,代码行数:23,代码来源:reader.py

示例4: test_outlier_detection

# 需要导入模块: from sklearn.covariance import EllipticEnvelope [as 别名]
# 或者: from sklearn.covariance.EllipticEnvelope import predict [as 别名]
def test_outlier_detection():
    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)
    decision = clf.decision_function(X, raw_values=True)
    decision_transformed = clf.decision_function(X, raw_values=False)

    assert_array_almost_equal(decision, 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.0)
    assert sum(y_pred == -1) == sum(decision_transformed < 0)
开发者ID:BTY2684,项目名称:scikit-learn,代码行数:17,代码来源:test_robust_covariance.py

示例5: ellipticenvelope

# 需要导入模块: from sklearn.covariance import EllipticEnvelope [as 别名]
# 或者: from sklearn.covariance.EllipticEnvelope import predict [as 别名]
def ellipticenvelope(data, fraction = 0.02):
    elenv = EllipticEnvelope(contamination=fraction)
    elenv.fit(data)
    score = elenv.predict(data)

    numeration = [[i] for i in xrange(1, len(data)+1, 1)]
    numeration = np.array(numeration)
    y = np.hstack((numeration, score))

    anomalies = numeration
    for num,s in y:
        if (y == 1):
            y = np.delete(anomalies, num-1, axis=0)

    return anomalies
开发者ID:bondarchukYV,项目名称:AD,代码行数:17,代码来源:ellipticenvelope.py

示例6: test_elliptic_envelope

# 需要导入模块: from sklearn.covariance import EllipticEnvelope [as 别名]
# 或者: from sklearn.covariance.EllipticEnvelope import predict [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))
开发者ID:AlexisMignon,项目名称:scikit-learn,代码行数:19,代码来源:test_elliptic_envelope.py

示例7: anomaly_detection

# 需要导入模块: from sklearn.covariance import EllipticEnvelope [as 别名]
# 或者: from sklearn.covariance.EllipticEnvelope import predict [as 别名]
def anomaly_detection(features, labels):
	# In this function, I try to use anomaly detection method (using mutivariate gaussian distribution) to identify poi-s
	non_pois = features[labels==0]
	pois = features[labels==1]
	print "non poi size", non_pois.shape, pois.shape, features.shape

	## Spliting data to train, test and cross validation set for anomaly detection

	split1 = produce_spliting_array(non_pois.shape[0], .75 )
	X_train = non_pois[split1==1]

	X_intermediate = non_pois[split1==0]

	print "size intermediate", X_intermediate.shape

	split2 = produce_spliting_array(X_intermediate.shape[0], .5 )

	X_test = X_intermediate[split2==1]
	label_test = np.zeros((X_test.shape[0],), dtype=np.int) - 1

	X_cv = X_intermediate[split2==0]
	label_cv = np.zeros((X_cv.shape[0],), dtype=np.int) - 1

	split3 = produce_spliting_array(pois.shape[0], .5 )
	X_test = np.vstack((X_test, pois[split3==1]))
	label_test = np.hstack((label_test, np.ones(sum(split3), dtype=np.int)))

	X_cv = np.vstack((X_cv, pois[split3==0]))
	label_cv = np.hstack((label_cv, np.ones(sum(split3==0), dtype=np.int)))



	print "size X_train", X_train.shape
	print "size test data", X_test.shape, label_test.shape
	print "size cv data", X_cv.shape, label_cv.shape
	print "size splits", len(split1), len(split2), len(split3)

	from sklearn.covariance import EllipticEnvelope
	detector = EllipticEnvelope(contamination=.85)
	detector.fit(X_train)
	pred_cv = detector.predict(X_cv)
	print pred_cv
	print label_cv
	print detector.score(X_cv, label_cv)
开发者ID:keymanesh,项目名称:Udacity--Intro-to-Data-Science,代码行数:46,代码来源:poi_id.py

示例8: CovEstOD

# 需要导入模块: from sklearn.covariance import EllipticEnvelope [as 别名]
# 或者: from sklearn.covariance.EllipticEnvelope import predict [as 别名]
def CovEstOD(data, classifier=None, N=1, **kw):
    if classifier is None:
        from sklearn.covariance import EllipticEnvelope
        contamination = N / data.shape[0]
        classifier = EllipticEnvelope(support_fraction=1., contamination=contamination)

    classifier.fit(data)
    clipix, = np.where( classifier.predict(data) == -1)
    
    wdb = kw.pop( 'with_decision_boundary', False )
    #TODO:  A better way of finding the decision boundary
    if wdb:
        w,T = np.linalg.eigh( clf.precision_ )          #T (eigenvectors of precision matrix) is the transformation matrix between principle axes and data coordinates
        Ti = np.linalg.inv(T)
        M = np.dot(Ti, clf.precision_) * T              #Diagonalizing the precision matrix ==> quadratic representation of decision boundary (ellipse): z^T M z = threshold. where x-<x> = Tz transforms to principle axes
        a, b = np.sqrt(clf.threshold / np.diag(M))      #semi-major & semi-minor axes
        theta = np.degrees( np.arccos(T[0,0]) )         #T is (im)proper rotation matrix
        theta = np.linalg.det(T) * theta                #If det(T)=-1 ==> improper rotation matrix (rotoinversion - one of the axes is inverted)
        decision_boundary = Ellipse( clf.location_, 2*a, 2*b, theta,  color='m' )
        return clipix, decision_boundary
    else:
        return clipix
开发者ID:apodemus,项目名称:tsa,代码行数:24,代码来源:outliers.py

示例9: status

# 需要导入模块: from sklearn.covariance import EllipticEnvelope [as 别名]
# 或者: from sklearn.covariance.EllipticEnvelope import predict [as 别名]
                'Age',
                'HAART-Naive',
                'HAART-Non-Adherent',
                'HAART-Off',
                'HAART-On',
                'Hepatitis C status (HCV)']
for col in tranfer_cols:
    _, cyto_data[col] = cyto_data.align(pat_data[col], join='left', axis = 0)
cyto_data['HCV'] = cyto_data['Hepatitis C status (HCV)']

# <codecell>

for col in cytos:
    env = EllipticEnvelope(contamination=0.05)
    env.fit(cyto_data[col].dropna().values.reshape(-1, 1))
    mask = env.predict(cyto_data[col].values.reshape(-1,1))
    cyto_data[col][mask==-1] = np.nan

# <codecell>


fig, axs = plt.subplots(11,3, figsize = (10,20))

for ax, col in zip(axs.flatten(), cytos):
    
    boxes = []
    mus = []
    stds = []
    for trop in trops:
        mask = cyto_data['Tropism'] == trop
        #mask &= cyto_data['Keep']
开发者ID:JudoWill,项目名称:ResearchNotebooks,代码行数:33,代码来源:ContinualV3Figures.py

示例10: print

# 需要导入模块: from sklearn.covariance import EllipticEnvelope [as 别名]
# 或者: from sklearn.covariance.EllipticEnvelope import predict [as 别名]
# print(Y)

# Find outliers in the interaction rate data

# Step 1 - Convert the dataset into pandas series
util = Utility.SeriesUtility()
datasetFileName = "fans_change_taylor_swift.csv"
series = util.convertDatasetsToSeries(datasetFileName)

series = util.resampleSeriesSum(series, "D")

numberOfPoints = series.data.shape[0]
X = series.values.flatten().reshape(numberOfPoints,1)

det.fit(X)

predicted = det.predict(X)

for i in range(numberOfPoints):
    outputClass = det.predict(X[i])[0]

    if(outputClass == -1):
        print("Outlier detected...")







开发者ID:rajcscw,项目名称:echo-state-networks,代码行数:25,代码来源:testOutliers.py

示例11: float

# 需要导入模块: from sklearn.covariance import EllipticEnvelope [as 别名]
# 或者: from sklearn.covariance.EllipticEnvelope import predict [as 别名]
    try:
        return float(val)
    except ValueError:
        return np.nan

cytos = ['VEGF','IL-1beta','G-CSF','EGF','IL-10','HGF','FGF-basic',
'IFN-alpha','IL-6','IL-12','Rantes','Eotaxin','IL-13','IL-15',
'IL-17','MIP-1alpha','GM-CSF','MIP-1beta','MCP-1','IL-5',
'IFN-gamma','TNF-alpha','IL-RA','IL-2','IL-7',
'IP-10','IL-2R','MIG','IL-4','IL-8']

for col in cytos:
    data[col] = data[col].map(safe_float)
    try:
        env = EllipticEnvelope().fit(data[col].dropna().values.reshape(-1,1))
        mask = env.predict(data[col].values.reshape(-1,1))
        data[col][mask == -1] = np.nan
    except:
        pass
        
    
    #print mask
    #break
    

# <codecell>

pos = dict(zip('ABCDEFGH', range(8)))
def xpos(val):
    _, p = val.split('(')
    return pos[p.split(',')[1][0]]
开发者ID:JudoWill,项目名称:ResearchNotebooks,代码行数:33,代码来源:KrebbsData.py

示例12: search_outliers_EllipticEnvelope

# 需要导入模块: from sklearn.covariance import EllipticEnvelope [as 别名]
# 或者: from sklearn.covariance.EllipticEnvelope import predict [as 别名]
def search_outliers_EllipticEnvelope(X):
    clf = EllipticEnvelope(contamination=0.2)
    clf.fit(X)
    is_outliers = clf.predict(X)
    return is_outliers
开发者ID:orazaro,项目名称:stumbleupon_kaggle,代码行数:7,代码来源:outliers.py

示例13: range

# 需要导入模块: from sklearn.covariance import EllipticEnvelope [as 别名]
# 或者: from sklearn.covariance.EllipticEnvelope import predict [as 别名]
for i in range(0,len(SectionData)):
    if SectionData['newAngle'][i]==0:
        SectionData['angle'][i]=180
    else:
        SectionData['angle'][i]=SectionData['newAngle'][i]
    x=SectionData['newX'][i]
    y=SectionData['newY'][i]
    SectionData['Distance'][i]=math.sqrt((x*x)+(y*y))
        



#fit the outlier detector to the data and predict
X=SectionData[['angle','newX','newY']]
outlier_detector = EllipticEnvelope(contamination=0.14).fit(X.values)
outliers = outlier_detector.predict(X.values)

#finds outliers
for i in range(0,len(outliers)):
    SectionData['OUTLIER'][i]=outliers[i]
    if outliers[i]==-1:
        print 'outlier at: ',SectionData['center'][i]
        
        
fig = plt.figure(figsize=(20,20))
#plotting the section map 
#outliers indicated on map with larger circles
for i in range(0,len(SectionData)):
    if SectionData['OUTLIER'][i]==-1:
        plt.scatter(SectionData['X'][i],SectionData['Y'][i],s=40)
        plt.annotate(str(int(round(SectionData['gradient_angle'][i],0))),(SectionData['X'][i],SectionData['Y'][i]+5))
开发者ID:eric-xu-ownerIQ,项目名称:DSBC,代码行数:33,代码来源:machine_learning_EricXu.py


注:本文中的sklearn.covariance.EllipticEnvelope.predict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。