ML之LiR&Lasso:基于datasets糖尿病数据集利用LiR和Lasso算法进行(9→1)回归预测(三维图散点图可视化)

简介: ML之LiR&Lasso:基于datasets糖尿病数据集利用LiR和Lasso算法进行(9→1)回归预测(三维图散点图可视化)

设计思路

image.png


输出结果

image.png

image.png

image.png

image.png

Lasso核心代码


class Lasso Found at: sklearn.linear_model._coordinate_descent

class Lasso(ElasticNet):

   """Linear Model trained with L1 prior as regularizer (aka the Lasso)

 

   The optimization objective for Lasso is::

 

   (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1

 

   Technically the Lasso model is optimizing the same objective function as

   the Elastic Net with ``l1_ratio=1.0`` (no L2 penalty).

 

   Read more in the :ref:`User Guide <lasso>`.

 

   Parameters

   ----------

   alpha : float, default=1.0

   Constant that multiplies the L1 term. Defaults to 1.0.

   ``alpha = 0`` is equivalent to an ordinary least square, solved

   by the :class:`LinearRegression` object. For numerical

   reasons, using ``alpha = 0`` with the ``Lasso`` object is not advised.

   Given this, you should use the :class:`LinearRegression` object.

 

   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).

 

   normalize : bool, default=False

   This parameter is ignored when ``fit_intercept`` is set to False.

   If True, the regressors X will be normalized before regression by

   subtracting the mean and dividing by the l2-norm.

   If you wish to standardize, please use

   :class:`sklearn.preprocessing.StandardScaler` before calling ``fit``

   on an estimator with ``normalize=False``.

 

   precompute : 'auto', bool or array-like of shape (n_features, n_features),\

   default=False

   Whether to use a precomputed Gram matrix to speed up

   calculations. If set to ``'auto'`` let us decide. The Gram

   matrix can also be passed as argument. For sparse input

   this option is always ``True`` to preserve sparsity.

 

   copy_X : bool, default=True

   If ``True``, X will be copied; else, it may be overwritten.

 

   max_iter : int, default=1000

   The maximum number of iterations

 

   tol : float, default=1e-4

   The tolerance for the optimization: if the updates are

   smaller than ``tol``, the optimization code checks the

   dual gap for optimality and continues until it is smaller

   than ``tol``.

 

   warm_start : bool, default=False

   When set to True, reuse the solution of the previous call to fit as

   initialization, otherwise, just erase the previous solution.

   See :term:`the Glossary <warm_start>`.

 

   positive : bool, default=False

   When set to ``True``, forces the coefficients to be positive.

 

   random_state : int, RandomState instance, default=None

   The seed of the pseudo random number generator that selects a

    random

   feature to update. Used when ``selection`` == 'random'.

   Pass an int for reproducible output across multiple function calls.

   See :term:`Glossary <random_state>`.

 

   selection : {'cyclic', 'random'}, default='cyclic'

   If set to 'random', a random coefficient is updated every iteration

   rather than looping over features sequentially by default. This

   (setting to 'random') often leads to significantly faster convergence

   especially when tol is higher than 1e-4.

 

   Attributes

   ----------

   coef_ : ndarray of shape (n_features,) or (n_targets, n_features)

   parameter vector (w in the cost function formula)

 

   sparse_coef_ : sparse matrix of shape (n_features, 1) or \

   (n_targets, n_features)

   ``sparse_coef_`` is a readonly property derived from ``coef_``

 

   intercept_ : float or ndarray of shape (n_targets,)

   independent term in decision function.

 

   n_iter_ : int or list of int

   number of iterations run by the coordinate descent solver to reach

   the specified tolerance.

 

   Examples

   --------

   >>> from sklearn import linear_model

   >>> clf = linear_model.Lasso(alpha=0.1)

   >>> clf.fit([[0,0], [1, 1], [2, 2]], [0, 1, 2])

   Lasso(alpha=0.1)

   >>> print(clf.coef_)

   [0.85 0.  ]

   >>> print(clf.intercept_)

   0.15...

 

   See also

   --------

   lars_path

   lasso_path

   LassoLars

   LassoCV

   LassoLarsCV

   sklearn.decomposition.sparse_encode

 

   Notes

   -----

   The algorithm used to fit the model is coordinate descent.

 

   To avoid unnecessary memory duplication the X argument of the fit

    method

   should be directly passed as a Fortran-contiguous numpy array.

   """

   path = staticmethod(enet_path)

   @_deprecate_positional_args

   def __init__(self, alpha=1.0, *, fit_intercept=True, normalize=False,

       precompute=False, copy_X=True, max_iter=1000,

       tol=1e-4, warm_start=False, positive=False,

       random_state=None, selection='cyclic'):

       super().__init__(alpha=alpha, l1_ratio=1.0, fit_intercept=fit_intercept,

        normalize=normalize, precompute=precompute, copy_X=copy_X,

        max_iter=max_iter, tol=tol, warm_start=warm_start, positive=positive,

        random_state=random_state, selection=selection)

######################################################

#########################

# Functions for CV with paths functions


相关文章
|
4月前
|
机器学习/深度学习 算法 PyTorch
【从零开始学习深度学习】38. Pytorch实战案例:梯度下降、随机梯度下降、小批量随机梯度下降3种优化算法对比【含数据集与源码】
【从零开始学习深度学习】38. Pytorch实战案例:梯度下降、随机梯度下降、小批量随机梯度下降3种优化算法对比【含数据集与源码】
|
2月前
|
数据采集 机器学习/深度学习 算法
【python】python客户信息审计风险决策树算法分类预测(源码+数据集+论文)【独一无二】
【python】python客户信息审计风险决策树算法分类预测(源码+数据集+论文)【独一无二】
|
3月前
|
机器学习/深度学习 数据采集 算法
Python基于Lasso特征选择、GM算法和SVR回归算法进行财政收入影响因素分析及预测
Python基于Lasso特征选择、GM算法和SVR回归算法进行财政收入影响因素分析及预测
|
4月前
|
存储 算法 Java
Java数据结构与算法:用于高效地存储和检索字符串数据集
Java数据结构与算法:用于高效地存储和检索字符串数据集
|
5月前
|
机器学习/深度学习 分布式计算 并行计算
【机器学习】怎样在非常大的数据集上执行K-means算法?
【5月更文挑战第13天】【机器学习】怎样在非常大的数据集上执行K-means算法?
|
2天前
|
传感器 算法 C语言
基于无线传感器网络的节点分簇算法matlab仿真
该程序对传感器网络进行分簇,考虑节点能量状态、拓扑位置及孤立节点等因素。相较于LEACH算法,本程序评估网络持续时间、节点死亡趋势及能量消耗。使用MATLAB 2022a版本运行,展示了节点能量管理优化及网络生命周期延长的效果。通过簇头管理和数据融合,实现了能量高效和网络可扩展性。
|
29天前
|
算法 BI Serverless
基于鱼群算法的散热片形状优化matlab仿真
本研究利用浴盆曲线模拟空隙外形,并通过鱼群算法(FSA)优化浴盆曲线参数,以获得最佳孔隙度值及对应的R值。FSA通过模拟鱼群的聚群、避障和觅食行为,实现高效全局搜索。具体步骤包括初始化鱼群、计算适应度值、更新位置及判断终止条件。最终确定散热片的最佳形状参数。仿真结果显示该方法能显著提高优化效率。相关代码使用MATLAB 2022a实现。
|
29天前
|
算法 数据可视化
基于SSA奇异谱分析算法的时间序列趋势线提取matlab仿真
奇异谱分析(SSA)是一种基于奇异值分解(SVD)和轨迹矩阵的非线性、非参数时间序列分析方法,适用于提取趋势、周期性和噪声成分。本项目使用MATLAB 2022a版本实现从强干扰序列中提取趋势线,并通过可视化展示了原时间序列与提取的趋势分量。代码实现了滑动窗口下的奇异值分解和分组重构,适用于非线性和非平稳时间序列分析。此方法在气候变化、金融市场和生物医学信号处理等领域有广泛应用。
|
1月前
|
资源调度 算法
基于迭代扩展卡尔曼滤波算法的倒立摆控制系统matlab仿真
本课题研究基于迭代扩展卡尔曼滤波算法的倒立摆控制系统,并对比UKF、EKF、迭代UKF和迭代EKF的控制效果。倒立摆作为典型的非线性系统,适用于评估不同滤波方法的性能。UKF采用无迹变换逼近非线性函数,避免了EKF中的截断误差;EKF则通过泰勒级数展开近似非线性函数;迭代EKF和迭代UKF通过多次迭代提高状态估计精度。系统使用MATLAB 2022a进行仿真和分析,结果显示UKF和迭代UKF在非线性强的系统中表现更佳,但计算复杂度较高;EKF和迭代EKF则更适合维数较高或计算受限的场景。
|
1月前
|
算法
基于SIR模型的疫情发展趋势预测算法matlab仿真
该程序基于SIR模型预测疫情发展趋势,通过MATLAB 2022a版实现病例增长拟合分析,比较疫情防控力度。使用SIR微分方程模型拟合疫情发展过程,优化参数并求解微分方程组以预测易感者(S)、感染者(I)和移除者(R)的数量变化。![]该模型将总人群分为S、I、R三部分,通过解析或数值求解微分方程组预测疫情趋势。
下一篇
无影云桌面