Skip to main content

A package for solar power prediction using LSTM in TensorFlow

Project description

AI-Driven Solar Power Prediction

Overview

This project focuses on forecasting solar power generation using LSTM (Long Short-Term Memory) neural networks and a Dense (fully connected) model. The goal is to improve solar energy efficiency, optimize power output, and predict inverter failures.

Features

  • Time Series Forecasting: Uses past energy production data to predict future output.
  • LSTM Model: Captures temporal dependencies in power generation.
  • Dense Model: Provides a baseline for comparison.
  • Scalability: Easily deployable for real-time applications.
  • Preprocessing: Automated data normalization and feature engineering.

Dataset

The dataset contains solar plant energy readings with the following key features:

  • DATE_TIME (Timestamp of the reading)
  • DC_POWER (Generated DC power in kW)
  • AC_POWER (Generated AC power in kW)
  • DAILY_YIELD (Cumulative yield per day in kWh)
  • TOTAL_YIELD (Total cumulative energy generation in kWh)

Installation

Ensure you have Python 3.8+ installed, then install the required packages:

pip install numpy pandas tensorflow scikit-learn

Usage

1. Train the Model

Run the following command to train the LSTM model:

from solar_power import train_model
model, scaler = train_model("data.csv")

This will:

  • Load and preprocess the dataset.
  • Train the LSTM model.
  • Save the trained model as solar_power_lstm.keras.

2. Predict Power Output

After training, you can use the trained model for predictions:

import numpy as np
from tensorflow.keras.models import load_model

def predict_future_power(model_path, input_data):
    model = load_model(model_path)
    input_data = np.array(input_data).reshape(1, 24, -1)  # Reshape for LSTM
    return model.predict(input_data)

predicted_power = predict_future_power("solar_power_lstm.keras", sample_input)
print("Predicted Power Output:", predicted_power)

Model Architecture

LSTM Model

def build_lstm_model(input_shape):
    model = Sequential([
        Input(shape=input_shape),
        LSTM(64, return_sequences=True),
        Dropout(0.2),
        LSTM(32, return_sequences=False),
        Dropout(0.2),
        Dense(16, activation='relu'),
        Dense(1)
    ])
    model.compile(optimizer='adam', loss='mse')
    return model
  • LSTM layers capture time-series dependencies.
  • Dropout layers prevent overfitting.
  • Dense layers refine predictions.

Dense Model (Baseline)

def build_dense_model(input_shape):
    model = Sequential([
        Input(shape=input_shape),
        Dense(128, activation='relu'),
        Dropout(0.2),
        Dense(64, activation='relu'),
        Dropout(0.2),
        Dense(32, activation='relu'),
        Dense(1)
    ])
    model.compile(optimizer='adam', loss='mse')
    return model

Performance Optimization

To reduce training time:

  1. Use a smaller batch size (e.g., batch_size=16).
  2. Enable GPU acceleration with TensorFlow (tensorflow-gpu).
  3. Apply XLA optimization:
    import tensorflow as tf
    tf.config.optimizer.set_jit(True)
    
  4. Use Early Stopping to stop training when validation loss stops improving:
    from tensorflow.keras.callbacks import EarlyStopping
    early_stopping = EarlyStopping(monitor='val_loss', patience=3, restore_best_weights=True)
    

Future Improvements

  • Real-time deployment using Flask/FastAPI.
  • Integration with IoT sensors for real-time solar panel monitoring.
  • Hybrid models combining CNNs and LSTMs for better accuracy.

License

This project is licensed under the MIT License.


🚀 Start optimizing solar energy production today!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file solar_power_prediction_tensorflow_lstm_model-0.1.1.tar.gz.

File metadata

File hashes

Hashes for solar_power_prediction_tensorflow_lstm_model-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2969530c418147554b62d4f385e96bf09cd58949eb93e541e6f11a4f883bdb27
MD5 c4e7f985f4f2777f29e31f47704d33ea
BLAKE2b-256 3ebd9a6b43849ed85ffc53eca910360bd36b44e129039d38dd791c480b69061a

See more details on using hashes here.

File details

Details for the file solar_power_prediction_tensorflow_lstm_model-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for solar_power_prediction_tensorflow_lstm_model-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aafcbbe6db70636ed3346127575c91d9fbf54635aad4e5ad0ed1fa3ef6dd9aa9
MD5 da124bf4628b415ee54773a67a1624d0
BLAKE2b-256 21bbbf04c9e106ba87c6dcc82cc68a5b884b4d69380d7ed62f5178727ba8853d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page