Regression

Regression#

This example demonstrates how use Regression module from the mambular package.

 1# Simulate data
 2import numpy as np
 3import pandas as pd
 4from sklearn.model_selection import train_test_split
 5
 6from mambular.models import MambularRegressor
 7
 8# Set random seed for reproducibility
 9np.random.seed(0)
10
11# Number of samples
12n_samples = 1000
13n_features = 5
14
15# Generate random features
16X = np.random.randn(n_samples, n_features)
17coefficients = np.random.randn(n_features)
18
19# Generate target variable
20y = np.dot(X, coefficients) + np.random.randn(n_samples)
21
22# Create a DataFrame to store the data
23data = pd.DataFrame(X, columns=[f"feature_{i}" for i in range(n_features)])
24data["target"] = y
25
26# Split data into features and target variable
27X = data.drop(columns=["target"])
28y = np.array(data["target"])
29
30
31X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
32
33
34# Instantiate the regressor
35regressor = MambularRegressor()
36
37# Fit the model on training data
38regressor.fit(X_train, y_train, max_epochs=10)
39
40print(regressor.evaluate(X_test, y_test))