Ajout analyse de données par réseau neuronal
This commit is contained in:
62
src/app.py
62
src/app.py
@@ -8,6 +8,13 @@ import joblib
|
||||
from io import TextIOWrapper
|
||||
from ydata_profiling import ProfileReport
|
||||
|
||||
# model
|
||||
from sklearn.model_selection import train_test_split
|
||||
from sklearn.preprocessing import StandardScaler
|
||||
from tensorflow.keras.models import Sequential
|
||||
from tensorflow.keras.layers import Dense
|
||||
from tensorflow.keras.utils import plot_model
|
||||
|
||||
app = Flask(__name__)
|
||||
FREQTRADE_USERDATA_DIR = '/mnt/external'
|
||||
|
||||
@@ -121,6 +128,43 @@ def read_feather(filename):
|
||||
# dataframe['min200'] = talib.MIN(dataframe['close'], timeperiod=200)
|
||||
# dataframe['max200'] = talib.MAX(dataframe['close'], timeperiod=200)
|
||||
|
||||
# Choisir les colonnes techniques comme variables d'entrée (X)
|
||||
feature_cols = ['rsi', 'sma20', 'sma5_1h', 'volume']
|
||||
df = dataframe
|
||||
# Variable cible
|
||||
df['target'] = df['futur_price_1h']
|
||||
|
||||
# Supprimer les lignes avec des NaN
|
||||
df.dropna(subset=feature_cols + ['target'], inplace=True)
|
||||
|
||||
X = df[feature_cols].values
|
||||
y = df['target'].values
|
||||
|
||||
# Normalisation
|
||||
scaler = StandardScaler()
|
||||
X = scaler.fit_transform(X)
|
||||
|
||||
# Split
|
||||
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
|
||||
|
||||
# Modèle
|
||||
model = Sequential([
|
||||
Dense(64, input_dim=X.shape[1], activation='relu'),
|
||||
Dense(32, activation='relu'),
|
||||
Dense(1) # Prédiction continue
|
||||
])
|
||||
|
||||
model.compile(optimizer='adam', loss='mse', metrics=['mae'])
|
||||
|
||||
# Entraînement
|
||||
model.fit(X_train, y_train, epochs=50, batch_size=32, validation_data=(X_test, y_test))
|
||||
|
||||
loss, mae = model.evaluate(X_test, y_test)
|
||||
print(f"Erreur moyenne absolue : {mae:.4f}")
|
||||
|
||||
model.summary()
|
||||
|
||||
plot_model(model, show_shapes=True, show_layer_names=True, to_file=FREQTRADE_USERDATA_DIR + "/reports/model.png")
|
||||
return dataframe.to_json(orient="records")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
@@ -185,6 +229,24 @@ def get_chart_data():
|
||||
|
||||
return df.to_json(orient="records") #jsonify(chart_data)
|
||||
|
||||
@app.route('/model')
|
||||
def show_model():
|
||||
# Créer un exemple de modèle si non encore généré
|
||||
model_path = FREQTRADE_USERDATA_DIR + "/reports/model.png"
|
||||
if not os.path.exists(model_path):
|
||||
model = Sequential([
|
||||
Dense(64, input_shape=(6,), activation='relu'),
|
||||
Dense(32, activation='relu'),
|
||||
Dense(1)
|
||||
])
|
||||
plot_model(model, to_file=model_path, show_shapes=True, show_layer_names=True)
|
||||
return render_template('model.html', model_image=model_path)
|
||||
|
||||
# Route pour servir les fichiers statiques (optionnelle si bien configuré)
|
||||
@app.route('/static/<path:filename>')
|
||||
def static_files(filename):
|
||||
return send_from_directory('static', filename)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0', port=5000)
|
||||
|
||||
Reference in New Issue
Block a user