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


相关文章
|
10月前
|
机器学习/深度学习 算法 安全
【无人机三维路径规划】多目标螳螂搜索算法MOMSA与非支配排序的鲸鱼优化算法NSWOA求解无人机三维路径规划研究(Matlab代码实现)
【无人机三维路径规划】多目标螳螂搜索算法MOMSA与非支配排序的鲸鱼优化算法NSWOA求解无人机三维路径规划研究(Matlab代码实现)
339 0
|
11月前
|
算法 BI 定位技术
三维Chan算法解决室内定位问题的MATLAB实现
三维Chan算法解决室内定位问题的MATLAB实现
252 0
|
9月前
|
开发框架 算法 .NET
基于ADMM无穷范数检测算法的MIMO通信系统信号检测MATLAB仿真,对比ML,MMSE,ZF以及LAMA
简介:本文介绍基于ADMM的MIMO信号检测算法,结合无穷范数优化与交替方向乘子法,降低计算复杂度并提升检测性能。涵盖MATLAB 2024b实现效果图、核心代码及详细注释,并对比ML、MMSE、ZF、OCD_MMSE与LAMA等算法。重点分析LAMA基于消息传递的低复杂度优势,适用于大规模MIMO系统,为通信系统检测提供理论支持与实践方案。(238字)
|
机器学习/深度学习 算法 数据挖掘
K-means聚类算法是机器学习中常用的一种聚类方法,通过将数据集划分为K个簇来简化数据结构
K-means聚类算法是机器学习中常用的一种聚类方法,通过将数据集划分为K个簇来简化数据结构。本文介绍了K-means算法的基本原理,包括初始化、数据点分配与簇中心更新等步骤,以及如何在Python中实现该算法,最后讨论了其优缺点及应用场景。
1855 6
|
10月前
|
机器学习/深度学习 边缘计算 并行计算
【无人机三维路径规划】基于遗传算法GA结合粒子群算法PSO无人机复杂环境避障三维路径规划(含GA和PSO对比)研究(Matlab代码代码实现)
【无人机三维路径规划】基于遗传算法GA结合粒子群算法PSO无人机复杂环境避障三维路径规划(含GA和PSO对比)研究(Matlab代码代码实现)
766 2
|
11月前
|
传感器 算法 Python
【无人机设计与控制】改进型粒子群优化算法(IPSO)的无人机三维路径规划研究(Matlab代码实现)
【无人机设计与控制】改进型粒子群优化算法(IPSO)的无人机三维路径规划研究(Matlab代码实现)
435 1
|
算法 数据可视化 数据挖掘
基于EM期望最大化算法的GMM参数估计与三维数据分类系统python源码
本内容展示了基于EM算法的高斯混合模型(GMM)聚类实现,包含完整Python代码、运行效果图及理论解析。程序使用三维数据进行演示,涵盖误差计算、模型参数更新、结果可视化等关键步骤,并附有详细注释与操作视频,适合学习EM算法与GMM模型的原理及应用。
|
10月前
|
算法 调度 决策智能
基于高尔夫优化算法GOA求解无人机三维路径规划研究(Matlab代码实现)
基于高尔夫优化算法GOA求解无人机三维路径规划研究(Matlab代码实现)
189 0
|
10月前
|
机器学习/深度学习 存储 算法
基于密集型复杂城市场景下求解无人机三维路径规划的Q-learning 算法研究(Matlab代码实现)
基于密集型复杂城市场景下求解无人机三维路径规划的Q-learning 算法研究(Matlab代码实现)
220 0
|
11月前
|
传感器 编解码 分布式计算
【创新未发表】基于吕佩尔狐算法RFO复杂城市地形无人机避障三维航迹规划研究(Matlab代码实现)
【创新未发表】基于吕佩尔狐算法RFO复杂城市地形无人机避障三维航迹规划研究(Matlab代码实现)
232 0

热门文章

最新文章