当前位置:网站首页>[sklearn] lightgbm
[sklearn] lightgbm
2022-06-12 08:49:00 【jaeden_ xu】
# lightgbm The native interface
import lightgbm as lgb
# be based on scikit-learn Interface
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', # Objective function
'num_class': 3,
}
# lgb_train
lgb_model = lgb.train(params, lgb_train, valid_sets=lgb_test)
# Model to predict
y_pred = lgb_model.predict(data_test)
y_pred = [list(x).index(max(x)) for x in y_pred]
print(y_pred)
# Model to evaluate
print(accuracy_score(target_test, y_pred))
边栏推荐
- Background location case 1
- Vscode download slow solution
- Random acquisition of 4-digit non repeated verification code
- Construction of memcached cache service under Linux:
- 分库分表会带来读扩散问题?怎么解决?
- Py & go programming skills: logic control to avoid if else
- [advanced pointer I] character array & array pointer & pointer array
- (node:22344) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permit
- What exactly is APS? You will know after reading the article
- The Three Kingdoms kill the surrounding areas -------- explanation of the pig Kingdom kill problem
猜你喜欢

【指针进阶三】实现C语言快排函数qsort&回调函数
![(node:22344) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permit](/img/c1/d56ec09663857afa52f20848aeadac.png)
(node:22344) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permit

处理异常数据
![[essence] explain in detail the memory management mechanism in QT](/img/7d/0d83158c6b0574dd3b3547b47af67e.jpg)
[essence] explain in detail the memory management mechanism in QT

Priority issues

【字符集九】gbk拷贝到Unicode会乱码?

【无标题】Task3 多路召回

Engineers learn music theory (I) try to understand music

This article is required for the popularization of super complete MES system knowledge

torch.logical_and()方法
随机推荐
[essence] explain in detail the memory management mechanism in QT
Engineers learn music theory (III) interval mode and chord
Shell基本语法--数组
Principle and configuration of MPLS
2022.6.11-----leetcode. nine hundred and twenty-six
When the uniapp page jumps with complex data parameters.
When converting tensor to ndarray in tensorflow, the run or Eval function is constantly called in the loop, and the code runs more and more slowly!
What should be paid attention to when establishing MES system? What benefits can it bring to the enterprise?
Analysis of 43 cases of MATLAB neural network: Chapter 7 regression of RBF Network -- Realization of nonlinear function regression
Centos8 installing MySQL 8.0 (upper)
Specify 404 and 500 error reporting pages.
Notes used by mqtt (combined with source code)
At present, MES is widely used. Why are there few APS scheduling systems? Why?
[dynamic memory management] malloc & calloc and realloc and written test questions and flexible array
(P13) use of final keyword
《MATLAB 神经网络43个案例分析》:第7章 RBF网络的回归--非线性函数回归的实现
Jump to an interface at a specified time. (Web Development)
API处理Android安全距离
Method to limit the input box to only numbers
【进阶指针二】数组传参&指针传参&函数指针&函数指针数组&回调函数