snowflake.ml.modeling.linear_model.RANSACRegressor¶
- class snowflake.ml.modeling.linear_model.RANSACRegressor(*, estimator=None, min_samples=None, residual_threshold=None, is_data_valid=None, is_model_valid=None, max_trials=100, max_skips=inf, stop_n_inliers=inf, stop_score=inf, stop_probability=0.99, loss='absolute_error', random_state=None, input_cols: Optional[Union[str, Iterable[str]]] = None, output_cols: Optional[Union[str, Iterable[str]]] = None, label_cols: Optional[Union[str, Iterable[str]]] = None, drop_input_cols: Optional[bool] = False, sample_weight_col: Optional[str] = None)¶
Bases:
BaseTransformer
RANSAC (RANdom SAmple Consensus) algorithm For more details on this class, see sklearn.linear_model.RANSACRegressor
- estimator: object, default=None
Base estimator object which implements the following methods:
fit(X, y): Fit model to given training data and target values.
score(X, y): Returns the mean accuracy on the given test data, which is used for the stop criterion defined by stop_score. Additionally, the score is used to decide which of two equally large consensus sets is chosen as the better one.
predict(X): Returns predicted values using the linear model, which is used to compute residual error using loss function.
If estimator is None, then
LinearRegression
is used for target values of dtype float.Note that the current implementation only supports regression estimators.
- min_samples: int (>= 1) or float ([0, 1]), default=None
Minimum number of samples chosen randomly from original data. Treated as an absolute number of samples for min_samples >= 1, treated as a relative number ceil(min_samples * X.shape[0]) for min_samples < 1. This is typically chosen as the minimal number of samples necessary to estimate the given estimator. By default a
sklearn.linear_model.LinearRegression()
estimator is assumed and min_samples is chosen asX.shape[1] + 1
. This parameter is highly dependent upon the model, so if a estimator other thanlinear_model.LinearRegression
is used, the user must provide a value.- residual_threshold: float, default=None
Maximum residual for a data sample to be classified as an inlier. By default the threshold is chosen as the MAD (median absolute deviation) of the target values y. Points whose residuals are strictly equal to the threshold are considered as inliers.
- is_data_valid: callable, default=None
This function is called with the randomly selected data before the model is fitted to it: is_data_valid(X, y). If its return value is False the current randomly chosen sub-sample is skipped.
- is_model_valid: callable, default=None
This function is called with the estimated model and the randomly selected data: is_model_valid(model, X, y). If its return value is False the current randomly chosen sub-sample is skipped. Rejecting samples with this function is computationally costlier than with is_data_valid. is_model_valid should therefore only be used if the estimated model is needed for making the rejection decision.
- max_trials: int, default=100
Maximum number of iterations for random sample selection.
- max_skips: int, default=np.inf
Maximum number of iterations that can be skipped due to finding zero inliers or invalid data defined by
is_data_valid
or invalid models defined byis_model_valid
.- stop_n_inliers: int, default=np.inf
Stop iteration if at least this number of inliers are found.
- stop_score: float, default=np.inf
Stop iteration if score is greater equal than this threshold.
- stop_probability: float in range [0, 1], default=0.99
RANSAC iteration stops if at least one outlier-free set of the training data is sampled in RANSAC. This requires to generate at least N samples (iterations):
N >= log(1 - probability) / log(1 - e**m)
where the probability (confidence) is typically set to high value such as 0.99 (the default) and e is the current fraction of inliers w.r.t. the total number of samples.
- loss: str, callable, default=’absolute_error’
String inputs, ‘absolute_error’ and ‘squared_error’ are supported which find the absolute error and squared error per sample respectively.
If
loss
is a callable, then it should be a function that takes two arrays as inputs, the true and predicted value and returns a 1-D array with the i-th value of the array corresponding to the loss onX[i]
.If the loss on a sample is greater than the
residual_threshold
, then this sample is classified as an outlier.- random_state: int, RandomState instance, default=None
The generator used to initialize the centers. Pass an int for reproducible output across multiple function calls. See Glossary.
- input_cols: Optional[Union[str, List[str]]]
A string or list of strings representing column names that contain features. If this parameter is not specified, all columns in the input DataFrame except the columns specified by label_cols and sample-weight_col parameters are considered input columns.
- label_cols: Optional[Union[str, List[str]]]
A string or list of strings representing column names that contain labels. This is a required param for estimators, as there is no way to infer these columns. If this parameter is not specified, then object is fitted without labels(Like a transformer).
- output_cols: Optional[Union[str, List[str]]]
A string or list of strings representing column names that will store the output of predict and transform operations. The length of output_cols mus match the expected number of output columns from the specific estimator or transformer class used. If this parameter is not specified, output column names are derived by adding an OUTPUT_ prefix to the label column names. These inferred output column names work for estimator’s predict() method, but output_cols must be set explicitly for transformers.
- sample_weight_col: Optional[str]
A string representing the column name containing the examples’ weights. This argument is only required when working with weighted datasets.
- drop_input_cols: Optional[bool], default=False
If set, the response of predict(), transform() methods will not contain input columns.
Methods
fit
(dataset)Fit estimator using RANSAC algorithm For more details on this function, see sklearn.linear_model.RANSACRegressor.fit
predict
(dataset)Predict using the estimated model For more details on this function, see sklearn.linear_model.RANSACRegressor.predict
score
(dataset)Return the score of the prediction For more details on this function, see sklearn.linear_model.RANSACRegressor.score
set_input_cols
(input_cols)Input columns setter.
to_sklearn
()Get sklearn.linear_model.RANSACRegressor object.
Attributes
model_signatures
Returns model signature of current class.