Trainstation: Convenient Linear Model Training
Trainstation is a lightweight Python library designed for convenient training and evaluation of linear models. It acts as a simplified wrapper around `scikit-learn`'s linear models, streamlining common workflows. As of version 1.2, it focuses on ease of use for basic linear regression tasks, offering a straightforward API. It has an active release cadence, with minor enhancements and bug fixes.
Common errors
-
ModuleNotFoundError: No module named 'trainstation'
cause The `trainstation` package is not installed in the current Python environment or is not accessible.fixInstall the library using `pip install trainstation`. -
AttributeError: 'LinearModel' object has no attribute 'coef_'
cause You are attempting to access an attribute (like `coef_`, `intercept_`, `n_features_in_`) that belongs to the underlying `scikit-learn` estimator, not the `trainstation.LinearModel` wrapper directly.fixAccess the underlying `sklearn` model via `model.model` and then its attributes, e.g., `model.model.coef_`. -
TypeError: 'LinearModel' object is not callable
cause You are trying to call an instance of `LinearModel` directly, as if it were a function, instead of using its `predict` method for making predictions.fixUse the `predict` method for making predictions, e.g., `predictions = model.predict(X_test)`.
Warnings
- gotcha Accessing underlying `scikit-learn` model attributes (e.g., `coef_`, `intercept_`) directly on the `LinearModel` instance will fail.
- gotcha `trainstation` provides a simplified API and does not directly expose all advanced `scikit-learn` parameters or specific linear model types (e.g., Ridge, Lasso) by default. It's primarily a wrapper for `sklearn.linear_model.LinearRegression`.
- gotcha Data preprocessing steps like handling missing values (NaNs) or feature scaling (e.g., StandardScaler) are not automated by `trainstation`. Input data is expected to be clean and scaled if necessary.
Install
-
pip install trainstation
Imports
- LinearModel
from trainstation import LinearModel
Quickstart
from trainstation import LinearModel
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
# Generate synthetic data
X, y = make_regression(n_samples=1000, n_features=10, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Initialize and train the model
model = LinearModel()
model.fit(X_train, y_train)
# Make predictions and evaluate
predictions = model.predict(X_test)
score = model.evaluate(X_test, y_test)
print(f"Model score: {score:.4f}")