本文整理汇总了Python中sklearn.cross_decomposition.PLSRegression.predict_proba方法的典型用法代码示例。如果您正苦于以下问题:Python PLSRegression.predict_proba方法的具体用法?Python PLSRegression.predict_proba怎么用?Python PLSRegression.predict_proba使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.cross_decomposition.PLSRegression
的用法示例。
在下文中一共展示了PLSRegression.predict_proba方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fit_base_model
# 需要导入模块: from sklearn.cross_decomposition import PLSRegression [as 别名]
# 或者: from sklearn.cross_decomposition.PLSRegression import predict_proba [as 别名]
def fit_base_model(classifiers, fully, dummyY, trainx, testx):
""" Takes a list of classifiers and/or PLS regression and
does dimension reduction by returning the predictions of the classifiers
or first two scores of the PLS regression on bootstrapped subsamples of
the data."""
trainProbs = []
testProbs = []
iterations = 0
for clf in classifiers:
for i in range(clf[1]):
iterations += 1
print(iterations)
print(clf[0])
train_rows = np.random.choice(trainx.shape[0],
round(trainx.shape[0] * base_prop),
True)
oob_rows = list(set(range(trainx.shape[0])) - set(train_rows))
print(len(train_rows))
print(len(oob_rows))
x = trainx[train_rows, :]
if clf[0] == 'PLS':
y = dummyY[train_rows, :]
mod = PLSRegression().fit(x, y)
trainscores = mod.transform(trainx)
testscores = mod.transform(testx)
trainProbs.append(trainscores[:, 0])
trainProbs.append(trainscores[:, 1])
testProbs.append(testscores[:, 0])
testProbs.append(testscores[:, 1])
else:
y = fully[train_rows]
print('\t Fitting model...')
mod = clf[0].fit(x, y)
print('\t Predicting training results...')
tpreds = mod.predict_proba(trainx)
trainProbs.append(list(tpreds[:, 1]))
print('\t Predicting test results...')
testProbs.append(list(mod.predict_proba(testx)[:, 1]))
print('\t OOB score: ' + str(log_loss(fully[oob_rows],
tpreds[oob_rows, :])))
return trainProbs, testProbs