用sklearn 线性回归拟合股票的开盘价和收盘价 pandas、python

股票数据下载:http://quotes.money.163.com/trade/lsjysj_600508.html#01b07  在查询右边有个“下载数据”

# @Time      :2020/6/2 18:07
# @Author    :yaoxingtian

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression

data = pd.read_csv('600508.csv',encoding='gb2312')
# print(data['换手率'])
plt.figure(figsize=(16,16 ))
plt.scatter(x=data['收盘价'],y=data['开盘价'],c='black')
plt.xlabel('money spend on tv ads')
plt.ylabel('sales')
plt.show()
X = data['收盘价'].values.reshape(-1,1)
y = data['开盘价'].values.reshape(-1,1) # (6,) ==>(6,1)
reg = LinearRegression()
reg.fit(X, y)
print("The linear model is: Y = {:.5} + {:.5}X".format(reg.intercept_[0], reg.coef_[0][0]))
# print(reg.intercept_)
# print(reg.coef_)

结果:

The linear model is: Y = 0.027029 + 0.99736X

数据分布:

用sklearn 线性回归拟合股票的开盘价和收盘价 pandas、python_第1张图片

 

 

你可能感兴趣的:(用sklearn 线性回归拟合股票的开盘价和收盘价 pandas、python)