pub struct PyLinearRegression { /* private fields */ }Expand description
Ordinary least squares Linear Regression.
LinearRegression fits a linear model with coefficients w = (w1, …, wp) to minimize the residual sum of squares between the observed targets in the dataset, and the targets predicted by the linear approximation.
§Parameters
fit_intercept : bool, default=True Whether to calculate the intercept for this model. If set to False, no intercept will be used in calculations (i.e. data is expected to be centered).
copy_X : bool, default=True If True, X will be copied; else, it may be overwritten.
n_jobs : int, default=None
The number of jobs to use for the computation. This will only provide
speedup in case of sufficiently large problems, that is if firstly
n_targets > 1 and secondly X is sparse or if positive is set
to True. None means 1 unless in a
:obj:joblib.parallel_backend context. -1 means using all
processors.
positive : bool, default=False
When set to True, forces the coefficients to be positive. This
option is only supported for dense arrays.
§Attributes
coef_ : array of shape (n_features,) or (n_targets, n_features) Estimated coefficients for the linear regression problem. If multiple targets are passed during the fit (y 2D), this is a 2D array of shape (n_targets, n_features), while if only one target is passed, this is a 1D array of length n_features.
intercept_ : float or array of shape (n_targets,)
Independent term in the linear model. Set to 0.0 if
fit_intercept = False.
n_features_in_ : int
Number of features seen during :term:fit.
§Examples
import numpy as np from sklears_python import LinearRegression X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
§y = 1 * x_0 + 2 * x_1 + 3
y = np.dot(X, [1, 2]) + 3 reg = LinearRegression().fit(X, y) reg.score(X, y) 1.0 reg.coef_ array([1., 2.]) reg.intercept_ 3.0… reg.predict(np.array([[3, 5]])) array([16.])
§Notes
From the implementation point of view, this is just plain Ordinary Least Squares (scipy.linalg.lstsq) or Non Negative Least Squares (scipy.optimize.nnls) wrapped as a predictor object.
Trait Implementations§
Source§impl<'py> IntoPyObject<'py> for PyLinearRegression
impl<'py> IntoPyObject<'py> for PyLinearRegression
Source§type Target = PyLinearRegression
type Target = PyLinearRegression
Source§type Output = Bound<'py, <PyLinearRegression as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <PyLinearRegression as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PyClass for PyLinearRegression
impl PyClass for PyLinearRegression
Source§impl PyClassImpl for PyLinearRegression
impl PyClassImpl for PyLinearRegression
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = /// Ordinary least squares Linear Regression.
///
/// LinearRegression fits a linear model with coefficients w = (w1, ..., wp)
/// to minimize the residual sum of squares between the observed targets in
/// the dataset, and the targets predicted by the linear approximation.
///
/// Parameters
/// ----------
/// fit_intercept : bool, default=True
/// Whether to calculate the intercept for this model. If set
/// to False, no intercept will be used in calculations
/// (i.e. data is expected to be centered).
///
/// copy_X : bool, default=True
/// If True, X will be copied; else, it may be overwritten.
///
/// n_jobs : int, default=None
/// The number of jobs to use for the computation. This will only provide
/// speedup in case of sufficiently large problems, that is if firstly
/// `n_targets > 1` and secondly `X` is sparse or if `positive` is set
/// to `True`. ``None`` means 1 unless in a
/// :obj:`joblib.parallel_backend` context. ``-1`` means using all
/// processors.
///
/// positive : bool, default=False
/// When set to ``True``, forces the coefficients to be positive. This
/// option is only supported for dense arrays.
///
/// Attributes
/// ----------
/// coef_ : array of shape (n_features,) or (n_targets, n_features)
/// Estimated coefficients for the linear regression problem.
/// If multiple targets are passed during the fit (y 2D), this
/// is a 2D array of shape (n_targets, n_features), while if only
/// one target is passed, this is a 1D array of length n_features.
///
/// intercept_ : float or array of shape (n_targets,)
/// Independent term in the linear model. Set to 0.0 if
/// `fit_intercept = False`.
///
/// n_features_in_ : int
/// Number of features seen during :term:`fit`.
///
/// Examples
/// --------
/// >>> import numpy as np
/// >>> from sklears_python import LinearRegression
/// >>> X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
/// >>> # y = 1 * x_0 + 2 * x_1 + 3
/// >>> y = np.dot(X, [1, 2]) + 3
/// >>> reg = LinearRegression().fit(X, y)
/// >>> reg.score(X, y)
/// 1.0
/// >>> reg.coef_
/// array([1., 2.])
/// >>> reg.intercept_
/// 3.0...
/// >>> reg.predict(np.array([[3, 5]]))
/// array([16.])
///
/// Notes
/// -----
/// From the implementation point of view, this is just plain Ordinary
/// Least Squares (scipy.linalg.lstsq) or Non Negative Least Squares
/// (scipy.optimize.nnls) wrapped as a predictor object.
const RAW_DOC: &'static CStr = /// Ordinary least squares Linear Regression. /// /// LinearRegression fits a linear model with coefficients w = (w1, ..., wp) /// to minimize the residual sum of squares between the observed targets in /// the dataset, and the targets predicted by the linear approximation. /// /// Parameters /// ---------- /// fit_intercept : bool, default=True /// Whether to calculate the intercept for this model. If set /// to False, no intercept will be used in calculations /// (i.e. data is expected to be centered). /// /// copy_X : bool, default=True /// If True, X will be copied; else, it may be overwritten. /// /// n_jobs : int, default=None /// The number of jobs to use for the computation. This will only provide /// speedup in case of sufficiently large problems, that is if firstly /// `n_targets > 1` and secondly `X` is sparse or if `positive` is set /// to `True`. ``None`` means 1 unless in a /// :obj:`joblib.parallel_backend` context. ``-1`` means using all /// processors. /// /// positive : bool, default=False /// When set to ``True``, forces the coefficients to be positive. This /// option is only supported for dense arrays. /// /// Attributes /// ---------- /// coef_ : array of shape (n_features,) or (n_targets, n_features) /// Estimated coefficients for the linear regression problem. /// If multiple targets are passed during the fit (y 2D), this /// is a 2D array of shape (n_targets, n_features), while if only /// one target is passed, this is a 1D array of length n_features. /// /// intercept_ : float or array of shape (n_targets,) /// Independent term in the linear model. Set to 0.0 if /// `fit_intercept = False`. /// /// n_features_in_ : int /// Number of features seen during :term:`fit`. /// /// Examples /// -------- /// >>> import numpy as np /// >>> from sklears_python import LinearRegression /// >>> X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]]) /// >>> # y = 1 * x_0 + 2 * x_1 + 3 /// >>> y = np.dot(X, [1, 2]) + 3 /// >>> reg = LinearRegression().fit(X, y) /// >>> reg.score(X, y) /// 1.0 /// >>> reg.coef_ /// array([1., 2.]) /// >>> reg.intercept_ /// 3.0... /// >>> reg.predict(np.array([[3, 5]])) /// array([16.]) /// /// Notes /// ----- /// From the implementation point of view, this is just plain Ordinary /// Least Squares (scipy.linalg.lstsq) or Non Negative Least Squares /// (scipy.optimize.nnls) wrapped as a predictor object.
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type ThreadChecker = SendablePyClass<PyLinearRegression>
type ThreadChecker = SendablePyClass<PyLinearRegression>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyClassNewTextSignature for PyLinearRegression
impl PyClassNewTextSignature for PyLinearRegression
const TEXT_SIGNATURE: &'static str = "(fit_intercept=True, copy_x=True, n_jobs=None, positive=False)"
Source§impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder PyLinearRegression
impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder PyLinearRegression
Source§impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder mut PyLinearRegression
impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder mut PyLinearRegression
Source§impl PyMethods<PyLinearRegression> for PyClassImplCollector<PyLinearRegression>
impl PyMethods<PyLinearRegression> for PyClassImplCollector<PyLinearRegression>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for PyLinearRegression
impl PyTypeInfo for PyLinearRegression
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Source§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
impl DerefToPyAny for PyLinearRegression
Auto Trait Implementations§
impl Freeze for PyLinearRegression
impl RefUnwindSafe for PyLinearRegression
impl Send for PyLinearRegression
impl Sync for PyLinearRegression
impl Unpin for PyLinearRegression
impl UnwindSafe for PyLinearRegression
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
Source§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.