Python 如何在scikit学习中使用多元回归进行分类
我有一个多元回归,我用它将波段绘制成散点图,如下所示。该函数获取指数、收益率和收益率列中的投资组合列表,并在其周围放置1&2个标准差带。现在,我想重新调整相同回归的用途,并返回位于不同阴影区域的行列表Python 如何在scikit学习中使用多元回归进行分类,python,pandas,scikit-learn,regression,classification,Python,Pandas,Scikit Learn,Regression,Classification,我有一个多元回归,我用它将波段绘制成散点图,如下所示。该函数获取指数、收益率和收益率列中的投资组合列表,并在其周围放置1&2个标准差带。现在,我想重新调整相同回归的用途,并返回位于不同阴影区域的行列表 import pandas as pd import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker as plticker import matplotlib.ticker as mticker impor
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as plticker
import matplotlib.ticker as mticker
import seaborn as sns
def all_scatter_charter(df):
plt.figure(figsize=(12,8))
#create sets for the polynomial regression and the bands
df = df.loc[:,['returns','vol']]
df.dropna(how='any',inplace=True)
x = df['vol']
y = df['returns']
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42)
x_train = x_train.values.reshape(-1, 1)
y_train = y_train.values.reshape(-1, 1)
y_train = y_train[x_train[:,0].argsort()]
x_train = x_train[x_train[:, 0].argsort()]
poly = PolynomialFeatures(degree=2)
x_poly = poly.fit_transform(x_train)
poly_reg = LinearRegression()
poly_reg.fit(x_poly, y_train)
#get STD of Y axis
std_y_axis = y.std()
y2 = poly_reg.predict(x_poly)+std_y_axis
y1 = poly_reg.predict(x_poly)-std_y_axis
y4 = poly_reg.predict(x_poly)+(std_y_axis*2)
y3 = poly_reg.predict(x_poly)-(std_y_axis*2)
y2 = y2.reshape(-1)
y1 = y1.reshape(-1)
y3 = y3.reshape(-1)
y4 = y4.reshape(-1)
x_train = x_train.reshape(-1)
#create chart
plt.fill_between(x_train,y1,y2,color='#3A5675',alpha=0.3)
plt.fill_between(x_train,y3,y4,color='#3A5675',alpha=0.1)
ax = sns.scatterplot(data=df,y=df['returns'],x=df['vol']\
,s=120,marker='o',alpha=0.3)
n = 200
df = pd.DataFrame(dict(
A=np.random.randint(1, 600, size=n),
B=np.random.randint(1, 1700, size=n)
))
df.columns = ['returns','vol']
all_scatter_charter(df)
对于阴影以上的任何点,我想返回'> 2SD ',在顶部光阴影> 1SD”中,在中间“中间”,在下阴影中只是一个凸点…有人有线索吗?我认为关键是从算法中提取直线方程,我知道如何使用线性回归而不是多元回归。。。