コード例 #1
0
ファイル: knn.py プロジェクト: ChrisChV/Stock_prediction
scaler = MinMaxScaler(feature_range=(0, 1))

data = db_functions.getDb()
add_datepart(data, 'Date')
data.drop('Elapsed', axis=1, inplace=True)

train = data[:987]
valid = data[987:]

x_train = train.drop('Close', axis=1)
y_train = train['Close']
x_valid = valid.drop('Close', axis=1)
y_valid = valid['Close']

x_train_scaled = scaler.fit_transform(x_train)
x_train = pd.DataFrame(x_train_scaled)
x_valid_scaled = scaler.fit_transform(x_valid)
x_valid = pd.DataFrame(x_valid_scaled)

params = {'n_neighbors': [2, 3, 4, 5, 6, 7, 8, 9]}
knn = neighbors.KNeighborsRegressor()
model = GridSearchCV(knn, params, cv=5)

model.fit(x_train, y_train)
prediction = model.predict(x_valid)

print(db_functions.getRMSE(valid, prediction))

db_functions.plot(train, valid, prediction)
コード例 #2
0
from fbprophet import Prophet
import db_functions


data = db_functions.getDb()

data.rename(columns={'Close': 'y', 'Date': 'ds'}, inplace=True)


train = data[:987]
valid = data[987:]

model = Prophet()
model.fit(train)

close_prices = model.make_future_dataframe(periods=len(valid))
forecast = model.predict(close_prices)

forecast_valid = forecast['yhat'][987:]
valid.rename(columns={'y': 'Close'}, inplace=True)
train.rename(columns={'y': 'Close'}, inplace=True)

print(db_functions.getRMSE(valid, forecast_valid))

db_functions.plot(train, valid, forecast_valid)
コード例 #3
0
ファイル: average.py プロジェクト: ChrisChV/Stock_prediction
import db_functions

data = db_functions.getDb()

train = data[:987]
test = data[987:]

predictions = []

for i in range(0, len(test)):
    a = train['Close'][len(train) - len(test) + i:].sum() + sum(predictions)
    b = a / len(test)
    predictions.append(b)

db_functions.plot(train, test, predictions)
print db_functions.getRMSE(test, predictions)