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


Python ElasticNet.score方法代码示例

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


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

示例1: enet

# 需要导入模块: from sklearn.linear_model import ElasticNet [as 别名]
# 或者: from sklearn.linear_model.ElasticNet import score [as 别名]
def enet(a):
    print ("Doing elastic net")
    clf3 = ElasticNet(alpha=a)
    clf3.fit(base_X, base_Y)
    print ("Score = %f" % clf3.score(base_X, base_Y))
    clf3_pred = clf3.predict(X_test)
    write_to_file("elastic.csv", clf3_pred)
开发者ID:abbylyons,项目名称:181practicals,代码行数:9,代码来源:enetTests.py

示例2: enet_granger_causality_test

# 需要导入模块: from sklearn.linear_model import ElasticNet [as 别名]
# 或者: from sklearn.linear_model.ElasticNet import score [as 别名]
def enet_granger_causality_test(X_t, y_t, top_df, max_iter=10000000):
    """
    Return the cv-parameters tested across the whole data
    :param X_t:
    :param y_t:
    :param top_df:
    :return: res_df, test_betas
    """

    test_errs = np.zeros(len(top_df))
    scores = np.zeros(len(top_df))
    dfs = np.zeros(len(top_df))

    test_coefs = np.zeros((len(top_df), X_t.shape[1]))
    for i in range(len(top_df)):
        alpha = top_df.iloc[i]["alpha"]
        lambda_min = top_df.iloc[i]["lambda.min"]
        enet = ElasticNet(l1_ratio=alpha, alpha=lambda_min, max_iter=max_iter)
        enet.fit(X_t, y_t)
        y_pred = enet.predict(X_t)
        test_errs[i] = np.average((y_t - y_pred)**2)
        scores[i] = enet.score(X_t, y_t)
        test_coefs[i] = enet.coef_

        dfs[i] = len(np.where(enet.coef_)[0])

    top_df["test_err"] = test_errs
    top_df["score"] = scores
    top_df["df"] = dfs


    return top_df, test_coefs
开发者ID:lujonathanh,项目名称:v-causal-snps,代码行数:34,代码来源:CausalTests.py

示例3: ElasticNet

# 需要导入模块: from sklearn.linear_model import ElasticNet [as 别名]
# 或者: from sklearn.linear_model.ElasticNet import score [as 别名]
# ElasticNet Regression
import numpy as np
from sklearn import datasets
from sklearn.linear_model import ElasticNet
# load the diabetes datasets
dataset = datasets.load_diabetes()
# fit a model to the data
model = ElasticNet(alpha=0.1)
model.fit(dataset.data, dataset.target)
print(model)
# make predictions
expected = dataset.target
predicted = model.predict(dataset.data)
# summarize the fit of the model
mse = np.mean((predicted-expected)**2)
print(mse)
print(model.score(dataset.data, dataset.target))
开发者ID:marionleborgne,项目名称:machine_learning,代码行数:19,代码来源:elastic_net.py

示例4: ElasticNet

# 需要导入模块: from sklearn.linear_model import ElasticNet [as 别名]
# 或者: from sklearn.linear_model.ElasticNet import score [as 别名]
net = ElasticNet(alpha=1.5)
lasso = Lasso(alpha=5)
ridge = Ridge(alpha=3)
lr = LinearRegression()
dtr = DecisionTreeRegressor(max_depth=17)
bagger = BaggingRegressor(net, verbose = 1)

X_train, X_test, y_train, y_test = train_test_split(X_model, y)

dtr.fit(X_train,y_train)
dtr.score(X_test, y_test)
pred = dtr.predict(X_test)
plt.scatter(y_test, (pred*0.8)-y_test)

net.fit(X_train, y_train)
net.score(X_test, y_test)
preds = net.predict(X_test)
plt.scatter(y_test, (preds) - y_test, alpha = 0.7)

scores = cross_val_score(net, scale(X_model), y, cv=12)
scores.mean()

X2 = pivoted[['compilation_0', 'compilation_1', 'compilation_2']]
y2 = pivoted.compilation_3

X_train, X_test, y_train, y_test = train_test_split(X2, y2, test_size=0.2)

lr.fit(X_train, y_train)
lr.score(X_test, y_test)
pivoted.head()
mapped_pivot = pd.read_csv('pivot_catcherr.csv')
开发者ID:cl65610,项目名称:GABBERT,代码行数:33,代码来源:catcherr.py

示例5: fit_linear_model

# 需要导入模块: from sklearn.linear_model import ElasticNet [as 别名]
# 或者: from sklearn.linear_model.ElasticNet import score [as 别名]
def fit_linear_model(X, y, results, keys,
                     alpha = np.logspace(-5,2,50),
                     l1_ratio = np.array([.1, .5, .7, .9, .95, .99, 1]),
                     num_cv = 5, 
                     verbose = False, 
                     intercept_scaling = 10,
                     plot_results = False, 
                     labels = None
                     ):
    X = pp.scale(X)
    clf = []
    R2 = []
    coef = []
    prob = []
    score = []
    group_keys = []
    if num_cv > 1:
        num_cv2 = num_cv
    else:
        num_cv2 = 10
    # Find best alpha and lambda
    if (np.size(alpha)>1) or (np.size(l1_ratio)>1):
        print "Determining best values for L1 ratio and alpha..."
        clf_temp = ENCV(
                    l1_ratio = l1_ratio,
                    alphas = alpha,
                    cv = num_cv2,
                    fit_intercept = False,
                    verbose = verbose
                    )
        clf_temp.fit(X,y)
        best_alpha = clf_temp.alpha_
        best_l1_ratio = clf_temp.l1_ratio_
        print "Best L1 ratio: " + str(best_l1_ratio) + ", best alpha: " + str(best_alpha)
    else:
        best_alpha = alpha
        best_l1_ratio = l1_ratio
    # Now do cross-validation to estimate accuracy
    if num_cv > 1:
        if labels == None:
            kf = KFold(n = len(y), n_folds = num_cv)
        else:
            kf = LOLO(labels)
        #
        for train, test in kf:
            X_train, X_test, y_train, y_test, results_test, keys_test = X[train], X[test], y[train], y[test], results[test], keys[test]
            clf_temp2 = EN(
                            l1_ratio = best_l1_ratio,
                            alpha = best_alpha,
                            fit_intercept = False)
            clf_temp2.fit(X_train,y_train)
            pred = clf_temp2.predict(X_test)
            clf.append(clf_temp2)
            R2.append(clf_temp2.score(X_test,y_test))
            coef.append(clf_temp2.coef_)
            prob.append(diff_to_prob(pred))
            score.append(lossFx(results_test,pred))
            group_keys.append(keys_test)
    else:
        clf_temp2 = EN(
                l1_ratio = best_l1_ratio,
                alpha = best_alpha,
                fit_intercept = False)
        clf_temp2.fit(X,y)
        pred = clf_temp2.predict(X)
        clf = clf_temp2
        R2 = clf_temp2.score(X,y)
        coef = clf_temp2.coef_
        prob = diff_to_prob(pred)
        score = lossFx(results,pred)
        group_keys = keys
    if num_cv > 1:
        return clf, R2, score, coef, prob, kf, group_keys
    else:
        return clf, R2, score, coef, prob, group_keys
开发者ID:pnlawlor,项目名称:Mad_Kegel,代码行数:77,代码来源:fit_GLM.py

示例6: print

# 需要导入模块: from sklearn.linear_model import ElasticNet [as 别名]
# 或者: from sklearn.linear_model.ElasticNet import score [as 别名]
# print ('final score: ' + str(np.mean(final_score)))

# mean_coef = final_coef/10
# mean_intercept = np.mean(final_intercept)


# lin_reg.coef_ = mean_coef
# lin_reg.intercept_ = mean_intercept


# LABEL NEW ERROR TICKET LABELS ON EXISTING DATA

y_new = lin_reg.predict(X_test)

# print(lin_reg.coef_)
print('final score for linear Elastic Net: ' + str(lin_reg.score(X_test, y_test)))


# DEFINITION FOR ERROR TICKET

rate = 0.7
lower = y_new * (1-rate)
result = np.expand_dims((np.squeeze(y_test) - lower) < 0, axis=1)


# results = np.array(results)
# plt.scatter(X_test, y_test, color='black', s=1)
# plt.plot(X_test, y_new, color='blue')
# plt.ylabel('price (USD)')
# plt.xlabel('week score')
# plt.xticks()
开发者ID:tderosa,项目名称:flydeal,代码行数:33,代码来源:linear_regression.py


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