rfflearn.cpu.RFFRegression
Regression with random Fourier features.
def rfflearn.cpu.RFFRegression(self, dim_kernel=16, std_kernel=0.1, W=None, b=None, **args)
Parameters:
dim_kernel: int (default=16)
Dimension of the random matrix.
std_kernel: float (default=0.1)
Standard deviation of the random matrix.
W: np.ndarray (default=None)
Random matrix for the input X. If None then generated automatically.
b: np.ndarray (default=None)
Random bias for the input X. If None then generated automatically.
args: dict (default={})
Extra arguments. This arguments will be passed to the constructor of scikit-learn's LinearRegression model directly.
Attributes:
dim: int
Dimension of the random matrix.
s_k: float
Standard deviation of the random matrix.
mat: Callable
A function to generate the random matrix W.
W: np.ndarray
Random matrix for the input X.
b: np.ndarray
Random bias for the input X.
Member functions
def fit(self, X, y, **args)
Trains the RFF regression model according to the given data.
Parameters:
X: np.ndarray
Input matrix with shape (n_samples, n_features_input).
y: np.ndarray
Output vector with shape (n_samples,).
args: dict (default={})
Extra arguments. This arguments will be passed to the sklearn's fit function.
Returns:
rfflearn.cpu.RFFRegression
Fitted estimator.
def predict(self, X, **args)
Performs prediction on the given data.
Parameters:
X: np.ndarray
Input matrix with shape (n_samples, n_features_input).
args: dict (default={})
Extra arguments. This arguments will be passed to the sklearn's predict function directly.
Returns:
np.ndarray
Predicted vector.
def score(self, X, y, **args)
Returns the R2 score (coefficient of determination) of the prediction.
Parameters:
X: np.ndarray
Input matrix with shape (n_samples, n_features_input).
y: np.ndarray
True output vector with shape (n_samples,).
args: dict (default={})
Extra arguments. This arguments will be passed to sklearn's score function.
Returns:
float
R2 score of the prediction.
Minimal Example
>>> import numpy as np
>>> import rfflearn.cpu as rfflearn
>>> X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])
>>> y = np.array([1, 1, 2, 2])
>>> reg = rfflearn.RFFRegression().fit(X, y)
>>> reg.score(X, y)
1.0
>>> reg.predict(np.array([[-0.8, -1]]))
array([1.00065865])