fivedreg Package¶
- class fivedreg.DataLoader(data_path: str)[source]
Bases:
object- __init__(data_path: str)[source]
Initialize DataLoader with path to pickle file.
- Args:
data_path: Path to the pickle file containing the dataset dictionary
- load_data() Dict[str, Any][source]
Load data from pickle file.
Expected format: {
‘X’: numpy array of shape (n_samples, n_features), ‘y’: numpy array of shape (n_samples,), ‘metadata’: dict with dataset information
}
- Returns:
Dictionary containing ‘X’, ‘y’, and ‘metadata’ keys
- get_data_summary(data: Dict[str, Any]) Dict[str, Any][source]
Get a structured summary of the data dictionary.
- Args:
data: Dictionary with ‘X’, ‘y’, and ‘metadata’ keys
- Returns:
Dictionary containing structured summary data
- class fivedreg.LightweightNN(hidden_layers: List[int] = [64, 32, 16], learning_rate: float = 0.001, max_iter: int = 1000, activation: str = 'relu', output_activation: str | None = None, random_state: int | None = None, verbose: int = 0)[source]
Bases:
objectA lightweight neural network using TensorFlow with configurable architecture.
Designed for fast training on CPU (< 1 minute for datasets up to 10,000 samples). Works with 5D pandas DataFrame input data.
- Parameters:
hidden_layers (list of int, default=[64, 32, 16]) – Number of neurons in each hidden layer. The number of layers is determined by the length of this list.
learning_rate (float, default=0.001) – Learning rate for the optimizer.
max_iter (int, default=1000) – Maximum number of training iterations (epochs).
activation (str, default='relu') – Activation function for hidden layers (‘relu’, ‘tanh’, ‘sigmoid’).
output_activation (str, default=None) – Activation function for output layer. None means linear activation.
random_state (int, default=None) – Random seed for reproducibility.
verbose (int, default=0) – Verbosity level. 0 = silent, 1 = progress updates.
- model
The compiled TensorFlow Keras model.
- Type:
tf.keras.Model
- is_fitted_
Whether the model has been fitted to data.
- Type:
bool
- input_dim_
Number of input features (determined during fit).
- Type:
int
- output_dim_
Number of output features (determined during fit).
- Type:
int
Examples
>>> import pandas as pd >>> import numpy as np >>> from fiveD_NN.neural_network import LightweightNN >>> >>> # Create sample 5D data >>> X = pd.DataFrame(np.random.randn(1000, 5)) >>> y = pd.DataFrame(np.random.randn(1000, 1)) >>> >>> # Initialize and train model >>> model = LightweightNN(hidden_layers=[64, 32, 16], learning_rate=0.001, max_iter=500) >>> model.fit(X, y) >>> >>> # Make predictions >>> predictions = model.predict(X)
- __init__(hidden_layers: List[int] = [64, 32, 16], learning_rate: float = 0.001, max_iter: int = 1000, activation: str = 'relu', output_activation: str | None = None, random_state: int | None = None, verbose: int = 0)[source]
- reset_keras()[source]
Reset the Keras session to clear memory and avoid memory leaks.
- fit(X: DataFrame | ndarray, y: DataFrame | ndarray, early_stopping: bool = True, vs: float | None = None) LightweightNN[source]
Train the neural network on the provided data.
- Parameters:
X (pd.DataFrame or np.ndarray) – Training input features (n_samples, n_features). For 5D_NN package, this should be 5 features.
y (pd.DataFrame or np.ndarray) – Training target values (n_samples, n_outputs).
early_stopping (bool, default=True) – Whether to use early stopping during training. If True, training will stop early if the loss does not improve for a certain number of epochs.
vs (float, optional, default=None) – Validation split ratio. If None, no validation split is performed. If a float, indicates the proportion of data to use for validation (must be < 1.0).
- Returns:
self – Returns self for method chaining.
- Return type:
Examples
>>> import pandas as pd >>> import numpy as np >>> from fiveD_NN.neural_network import LightweightNN >>> >>> X = pd.DataFrame(np.random.randn(1000, 5)) >>> y = pd.DataFrame(np.random.randn(1000, 1)) >>> model = LightweightNN(max_iter=500) >>> model.fit(X, y) >>> # Disable early stopping >>> model.fit(X, y, early_stopping=False) >>> # Use validation split >>> model.fit(X, y, vs=0.2)
- get_history() History[source]
Get the training history.
- Returns:
history – Training history.
- Return type:
keras.callbacks.History
- predict(X: DataFrame | ndarray) ndarray[source]
Make predictions using the trained model.
- Parameters:
X (pd.DataFrame or np.ndarray) – Input features for prediction (n_samples, n_features).
- Returns:
predictions – Predicted values (n_samples, n_outputs).
- Return type:
np.ndarray
- Raises:
ValueError – If the model has not been fitted yet.
Examples
>>> import pandas as pd >>> import numpy as np >>> from fiveD_NN.neural_network import LightweightNN >>> >>> X_train = pd.DataFrame(np.random.randn(1000, 5)) >>> y_train = pd.DataFrame(np.random.randn(1000, 1)) >>> X_test = pd.DataFrame(np.random.randn(100, 5)) >>> >>> model = LightweightNN(max_iter=500) >>> model.fit(X_train, y_train) >>> predictions = model.predict(X_test)
- set_params(**params)[source]
Set model parameters.
- Parameters:
**params (dict) – Parameter names and values to set.
- Returns:
self – Returns self for method chaining.
- Return type: