PLS回歸是一個回歸方法,考慮到在兩個數據集中的潛結構。偏最小二乘回歸在兩個single-label和multi-label學習的原因基於MRI的評估表現良好。 PLSRegression從PLS獲取與模式=” A”和deflation_mode =”回歸”。另外,在一維響應的情況下,已知的PLS2或PLS。
用法:class sklearn.cross_decomposition.PLSRegression(n_components=2, *, scale=True, max_iter=500, tol=1e-06, copy=True)
參數:
該函數接受被上述和下麵定義的五個參數:
- n_components:<int>:其默認值為2,它接受需要保留的組件數。
- 規模:<布爾>:其缺省值為True,並且它接受是否縮放數據或沒有。
- max_iteran:<int>的:它的默認值是500,並且它接受NIPALS內部循環迭代的最大數量。
- 收費:<非負實數>:其默認值為1e-06,它接受迭代算法中使用的容差。
- 複製:<bool>:其默認值為True,它表明應該對副本進行偏轉。當默認值設置為true不要在意副作用。
返回值:PLSRegression是預測響應的方法。
在下麵的實施例說明了如何使用PLSRegression()模型。
例:
Python3
import numpy as np
import pandas as pd
from sklearn import datasets
import matplotlib.pyplot as plt
from sklearn.cross_decomposition import PLSRegression
from sklearn.model_selection import train_test_split
# load boston data using sklearn datasets
boston = datasets.load_boston()
# seprate data and target values
x = boston.data
y = boston.target
# tabular data structure with labeled axes
# (rows and columns) using DataFrame
df_x = pd.DataFrame(x, columns=boston.feature_names)
df_y = pd.DataFrame(y)
# create PLSRegression model
pls2 = PLSRegression(n_components=2)
# split data
x_train, x_test, y_train, y_test = train_test_split(
df_x, df_y, test_size=0.30, random_state=1)
# fit the model
pls2.fit(x_train, y_train)
# predict the values
Y_pred = pls2.predict(x_test)
# plot the predicted Values
plt.plot(Y_pred)
plt.xticks(rotation=90)
plt.show()
# print the predicted value
print(Y_pred)
輸出:
使用PLSRegression繪製預測值
使用訓練模型打印的預測值
相關用法
- Python Wand function()用法及代碼示例
- Python Sorted()用法及代碼示例
- Python Numbers choice()用法及代碼示例
- Python Tkinter askopenfile()用法及代碼示例
- Python ord()用法及代碼示例
- Python sum()用法及代碼示例
- Python round()用法及代碼示例
- Python id()用法及代碼示例
- Python vars()用法及代碼示例
注:本文由純淨天空篩選整理自adityakumar27200大神的英文原創作品 sklearn.cross_decomposition.PLSRegression() function in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。