當前位置: 首頁>>代碼示例>>Python>>正文


Python linear_model.ARDRegression類代碼示例

本文整理匯總了Python中sklearn.linear_model.ARDRegression的典型用法代碼示例。如果您正苦於以下問題:Python ARDRegression類的具體用法?Python ARDRegression怎麽用?Python ARDRegression使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ARDRegression類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_check_is_fitted

def test_check_is_fitted():
    # Check is ValueError raised when non estimator instance passed
    assert_raises(ValueError, check_is_fitted, ARDRegression, "coef_")
    assert_raises(TypeError, check_is_fitted, "SVR", "support_")

    ard = ARDRegression()
    svr = SVR()

    try:
        assert_raises(NotFittedError, check_is_fitted, ard, "coef_")
        assert_raises(NotFittedError, check_is_fitted, svr, "support_")
    except ValueError:
        assert False, "check_is_fitted failed with ValueError"

    # NotFittedError is a subclass of both ValueError and AttributeError
    try:
        check_is_fitted(ard, "coef_", "Random message %(name)s, %(name)s")
    except ValueError as e:
        assert_equal(str(e), "Random message ARDRegression, ARDRegression")

    try:
        check_is_fitted(svr, "support_", "Another message %(name)s, %(name)s")
    except AttributeError as e:
        assert_equal(str(e), "Another message SVR, SVR")

    ard.fit(*make_blobs())
    svr.fit(*make_blobs())

    assert_equal(None, check_is_fitted(ard, "coef_"))
    assert_equal(None, check_is_fitted(svr, "support_"))
開發者ID:Afey,項目名稱:scikit-learn,代碼行數:30,代碼來源:test_validation.py

示例2: ARDRegression_on_fold

def ARDRegression_on_fold(feature_sets, train, test, y, y_all, X, dim, dimsum, learn_options):
    '''
    '''
    clf = ARDRegression()
    clf.fit(X[train], y[train][:, 0])
    y_pred = clf.predict(X[test])[:, None]
    return y_pred, clf
開發者ID:pablocarderam,項目名稱:genetargeter,代碼行數:7,代碼來源:regression.py

示例3: fit_model_16

    def fit_model_16(self,toWrite=False):
        model = ARDRegression()

        for data in self.cv_data:
            X_train, X_test, Y_train, Y_test = data
            model.fit(X_train,Y_train)
            pred = model.predict(X_test)
            print("Model 16 score %f" % (logloss(Y_test,pred),))

        if toWrite:
            f2 = open('model16/model.pkl','w')
            pickle.dump(model,f2)
            f2.close()
開發者ID:JakeMick,項目名稱:kaggle,代碼行數:13,代碼來源:days_work.py

示例4: ARDRegression

# Create weigts with a precision lambda_ of 4.
lambda_ = 4.
w = np.zeros(n_features)
# Only keep 10 weights of interest
relevant_features = np.random.randint(0, n_features, 10)
for i in relevant_features:
    w[i] = stats.norm.rvs(loc=0, scale=1. / np.sqrt(lambda_))
# Create noite with a precision alpha of 50.
alpha_ = 50.
noise = stats.norm.rvs(loc=0, scale=1. / np.sqrt(alpha_), size=n_samples)
# Create the target
y = np.dot(X, w) + noise

###############################################################################
# Fit the ARD Regression
clf = ARDRegression(compute_score=True)
clf.fit(X, y)

ols = LinearRegression()
ols.fit(X, y)

###############################################################################
# Plot the true weights, the estimated weights and the histogram of the
# weights
plt.figure(figsize=(6, 5))
plt.title("Weights of the model")
plt.plot(clf.coef_, 'b-', label="ARD estimate")
plt.plot(ols.coef_, 'r--', label="OLS estimate")
plt.plot(w, 'g-', label="Ground truth")
plt.xlabel("Features")
plt.ylabel("Values of the weights")
開發者ID:NicovincX2,項目名稱:Python-3.5,代碼行數:31,代碼來源:ard_ols.py

示例5: ARDRegression

# Create weights with a precision lambda_ of 4.
lambda_ = 4.
w = np.zeros(n_features)
# Only keep 10 weights of interest
relevant_features = np.random.randint(0, n_features, 10)
for i in relevant_features:
    w[i] = stats.norm.rvs(loc=0, scale=1. / np.sqrt(lambda_))
# Create noise with a precision alpha of 50.
alpha_ = 50.
noise = stats.norm.rvs(loc=0, scale=1. / np.sqrt(alpha_), size=n_samples)
# Create the target
y = np.dot(X, w) + noise

###############################################################################
# Fit the ARD Regression
clf = ARDRegression(compute_score=True)
clf.fit(X, y)

ols = LinearRegression()
ols.fit(X, y)

###############################################################################
# Plot the true weights, the estimated weights, the histogram of the
# weights, and predictions with standard deviations
plt.figure(figsize=(6, 5))
plt.title("Weights of the model")
plt.plot(clf.coef_, color='darkblue', linestyle='-', linewidth=2,
         label="ARD estimate")
plt.plot(ols.coef_, color='yellowgreen', linestyle=':', linewidth=2,
         label="OLS estimate")
plt.plot(w, color='orange', linestyle='-', linewidth=2, label="Ground truth")
開發者ID:AlexandreAbraham,項目名稱:scikit-learn,代碼行數:31,代碼來源:plot_ard.py

示例6: Normalizer

    
if __name__ == "__main__":
    
    ########################### Set script paramaters  ###########################
    #Gene expression paramaters
    log10Normalize = True
    standardizeByTCGA = True #Normalize expression data in a unified way for TCGA and cell lines
    L2Normalizer = Normalizer(norm='l2', copy=True) #Method to normalize gene expression values
    
    
    #Gene Pruning parameters
    pruneUncorrelatedGenes = True; #Eliminates genes that are uncorrelated between array and RNASeq
    pruneCutoff = 0.001; #p value cutoff for pruning
    clinicalSplitPoint =  60 #for the array data, the first 60 entries correspond to NCI60 dataset
   
    clf = ARDRegression(normalize=False)

    #Location for training data
    inputFolder = '../output/standardizedData/2015-07-30/'
    docetaxelArrayFolder = '../data/docetaxel_validation/'
    outputFolder = '../output/DocetaxelClinical/' + np.str(date.today()) + '/'

    if not os.path.exists(outputFolder):
            os.makedirs(outputFolder)
    #############################################################################
    
    cellExpression = joblib.load(inputFolder + 'cellExpression.pkl')
    tcgaExpression = joblib.load(inputFolder + 'tcgaExpression.pkl')
    mergedExpression = cellExpression.append(tcgaExpression)
            
    #Retrieves Combat homogonized data for NCI60 cell line and Docetaxel Clincal U95 Array Data
開發者ID:gkoytiger,項目名稱:OncologyOracle,代碼行數:30,代碼來源:validateDocetaxelClinical.py

示例7: learn_model

def learn_model(x_mat, y):
    #model = SVR(kernel='rbf')
    model = ARDRegression()
    model.fit(x_mat, y)
    return model
開發者ID:tchajed,項目名稱:partial-results,代碼行數:5,代碼來源:regression.py

示例8: load_boston

#+++++++++++++++++++++++++++++++++++++++++++++++++
#Importing sklearn, numpy pylab modules 
from sklearn.linear_model import ARDRegression
from sklearn.model_selection import cross_val_predict
from sklearn.datasets import load_boston
from sklearn.metrics import explained_variance_score, mean_squared_error
import numpy as np
import pylab as pl
#Loading boston datasets 
boston = load_boston()
# Creating Regression Design Matrix 
x = boston.data
# Creating target dataset
y = boston.target
# Create ARDRegression Regression object 
ARD= ARDRegression(alpha_1=0.01, alpha_2=0.01, lambda_1=1e-06, lambda_2=1e-06)
# Fitting a linear model using the dataset
ARD.fit(x,y)
# Y predicted values
yp = ARD.predict(x)
#Calculation 10-Fold CV
yp_cv = cross_val_predict(ARD, x, y, cv=10)
#Printing RMSE and Explained Variance
Evariance=explained_variance_score(y,yp)
Evariance_cv=explained_variance_score(y,yp_cv)
RMSE =np.sqrt(mean_squared_error(y,yp))
RMSECV=np.sqrt(mean_squared_error(y,yp_cv))
print('Method: ARDRegression Regression')
print('RMSE on the dataset: %.4f' %RMSE)
print('RMSE on 10-fold CV: %.4f' %RMSECV)
print('Explained Variance Regression Score on the dataset: %.4f' %Evariance)
開發者ID:omoreira,項目名稱:GM-Python-Workbook,代碼行數:31,代碼來源:ARDRegression_boston10foldcv.py


注:本文中的sklearn.linear_model.ARDRegression類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。