当前位置: 首页 > 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.lryc.cn/news/613347.html

相关文章:

  • Nuxt.js 国际化配置完整教程(含版本兼容与问题解决)
  • 驱动-设备树插件注册子系统
  • 【Bluedroid】蓝牙音频接收端活动设备切换机制深度解析(sink_set_active_device)
  • Maven私服搭建--Nexus-3.82.0 Linux环境
  • mysql基础-聚合函数
  • 二叉树算法之【中序遍历】
  • 打靶日记-PHPinclude-labs(一)
  • CS231n2017 Lecture14 强化学习笔记
  • 【MySQL基础篇】:MySQL事务并发控制原理-MVCC机制解析
  • 安卓开发:网络状态监听封装的奥秘
  • 力扣 hot100 Day68
  • 关于vue2中对接海康摄像头以及直播流rtsp或rtmp,后台ffmpeg转码后通过ws实现
  • ADC、Flash、SPI、watchdog
  • Linux 磁盘中的文件
  • 多线程问题,子线程同时操作全局变量,使用后需要清空吗 ?
  • 容器之王--部署Docker私有仓库harbor母盘步骤演练
  • 小米前端笔试和面试
  • AI日报0807 | GPT-5或今晚1点来袭:四大版本全曝光
  • 使用Ollama本地部署DeepSeek、GPT等大模型
  • 13-netty基础-手写rpc-消费方生成代理-05
  • 车辆特征与车牌识别准确率↑29%:陌讯多模态融合算法实战解析
  • [spring-cloud: 动态刷新]-源码分析
  • 基于MATLAB实现支持向量机(SVM)分类
  • android 之 Kotlin中Handler的使用
  • 栅栏密码的加密解密原理
  • zookeeper因jute.maxbuffer启动异常问题排查处理
  • 使用 decimal 包解决 go float 浮点数运算失真
  • 可执行文件的生成与加载执行
  • Linux的进程间通信
  • 嵌入式学习硬件(一)ARM体系架构