股票预测 day4 过拟合

import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
from sklearn.pipeline import Pipeline
from sklearn.model_selection import train_test_split
from sklearn.svm import LinearSVR,SVR
import pandas as pd
import tensorflow as tf
from tensorflow.keras import layers
from sklearn.preprocessing import MinMaxScaler
from tensorflow.keras.layers import Dropout, Dense, SimpleRNN


df2=pd.read_csv('F:\\股票预测code\\hs300_stock_predict-master\\000895.csv',encoding='UTF-8')
df1=df2.iloc[:,1:]
print(df1.head())
print(df1.shape)

len=3

result_x=df1[0:len].values.flatten()
result_y=[]
for i in range(1,df1.shape[0]-len):
 sub=np.mat(df1[i:i+len].values.flatten())
 result_x=np.vstack((result_x,sub))

for i in range(0, df1.shape[0] - len):
 rate=(df1['close'][i+len]-df1['close'][i+len-1])/df1['close'][i+len-1]
 result_y.append(rate)

x=result_x.A

y=np.array(result_y)
print(type(x))
print(type(y))
print(y)

print(x.shape)
print(y.shape)

X_train,X_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=666)#利用train_test_split进行将训练集和测试集进行分开,test_size占20%



# 归一化
sc = MinMaxScaler(feature_range=(0, 1))  # 定义归一化:归一化到(0,1)之间
training_set_scaled = sc.fit_transform(X_train)  # 求得训练集的最大值,最小值这些训练集固有的属性,并在训练集上进行归一化
test_set = sc.transform(X_test)  # 利用训练集的属性对测试集进行归一化
print(test_set.shape)


# 归一化
sc_y = MinMaxScaler(feature_range=(0, 1))  # 定义归一化:归一化到(0,1)之间
training_set_scaled_y = sc_y.fit_transform(y_train.reshape(-1,1))  # 求得训练集的最大值,最小值这些训练集固有的属性,并在训练集上进行归一化
test_set_y = sc_y.transform(y_test.reshape(-1,1))  # 利用训练集的属性对测试集进行归一化

# model=tf.keras.Sequential()
# model.add(layers.Dense(42,input_shape=(df1.shape
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值