当前位置:网站首页>【sklearn学习】LightGBM
【sklearn学习】LightGBM
2022-06-12 08:44:00 【jaeden_xu】
# lightgbm原生接口
import lightgbm as lgb
# 基于scikit-learn接口
from lightgbm import LGBMClassifier
from lightgbm import LGBMRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.metrics import mean_absolute_error, mean_squared_error
import pandas as pd
import numpy as np
from sklearn.model_selection import KFold,StratifiedKFold
from sklearn.datasets import load_boston, load_breast_cancer, load_wine
import warnings
warnings.simplefilter("ignore")
bonston = load_boston()
cancer = load_breast_cancer()
wine = load_wine()
from sklearn.datasets import fetch_california_housing
housing = fetch_california_housing()
data_train, data_test, target_train, target_test = train_test_split(cancer.data, cancer.target, test_size = 0.2, random_state = 0)
lgbm = LGBMClassifier()
lgbm.fit(data_train, target_train)
train_score = lgbm.score(data_train, target_train)
print('train score:', train_score)
test_score = lgbm.score(data_test, target_test)
print('test score:', test_score)
data_train, data_test, target_train, target_test = train_test_split(cancer.data, cancer.target, test_size = 0.2, random_state = 0)
lgb_train = lgb.Dataset(data_train, target_train)
lgb_test = lgb.Dataset(data_test, target_test)
params = {
'learning_rate': 0.1,
'lambda_l1': 0.1,
'lambda_l2': 0.2,
'max_depth': 4,
'objective': 'multiclass', # 目标函数
'num_class': 3,
}
# lgb_train
lgb_model = lgb.train(params, lgb_train, valid_sets=lgb_test)
# 模型预测
y_pred = lgb_model.predict(data_test)
y_pred = [list(x).index(max(x)) for x in y_pred]
print(y_pred)
# 模型评估
print(accuracy_score(target_test, y_pred))
边栏推荐
- [GUI development] browsing function implementation model of image processing software
- QT realizes multi screen and multi-resolution adaptation
- Webrtc series - mobile terminal hardware coding supports simulcast
- Background position position NOUN
- [open source project] easycmd command graphical software
- 【数据存储】浮点型数据在内存中的存储
- Regular verification user name
- 三国杀周边--------猪国杀题解
- Background position - exact units
- 【字符集七】汉字的宽字符码和多字节码分别是多少
猜你喜欢

Centos8 installing MySQL 8.0 (upper)

Application method of new version UI of idea + use method of non test qualification and related introduction
![[GUI development] browsing function implementation model of image processing software](/img/37/2162a6047682b9cfc9b8b7c2488068.jpg)
[GUI development] browsing function implementation model of image processing software

FDA审查人员称Moderna COVID疫苗对5岁以下儿童安全有效

第四章-第一个程序

Priority issues

《MATLAB 神经网络43个案例分析》:第8章 GRNN网络的预测----基于广义回归神经网络的货运量预测

x64dbg 调试 EXCEPTION_ACCESS_VIOLATION C0000005

Handling abnormal data

Error: what if the folder cannot be deleted when it is opened in another program
随机推荐
Application method of new version UI of idea + use method of non test qualification and related introduction
Triggers in MySQL
Regularization to limit the number of digits after the decimal point of an input number
ctfshow web 1-2
Close asymmetric key
x64dbg 调试 EXCEPTION_ACCESS_VIOLATION C0000005
第三章 寄存器 (内存访问)
第八章-数据处理的两个基本问题
进制GB和GiB的区别
QT realizes multi screen and multi-resolution adaptation
Scope of bean
第四章-第一个程序
《MATLAB 神经网络43个案例分析》:第7章 RBF网络的回归--非线性函数回归的实现
Get last month, current time and next month
svg中viewbox图解分析
【字符集七】汉字的宽字符码和多字节码分别是多少
Is it really expensive for enterprises to launch MES software?
Audio and video engineer (Preliminary) (I) basic concepts of audio and video
Wechat applet image saving function
Dynamic segment tree leetcode six hundred and ninety-nine