本文整理汇总了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)
示例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)
示例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
示例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)
示例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_')
示例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)
示例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'
示例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)