"주식데이터 학습 방법"의 두 판 사이의 차이
DB CAFE
(→주식 데이터 학습 방법) |
|||
43번째 줄: | 43번째 줄: | ||
print(f'Predicted price for new input: {new_output[0]:.2f}') | print(f'Predicted price for new input: {new_output[0]:.2f}') | ||
</source> | </source> | ||
+ | [[category:주식]] | ||
+ | [[category:python]] |
2024년 1월 2일 (화) 00:18 기준 최신판
thumb_up 추천메뉴 바로가기
- DBA { Oracle DBA 명령어 > DBA 초급 과정 > DBA 고급 과정 }
- 튜닝 { 오라클 튜닝 목록 }
- 모델링 { 데이터 모델링 가이드 }
1 주식데이터 학습[편집]
1.1 주식 데이터 학습 방법[편집]
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
# Load the data
df = pd.read_csv('stock_data.csv')
# Split the data into input and target variables
X = df[['volume', 'fluctuation_rate']]
y = df['price']
# Split the data into training and testing sets
train_size = int(len(X) * 0.8)
X_train, X_test = X[:train_size], X[train_size:]
y_train, y_test = y[:train_size], y[train_size:]
# Create a linear regression model
model = LinearRegression()
# Train the model on the training data
model.fit(X_train, y_train)
# Make predictions on the testing data
y_pred = model.predict(X_test)
# Evaluate the performance of the model
mse = mean_squared_error(y_test, y_pred)
rmse = np.sqrt(mse)
r2 = r2_score(y_test, y_pred)
print(f'Mean Squared Error: {mse:.2f}')
print(f'Root Mean Squared Error: {rmse:.2f}')
print(f'R-squared: {r2:.2f}')
# Make a prediction for a new input
new_input = [[1000000, 0.02]]
new_output = model.predict(new_input)
print(f'Predicted price for new input: {new_output[0]:.2f}')