gtime.regressors.LinearRegressor¶
-
class
gtime.regressors.LinearRegressor(loss=<function mean_squared_error>)¶ Implementation of a LinearRegressor that takes a custom loss function.
Parameters: - loss : Callable, optional, default:
mean_squared_error The loss function to use when fitting the model. The loss function must accept y_true, y_pred and return a single real number.
Examples
>>> from gtime.regressors.linear_regressor import LinearRegressor >>> from gtime.metrics import max_error >>> import numpy as np >>> import pandas as pd >>> X = np.random.random((100, 10)) >>> y = np.random.random(100) >>> lr = LinearRegressor(loss=max_error) >>> X_train, y_train = X[:90], y[:90] >>> X_test, y_test = X[90:], y[90:] >>> x0 = [0]*11 >>> lr.fit(X_train, y_train, x0=x0) >>> lr.predict(X_test) array([0.62987155, 0.46971378, 0.50421395, 0.5543149 , 0.50848151, 0.54768797, 0.50968854, 0.50500384, 0.58069366, 0.54912972])
Methods
fit(self, X, y, \*\*kwargs)Fit the linear model on Xandyon the given loss function.To do the minimization, thescipy.optimize.minimizefunction is used.predict(self, X)Predict the y values associated to the features X.-
__init__(self, loss=<function mean_squared_error at 0x7f5c9a835b70>)¶ Initialize self. See help(type(self)) for accurate signature.
-
fit(self, X: pandas.core.frame.DataFrame, y: pandas.core.frame.DataFrame, **kwargs) → 'LinearRegressor'¶ Fit the linear model on
Xandyon the given loss function.To do the minimization, thescipy.optimize.minimizefunction is used. To have more details and check which kind of options are available, please refer to the scipy documentation.Parameters: - X : pd.DataFrame, shape (n_samples, n_features), required
The X matrix used as features in the fitting procedure.
- y : pd.DataFrame, shape (n_samples, 1), required
The y matrix to use as target values in the fitting procedure.
- kwargs: dict, optional.
Optional arguments to pass to the
minimizefunction of scipy.
Returns: - self: LinearRegressor
The fitted model.
-
predict(self, X: pandas.core.frame.DataFrame) → pandas.core.frame.DataFrame¶ Predict the y values associated to the features
X.Parameters: - X : pd.DataFrame, shape (n_samples, n_features), required
The features used to predict.
Returns: - predictions : pd.DataFrame, shape (n_samples, 1)
The predictions of the model
- loss : Callable, optional, default: