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