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


Python PassiveAggressiveRegressor.fit方法代碼示例

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


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

示例1: test_regressor_mse

# 需要導入模塊: from sklearn.linear_model import PassiveAggressiveRegressor [as 別名]
# 或者: from sklearn.linear_model.PassiveAggressiveRegressor import fit [as 別名]
def test_regressor_mse():
    y_bin = y.copy()
    y_bin[y != 1] = -1

    for data in (X, X_csr):
        for fit_intercept in (True, False):
            reg = PassiveAggressiveRegressor(C=1.0, n_iter=50,
                                             fit_intercept=fit_intercept,
                                             random_state=0)
            reg.fit(data, y_bin)
            pred = reg.predict(data)
            assert_less(np.mean((pred - y_bin) ** 2), 1.7)
開發者ID:Big-Data,項目名稱:scikit-learn,代碼行數:14,代碼來源:test_passive_aggressive.py

示例2: test_regressor_correctness

# 需要導入模塊: from sklearn.linear_model import PassiveAggressiveRegressor [as 別名]
# 或者: from sklearn.linear_model.PassiveAggressiveRegressor import fit [as 別名]
def test_regressor_correctness(loss):
    y_bin = y.copy()
    y_bin[y != 1] = -1

    reg1 = MyPassiveAggressive(
        C=1.0, loss=loss, fit_intercept=True, n_iter=2)
    reg1.fit(X, y_bin)

    for data in (X, X_csr):
        reg2 = PassiveAggressiveRegressor(
            C=1.0, tol=None, loss=loss, fit_intercept=True, max_iter=2,
            shuffle=False)
        reg2.fit(data, y_bin)

        assert_array_almost_equal(reg1.w, reg2.coef_.ravel(), decimal=2)
開發者ID:allefpablo,項目名稱:scikit-learn,代碼行數:17,代碼來源:test_passive_aggressive.py

示例3: fancy_text_model

# 需要導入模塊: from sklearn.linear_model import PassiveAggressiveRegressor [as 別名]
# 或者: from sklearn.linear_model.PassiveAggressiveRegressor import fit [as 別名]
def fancy_text_model(x_train, y_train, x_test, x_valid, cache_name, use_cache=False):
    if use_cache:
        fhand = open(cache_name, 'r')
        data_dict = pickle.load(fhand)
        return data_dict['test_pred'], data_dict['valid_pred']
    np.random.seed(seed=123)
    model = PassiveAggressiveRegressor(n_iter=100, C=1, shuffle=True, random_state=123)
    model.fit(x_train, y_train)
    test_pred = model.predict(x_test)
    valid_pred = model.predict(x_valid)
    data_dict = {'test_pred': test_pred, 'valid_pred': valid_pred}
    fhand = open(cache_name, 'w')
    pickle.dump(data_dict, fhand)
    fhand.close()
    return test_pred, valid_pred
開發者ID:JakeMick,項目名稱:kaggle-bulldozer,代碼行數:17,代碼來源:model.py

示例4: test_regressor_correctness

# 需要導入模塊: from sklearn.linear_model import PassiveAggressiveRegressor [as 別名]
# 或者: from sklearn.linear_model.PassiveAggressiveRegressor import fit [as 別名]
def test_regressor_correctness():
    y_bin = y.copy()
    y_bin[y != 1] = -1

    for loss in ("epsilon_insensitive", "squared_epsilon_insensitive"):
        reg1 = MyPassiveAggressive(C=1.0,
                                   loss=loss,
                                   fit_intercept=True,
                                   n_iter=2)
        reg1.fit(X, y_bin)

        reg2 = PassiveAggressiveRegressor(C=1.0,
                                          loss=loss,
                                          fit_intercept=True,
                                          n_iter=2)
        reg2.fit(X, y_bin)

        assert_array_almost_equal(reg1.w, reg2.coef_.ravel(), decimal=2)
開發者ID:dengemann,項目名稱:scikit-learn,代碼行數:20,代碼來源:test_passive_aggressive.py

示例5: test_regressor_mse

# 需要導入模塊: from sklearn.linear_model import PassiveAggressiveRegressor [as 別名]
# 或者: from sklearn.linear_model.PassiveAggressiveRegressor import fit [as 別名]
def test_regressor_mse():
    y_bin = y.copy()
    y_bin[y != 1] = -1

    for data in (X, X_csr):
        for fit_intercept in (True, False):
            for average in (False, True):
                reg = PassiveAggressiveRegressor(
                    C=1.0, fit_intercept=fit_intercept,
                    random_state=0, average=average, max_iter=5)
                reg.fit(data, y_bin)
                pred = reg.predict(data)
                assert_less(np.mean((pred - y_bin) ** 2), 1.7)
                if average:
                    assert hasattr(reg, 'average_coef_')
                    assert hasattr(reg, 'average_intercept_')
                    assert hasattr(reg, 'standard_intercept_')
                    assert hasattr(reg, 'standard_coef_')
開發者ID:allefpablo,項目名稱:scikit-learn,代碼行數:20,代碼來源:test_passive_aggressive.py

示例6: PassiveAggressiveRegressor

# 需要導入模塊: from sklearn.linear_model import PassiveAggressiveRegressor [as 別名]
# 或者: from sklearn.linear_model.PassiveAggressiveRegressor import fit [as 別名]

quesparse = quevectorizer.fit_transform(question)
topsparse = topvectorizer.fit_transform(topics)
cfscaled = cfscaler.transform(contextfollowers)
tfscaled = tfscaler.transform(topicsfollowers)

tquesparse = quevectorizer.transform(tquestion)
ttopsparse = topvectorizer.transform(ttopics)
tcfscaled = cfscaler.transform(tcontextfollowers)
ttfscaled = tfscaler.transform(ttopicsfollowers)



par = PassiveAggressiveRegressor()
par.fit(topsparse,y)
pred = par.predict(ttopsparse)
pred[pred<0] = 0


temp = pl.figure("train y")
temp = pl.subplot(2,1,1)
temp = pl.hist(y,1000)
temp = pl.subplot(2,1,2)
yy = y.copy()
yy[yy==0] = 1
temp = pl.hist(np.log10(yy),1000)

temp = pl.figure("test y")
temp = pl.subplot(4,1,1)
temp = pl.hist(pred,1000)
開發者ID:syllogismos,項目名稱:QuoraMLCodeSprint2013,代碼行數:32,代碼來源:views.py

示例7: ElasticNet

# 需要導入模塊: from sklearn.linear_model import PassiveAggressiveRegressor [as 別名]
# 或者: from sklearn.linear_model.PassiveAggressiveRegressor import fit [as 別名]
br_sts_scores = br.predict(xt)


# Elastic Net
print 'elastic net'
enr = ElasticNet()
#enr.fit(x[:, np.newaxis], y)
#enr_sts_scores = enr.predict(xt[:, np.newaxis])
enr.fit(x, y)
enr_sts_scores = enr.predict(xt)


# Passive Aggressive Regression
print 'passive aggressive'
par = PassiveAggressiveRegressor()
par.fit(x, y)
par_sts_scores = par.predict(xt)
#par.fit(x[:, np.newaxis], y)
#par_sts_scores = par.predict(xt[:, np.newaxis])

# RANSAC Regression
print 'ransac'
ransac = RANSACRegressor()
#ransac.fit(x[:, np.newaxis], y)
#ransac_sts_scores = ransac.predict(xt[:, np.newaxis])
ransac.fit(x, y)
ransac_sts_scores = ransac.predict(xt)


# Logistic Regression
print 'logistic'
開發者ID:BinbinBian,項目名稱:USAAR-SemEval-2015,代碼行數:33,代碼來源:carolling-old.py

示例8: print

# 需要導入模塊: from sklearn.linear_model import PassiveAggressiveRegressor [as 別名]
# 或者: from sklearn.linear_model.PassiveAggressiveRegressor import fit [as 別名]
print("Training Models")

m1 = Ridge(normalize=True, alpha=0.001, solver='auto')
m2 = Lasso(normalize=False, alpha=0.0001, selection='cyclic',positive=False)
m3 = ElasticNet(normalize=False, alpha=0.0001,positive=False, l1_ratio = 0.2)
m4 = PassiveAggressiveRegressor(epsilon=0.001, C=100, shuffle=True)
m5 = LinearRegression()

m1.fit(Xtrain, Ytrain)
print("Model 1 Finished")
m2.fit(Xtrain, Ytrain)
print("Model 2 Finished")
m3.fit(Xtrain, Ytrain)
print("Model 3 Finished")
m4.fit(Xtrain, Ytrain)
print("Model 4 Finished")
m5.fit(Xtrain, Ytrain)
print("Model 5 Finished")


models = [m1, m2, m3, m4, m5]

X = np.zeros((Xtest.shape[0], 5))
Xt = np.zeros((Xtr.shape[0], 5))
for i in range(len(models)):
	y = models[i].predict(Xtest)
	X[:,i] = np.ravel(y)
	Xt[:,i] = models[i].predict(Xtr)
	submit = pd.DataFrame(data={'id': ids, 'quality': Yhat})
	submit.to_csv('./submissions/ensemble_m_'+str(i)+'.csv', index = False)
開發者ID:jaredawebb,項目名稱:rate_my_prof,代碼行數:32,代碼來源:ens_model.py


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