강얼쥐와 함께 즐겁게 읽는 AI

신공지능 주식 거래

영웅*^%&$ 2022. 12. 21. 11:14
728x90

import pandas as pd
from sklearn.ensemble import RandomForestClassifier

df = pd.read_csv('training_data.csv')

X = df[['open', 'high', 'low', 'volume']]
y = df['close']

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

model = RandomForestClassifier()
model.fit(X_train, y_train)

accuracy = model.score(X_test, y_test)
print('Accuracy:', accuracy)

new_data = [[100, 105, 98, 1000]]
prediction = model.predict(new_data)
print('Prediction:', prediction)

'''
This code uses a random forest classifier from the sklearn library to train a model 
on a dataset of stock prices. The model is then tested on a separate set of data 
and used to make a prediction on a single example.
'''

728x90