23 lines
625 B
Python
23 lines
625 B
Python
from sklearn.ensemble import RandomForestRegressor
|
|
from sklearn.metrics import r2_score, mean_absolute_error
|
|
import pandas as pd
|
|
|
|
# Données d'exemple
|
|
df = pd.DataFrame({
|
|
'sma5': [1, 2, 3, 4, 5],
|
|
'sma24': [2, 2, 2, 3, 4],
|
|
'close': [100, 102, 101, 105, 108]
|
|
})
|
|
df['future_gain'] = (df['close'].shift(-1) - df['close']) / df['close']
|
|
|
|
X = df[['sma5', 'sma24']][:-1]
|
|
y = df['future_gain'][:-1]
|
|
|
|
model = RandomForestRegressor(n_estimators=200, random_state=42)
|
|
model.fit(X, y)
|
|
y_pred = model.predict(X)
|
|
|
|
print("R²:", r2_score(y, y_pred))
|
|
print("MAE:", mean_absolute_error(y, y_pred))
|
|
print("Prédictions :", y_pred)
|