当前位置: 首页 > news >正文

sklearn study notes[3]

文章目录

  • Non-Negative Least Squares
  • references

Non-Negative Least Squares

  1. all the coefficients in the linear regression have to be non-negative to meet requirement of representing a lot of physical or naturally non-negative quantities through applying Non-Negative Least Squares , just setting up the positive parameter to True when calling the linearRegression function.
    for example:
from sklearn.linear_model import LinearRegression
import numpy as npnp.random.seed(42)n_samples, n_features = 500, 100
X = np.random.randn(n_samples, n_features)
actual_coef = 2.9 * np.random.randn(n_features)
# Generate sample data
y = np.dot(X, actual_coef)
y += 2 * np.random.normal(size=(n_samples,))from sklearn.model_selection import train_test_splitX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.6)# Standard linear regression (may have negative coefficients)
lr = LinearRegression().fit(X_train, y_train)
print("Linear regression coefficients:", lr.coef_)# Non-negative least squares
nnls = LinearRegression(positive=True).fit(X_train, y_train)
print("NNLS coefficients:", nnls.coef_)

calling LinearRegression without the True value of the positive parameter will gerenate a linear regressional object , to apply the fit function of that object achieve the trainning with datas.
through setting the positive parameter as True to call LinearRegression,the object of LinearRegression will be builded for creating Non-negative coefficients which will be used to make a regressional model.
2. subsequently,you can predict the y as follows.

y_pred_nnls = reg_nnls.fit(X_train, y_train).predict(X_test)

references

  1. https://scikit-learn.org/
http://www.dtcms.com/a/319293.html

相关文章:

  • Kong vs. NGINX:从反向代理到云原生网关的全景对比
  • 从零开始学习:深度学习(基础入门版)(1天)
  • [激光原理与应用-168]:测量仪器 - 对光学指标进行测量的仪器
  • 从“数字网格”到“空中交警” :星图低空云如何重构低空管理?
  • 嵌入式第二十二课!!!链式队列与哈希表
  • Maven分模块开发实战指南
  • Qt 子类重新实现父类的槽函数
  • 「iOS」————持久化
  • 【0基础3ds Max】菜单栏介绍
  • 【分享】我国八大沙漠空间矢量范围
  • Bonree ONE发布直通车 | 可观测平台如何深度应用LLM技术
  • 如何科学选择光伏运维系统?
  • docker安装半本地化安装方法
  • Shuffle SOAR使用学习经验
  • FreeRTOS2
  • 4G/5G无线电单元系统
  • 水下管道巡检机器人cad【10张】三维图+设计说明书
  • ai短视频与真人短视频哪个更好?
  • Docker容器部署harbor-小白级教学
  • Aurora MySQL 8.0 性能分析账号创建完整指南
  • ego-planner代码个人阅读笔记
  • 智慧物流分拣效率↑40%:陌讯多模态融合算法实战解析
  • Spring AI Alibaba 项目接入阿里云百炼平台大模型
  • leetcode-hot-100 (技巧)
  • STM32 HAL库外设编程学习笔记
  • SpringBoot中的单例注入方式
  • 上位机知识篇---AT指令
  • 「日拱一码」045 机器学习-因果发现算法
  • C 语言第 17 天学习笔记:从二级指针到内存布局的进阶指南
  • 力控汽车零部件冲压MES系统方案