第四届工业大数据代码-模型融合1(自写)

import tensorflow as tf
import matplotlib.pyplot as plt
%matplotlib inline
import pandas as pd
import numpy as np
import xgboost as xgb
from xgboost import plot_importance,plot_tree
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.datasets import load_boston
from sklearn.linear_model import Ridge
    df_x_train = pd.read_csv('new/new_my_train.csv')
    df_x_test = pd.read_csv('new/new_my_test.csv')
    df_y_train = pd.read_csv('new/new_label.csv')
    df_y_test = pd.read_csv('new/new_test_label.csv')
    df_x_train.drop('Id', axis=1, inplace=True)
    df_x_test.drop('Id', axis=1, inplace=True)
    df_y_train.drop('Id', axis=1, inplace=True)
    df_y_test.drop('Id', axis=1, inplace=True)
    
    x_train = np.array(df_x_train)
    y_train = np.array(df_y_train)
    x_test = np.array(df_x_test)
    y_test = np.array(df_y_test)
def my_loss(st, sp):
    num_example = sp.shape[0]
    num_size = sp.shape[1]
    w = np.ones(sp.shape)
    b = np.zeros(sp.shape)
    e = np.exp(abs(st - sp)/0.012) - 1
    for j in range(num_size):
        if j == 0:
            LL = 299.85
            UL = 300.15
        else:
            LL = 199.925
            UL = 200.075
        for i in range(num_example):
            if st[i][j] >= LL and st[i][j] <= UL:
                if sp[i][j] < LL or sp[i][j] > UL:
                    w[i][j] = 10
            if st[i][j] <LL:
                b[i][j] = abs(st[i][j] - LL)
                if sp[i][j] >= LL:
                    w[i][j] = 10
            else:
                b[i][j] = abs(st[i][j] - UL)
                if sp[i][j] <= UL:
                    w[i][j] = 10
    a=100*b+1
    score = np.sum(w*e*a) / float(num_example)
    return score
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.preprocessing import LabelEncoder
from scipy.stats import norm, skew, boxcox_normmax
import warnings
from sklearn import decomposition
from scipy.special import boxcox1p

warnings.filterwarnings('ignore')
from sklearn.linear_model import ElasticNetCV, LassoCV, RidgeCV
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.kernel_ridge import KernelRidge
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import RobustScaler
from sklearn.model_selection import KFold, cross_val_score
from sklearn.metrics import mean_squared_error
from mlxtend.regressor import StackingCVRegressor
import xgboost as xgb
import lightgbm as lgb
n_folds = 5
# 给特征排序,删除无用特征
def rmsle_cv(model):
    kf = KFold(n_folds, shuffle=True, random_state=42).get_n_splits(train)
    mse = np.sqrt(-cross_val_score(model, train, y_train, scoring="neg_mean_squared_error", cv=kf))
    return mse
kfolds = KFold(n_splits=n_folds, shuffle=True, random_state=42)
alph = [0.01, 0.001, 0.0001, 0.0002, 0.0004, 0.0008, 0.002, 0.004, 0.008, 1, 2, 4, 6, 8, 10, 12]
alph2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
lasso = make_pipeline(RobustScaler(), LassoCV(alphas=alph, cv=kfolds, random_state=1))
ENet = make_pipeline(RobustScaler(), ElasticNetCV(alphas=alph, l1_ratio=.9, cv=kfolds, random_state=3))
ridge = make_pipeline(RobustScaler(), RidgeCV(alphas=alph2, cv=kfolds))
KRR = KernelRidge(alpha=0.6, kernel='polynomial', degree=2, coef0=2.5)
GBoost = GradientBoostingRegressor(n_estimators=300, learning_rate=0.05,
                                   max_depth=4, max_features='sqrt',
                                   min_samples_leaf=15, min_samples_split=10,
                                   loss='huber', random_state=5)
model_xgb = xgb.XGBRegressor(max_depth=10,
                          learning_rate=0.05,
                          n_estimators=340,
                          subsample=0.6,
                          colsample_bytree= 0.6,
                          min_child_weight=3,
                          reg_lambda= 2,
                          seed =1000,
                        
                        )
model_lgb = lgb.LGBMRegressor(boosting_type= 'gbdt',  # 设置提升类型
    objective= 'regression',  # 目标函数
#     metric= 'l2',  # 评估函数
    num_leaves=31,  # 叶子节点数
    learning_rate=0.1,  # 学习速率
    feature_fraction=0.9,  # 建树的特征选择比例
    bagging_fraction= 0.8,  # 建树的样本采样比例
    bagging_freq= 5,  # k 意味着每 k 次迭代执行bagging
    verbose= 1
    
    
    )# <0 显示致命的, =0 显示错误 (警告), >0 显示信息)
stacked_averaged_models = StackingCVRegressor(regressors=(ENet, GBoost, KRR),
                                              meta_regressor=lasso,
                                              use_features_in_secondary=True)
def rmsle(y, y_pred):
    return np.sqrt(mean_squared_error(y, y_pred))
model_xgb.fit(x_train, y_train[:,0])
xgb_train_pred = model_xgb.predict(x_train)
xgb_importance = model_xgb.feature_importances_
xgb_out = np.argsort(xgb_importance)
print(rmsle(y_train[:,0], xgb_train_pred))
0.012697466448696014
model_lgb.fit(x_train, y_train[:,0])
[LightGBM] [Warning] feature_fraction is set=0.9, colsample_bytree=1.0 will be ignored. Current value: feature_fraction=0.9
[LightGBM] [Warning] bagging_fraction is set=0.8, subsample=1.0 will be ignored. Current value: bagging_fraction=0.8
[LightGBM] [Warning] bagging_freq is set=5, subsample_freq=0 will be ignored. Current value: bagging_freq=5
[LightGBM] [Warning] feature_fraction is set=0.9, colsample_bytree=1.0 will be ignored. Current value: feature_fraction=0.9
[LightGBM] [Warning] bagging_fraction is set=0.8, subsample=1.0 will be ignored. Current value: bagging_fraction=0.8
[LightGBM] [Warning] bagging_freq is set=5, subsample_freq=0 will be ignored. Current value: bagging_freq=5
[LightGBM] [Warning] Auto-choosing col-wise multi-threading, the overhead of testing was 0.003187 seconds.
You can set `force_col_wise=true` to remove the overhead.
[LightGBM] [Info] Total Bins 7308
[LightGBM] [Info] Number of data points in the train set: 16000, number of used features: 39
[LightGBM] [Info] Start training from score 300.064592





LGBMRegressor(bagging_fraction=0.8, bagging_freq=5, feature_fraction=0.9,
              objective='regression', verbose=1)
booster = model_lgb.booster_
lgb_importance = booster.feature_importance(importance_type='split')
lgb_out = np.argsort(lgb_importance)
lgb_train_pred = model_lgb.predict(x_train)
print(rmsle(y_train[:,0], lgb_train_pred))
print('RMSLE score on train data:')
0.018726673119239007
RMSLE score on train data:
GBoost.fit(x_train, y_train[:,0])
GBoost_train_pred = GBoost.predict(x_train)
GBT_feature = GBoost.feature_importances_
gbt_out = np.argsort(GBT_feature)
drop_num = 30
lgb_out = lgb_out[:drop_num]
xgb_out = xgb_out[:drop_num]
gbt_out = gbt_out[:drop_num]
drop_feature = list(set(lgb_out).union(xgb_out).union(gbt_out))
print(drop_feature)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 38]
train = np.delete(x_train, drop_feature, axis=1)
test = np.delete(x_test, drop_feature, axis=1)
stacked_averaged_models.fit(train, y_train[:,0])
StackingCVRegressor(meta_regressor=Pipeline(steps=[('robustscaler',
                                                    RobustScaler()),
                                                   ('lassocv',
                                                    LassoCV(alphas=[0.01, 0.001,
                                                                    0.0001,
                                                                    0.0002,
                                                                    0.0004,
                                                                    0.0008,
                                                                    0.002,
                                                                    0.004,
                                                                    0.008, 1, 2,
                                                                    4, 6, 8, 10,
                                                                    12],
                                                            cv=KFold(n_splits=5, random_state=42, shuffle=True),
                                                            random_state=1))]),
                    regressors=(Pipeline(steps=[('robustscaler',
                                                 RobustScaler()),
                                                ('elasticnetcv',
                                                 ElasticNetCV(alphas=[...
                                                                      2, 4, 6,
                                                                      8, 10,
                                                                      12],
                                                              cv=KFold(n_splits=5, random_state=42, shuffle=True),
                                                              l1_ratio=0.9,
                                                              random_state=3))]),
                                GradientBoostingRegressor(learning_rate=0.05,
                                                          loss='huber',
                                                          max_depth=4,
                                                          max_features='sqrt',
                                                          min_samples_leaf=15,
                                                          min_samples_split=10,
                                                          n_estimators=300,
                                                          random_state=5),
                                KernelRidge(alpha=0.6, coef0=2.5, degree=2,
                                            kernel='polynomial')),
                    use_features_in_secondary=True)
stacked_pred1 = stacked_averaged_models.predict(test)
model_lgb.fit(train, y_train[:,0])
model_xgb.fit(train, y_train[:,0])
[LightGBM] [Warning] feature_fraction is set=0.9, colsample_bytree=1.0 will be ignored. Current value: feature_fraction=0.9
[LightGBM] [Warning] bagging_fraction is set=0.8, subsample=1.0 will be ignored. Current value: bagging_fraction=0.8
[LightGBM] [Warning] bagging_freq is set=5, subsample_freq=0 will be ignored. Current value: bagging_freq=5
[LightGBM] [Warning] feature_fraction is set=0.9, colsample_bytree=1.0 will be ignored. Current value: feature_fraction=0.9
[LightGBM] [Warning] bagging_fraction is set=0.8, subsample=1.0 will be ignored. Current value: bagging_fraction=0.8
[LightGBM] [Warning] bagging_freq is set=5, subsample_freq=0 will be ignored. Current value: bagging_freq=5
[LightGBM] [Warning] Auto-choosing row-wise multi-threading, the overhead of testing was 0.000081 seconds.
You can set `force_row_wise=true` to remove the overhead.
And if memory is not enough, you can set `force_col_wise=true`.
[LightGBM] [Info] Total Bins 310
[LightGBM] [Info] Number of data points in the train set: 16000, number of used features: 2
[LightGBM] [Info] Start training from score 300.064592





XGBRegressor(base_score=0.5, booster='gbtree', colsample_bylevel=1,
             colsample_bynode=1, colsample_bytree=0.6, gamma=0, gpu_id=-1,
             importance_type='gain', interaction_constraints='',
             learning_rate=0.05, max_delta_step=0, max_depth=10,
             min_child_weight=3, missing=nan, monotone_constraints='()',
             n_estimators=340, n_jobs=0, num_parallel_tree=1, random_state=1000,
             reg_alpha=0, reg_lambda=2, scale_pos_weight=1, seed=1000,
             subsample=0.6, tree_method='exact', validate_parameters=1,
             verbosity=None)
xgb_pred1 = model_xgb.predict(test)
lgb_pred1= model_lgb.predict(test)
y_pred1=  stacked_pred1 * 0.1+ xgb_pred1 * 0.5+ lgb_pred1*0.4 
y_pred1
array([300.03815366, 300.04941286, 300.04630212, 300.03865585,
       300.0421992 , 300.04863364, 300.03935073, 300.03806479,
       300.0363137 , 300.03786326, 300.03085976, 300.04161427,
       300.03997811, 300.03957663, 300.03877248, 300.03649894,
       300.04016676, 300.03892717, 300.0397314 , 300.03946709,
       300.04825874, 300.06292021, 300.03893951, 300.05727181,
       300.03843484, 300.03618135, 300.04097601, 300.03619138,
       300.0482759 , 300.06425828, 300.03963785, 300.04066551,
       300.03916352, 300.04021645, 300.04053795, 300.04807789,
       300.03924883, 300.03741457, 300.06298834, 300.04318353,
       300.0557736 , 300.03873208, 300.03931591, 300.06569122,
       300.04935851, 300.04774066, 300.03823231, 300.06307645,
       300.038135  , 300.04615003, 300.04995955, 300.04058162,
       300.0364312 , 300.0516824 , 300.06161844, 300.04948728,
       300.04122572, 300.05006883, 300.06682011, 300.03235413,
       300.05989997, 300.04866947, 300.04120496, 300.03704795,
       300.05953865, 300.05202324, 300.04066463, 300.04902256,
       300.04688484, 300.06240286, 300.06036487, 300.03851736,
       300.04872697, 300.03835303, 300.03865089, 300.04883786,
       300.03943163, 300.03761534, 300.03965541, 300.05011781,
       300.04307223, 300.0479926 , 300.04212837, 300.0546005 ,
       300.04863348, 300.04967161, 300.05705908, 300.04068136,
       300.04705614, 300.05168214, 300.03857858, 300.04871803,
       300.03962862, 300.050078  , 300.04109655, 300.04199679,
       300.0531037 , 300.05664194, 300.06335457, 300.05449632,
       300.04936953, 300.04099182, 300.03068767, 300.04765125,
       300.04764922, 300.04152802, 300.03997708, 300.04523442,
       300.0378886 , 300.05586313, 300.05155911, 300.05248379,
       300.04134741, 300.04143351, 300.05516516, 300.03875882,
       300.03896158, 300.04945248, 300.04182753, 300.04094057,
       300.0601913 , 300.04070246, 300.04747408, 300.04339252,
       300.04460933, 300.05597788, 300.06355215, 300.04854497,
       300.03746274, 300.03517272, 300.05475254, 300.04918055,
       300.04026556, 300.03783576, 300.04459929, 300.0476221 ,
       300.04762357, 300.0561011 , 300.03973273, 300.05560613,
       300.04251626, 300.05035843, 300.03191773, 300.04925412,
       300.06573898, 300.05044855, 300.03950096, 300.04782832,
       300.04780829, 300.04022692, 300.05661831, 300.04243676,
       300.03993147, 300.04990455, 300.04178931, 300.04920362,
       300.04059877, 300.03761995, 300.03939706, 300.03932028,
       300.06409982, 300.0604372 , 300.06327349, 300.03964052,
       300.04960033, 300.06062182, 300.05737234, 300.04253411,
       300.04695826, 300.06194185, 300.06870668, 300.05993492,
       300.04591376, 300.04301853, 300.07009292, 300.04590867,
       300.04084955, 300.06032591, 300.06079645, 300.0653774 ,
       300.03983761, 300.06543551, 300.05072669, 300.06800309,
       300.04717489, 300.0511728 , 300.04824906, 300.04051719,
       300.06061235, 300.06568804, 300.06927862, 300.07390419,
       300.04618526, 300.04125742, 300.0645429 , 300.04955319,
       300.06672769, 300.05124803, 300.04756777, 300.03550055,
       300.06430847, 300.06403506, 300.05815033, 300.06846183,
       300.06333629, 300.06124818, 300.05706794, 300.05080542,
       300.04934897, 300.05112787, 300.05009958, 300.07790438,
       300.06317224, 300.03564289, 300.07320684, 300.06316803,
       300.07981676, 300.0680383 , 300.06509263, 300.06235676,
       300.06552919, 300.0455346 , 300.06550225, 300.06953744,
       300.05092963, 300.04837011, 300.04922137, 300.06188412,
       300.07292005, 300.07930125, 300.04381892, 300.0639549 ,
       300.07293905, 300.04941539, 300.04798192, 300.05848218,
       300.06451174, 300.04768867, 300.05072921, 300.05388249,
       300.06499651, 300.06412253, 300.05014885, 300.05191117,
       300.04697586, 300.05820139, 300.07024071, 300.06162658,
       300.06226085, 300.06264156, 300.06579946, 300.06626703,
       300.06456779, 300.06384219, 300.08787083, 300.07047085,
       300.05642459, 300.06473501, 300.07484282, 300.06639552,
       300.06494625, 300.06456777, 300.04538668, 300.10004377,
       300.05576087, 300.06385956, 300.0764309 , 300.06438054,
       300.02019241, 300.04251212, 300.06125674, 300.06377318,
       300.04382764, 300.06263785, 300.10429056, 300.06443892,
       300.07425897, 300.05340825, 300.06432974, 300.0657289 ,
       300.0881336 , 300.0607575 , 300.08814928, 300.0640423 ,
       300.05038139, 300.04040644, 300.07584941, 300.06515023,
       300.05004412, 300.1313477 , 300.06380863, 300.05444873,
       300.05277965, 300.06197112, 300.05157206, 300.07308947,
       300.097803  , 300.05415182, 300.08603755, 300.07512844,
       300.06312164, 300.06302752, 300.08834594, 300.06379432,
       300.06427174, 300.04886551, 300.03537993, 300.04912511,
       300.06369425, 300.07352393, 300.06444336, 300.05452653,
       300.07602755, 300.09307242, 300.09163905, 300.15720435,
       300.05945411, 300.12705621, 300.06549659, 300.15759531,
       300.04939284, 300.07780668, 300.07790842, 300.08836063,
       300.04569299, 300.05746919, 300.06580155, 300.05406119,
       300.06235818, 300.11312613, 300.12859725, 300.10029039,
       300.09516714, 300.05414515, 300.06062655, 300.09306375,
       300.05357318, 300.058501  , 300.06767887, 300.04745449,
       300.07193294, 300.0923927 , 300.07095598, 300.06142208,
       300.06682386, 300.06049891, 300.05037911, 300.07407219,
       300.05107622, 300.06390575, 300.06923382, 300.07164654,
       300.05578001, 300.06327348, 300.05492709, 300.0668188 ,
       300.05545988, 300.0647525 , 300.0512826 , 300.05356764,
       300.05162804, 300.06549319, 300.0370615 , 300.06277015,
       300.0638123 , 300.09118663, 300.05921944, 300.06411352,
       300.05914886, 300.06095636, 300.04896441, 300.06066807,
       300.06547685, 300.05202313, 300.06345909, 300.06776433,
       300.0557073 , 300.05302662, 300.04937634, 300.0671101 ,
       300.05002359, 300.06061547, 300.06457562, 300.06484854,
       300.06589909, 300.06640374, 300.05708571, 300.06482105,
       300.07561232, 300.06351032, 300.06769415, 300.06349152,
       300.06635665, 300.05897464, 300.05172562, 300.06443779,
       300.07766078, 300.06927094, 300.06628842, 300.06569064,
       300.0623555 , 300.0562433 , 300.07580485, 300.06383585,
       300.04607359, 300.06427639, 300.05668172, 300.05881654,
       300.12127896, 300.05002291, 300.06254679, 300.06611592,
       300.06560325, 300.06825846, 300.06479386, 300.07228545,
       300.05612637, 300.06485168, 300.05550666, 300.07547416,
       300.05954969, 300.05308432, 300.06254071, 300.06043288,
       300.05866277, 300.05719944, 300.06451043, 300.06457065,
       300.06371638, 300.06298931, 300.06316784, 300.0493125 ,
       300.0576729 , 300.06245439, 300.06436626, 300.06338594,
       300.047585  , 300.06046996, 300.06715997, 300.05705672,
       300.05907522, 300.06504115, 300.06030665, 300.0662191 ,
       300.06569064, 300.0489347 , 300.06397573, 300.06403433,
       300.05112737, 300.05958139, 300.06032187, 300.06275395,
       300.0579657 , 300.05970531, 300.05139692, 300.0593034 ,
       300.06366177, 300.06129874, 300.06036235, 300.04995878,
       300.06104525, 300.06198852, 300.063931  , 300.05630244,
       300.05098361, 300.06335382, 300.06316715, 300.06019438,
       300.04340871, 300.06137685, 300.04318087, 300.06182515,
       300.05635415, 300.06855464, 300.06034307, 300.06115293,
       300.06481814, 300.04054127, 300.06183374, 300.04420899,
       300.05105852, 300.0659252 , 300.0577291 , 300.0619918 ,
       300.04311105, 300.06137834, 300.06100831, 300.05752182,
       300.04608292, 300.04661905, 300.05876997, 300.03493897,
       300.06023489, 300.05634531, 300.05777309, 300.06127877,
       300.04859471, 300.04868766, 300.06007056, 300.04554562,
       300.06011262, 300.05432705, 300.06520877, 300.05695987,
       300.04101096, 300.05042723, 300.06235301, 300.04860327,
       300.04616533, 300.04902422, 300.06103029, 300.0482277 ,
       300.0613597 , 300.06381531, 300.05937093, 300.06058059,
       300.0605786 , 300.06638395, 300.06520078, 300.04358489,
       300.0623242 , 300.06218471, 300.0482348 , 300.06047054,
       300.06566099, 300.07058221, 300.04764472, 300.04999769,
       300.06030829, 300.0527899 , 300.06111825, 300.06520387,
       300.06903973, 300.05563263, 300.06469149, 300.07917699,
       300.0454216 , 300.04779935, 300.06173938, 300.06397828,
       300.0586578 , 300.06424693, 300.05820565, 300.03278129,
       300.07787904, 300.065135  , 300.06580252, 300.06626718,
       300.07310694, 300.06553519, 300.0636366 , 300.06422278,
       300.0503631 , 300.06196496, 300.14529283, 300.06435395,
       300.05866868, 300.06451357, 300.06005417, 300.06481996,
       300.16181194, 300.07060702, 300.06383669, 300.07084751,
       300.07242208, 300.06233049, 300.03477567, 300.06693301,
       300.07016806, 300.07212233, 300.09172172, 300.12232407,
       300.06743908, 300.07580486, 300.05856651, 300.06409359,
       300.05764854, 300.03833333, 300.06436761, 300.06342239,
       300.06435264, 300.0559362 , 300.05917945, 300.07696996,
       300.09182764, 300.07207957, 300.05719704, 300.05277108,
       300.07561129, 300.06430618, 300.07500249, 300.06514324,
       300.0372583 , 300.06630152, 300.06956195, 300.05926099,
       300.06493942, 300.06346793, 300.06770573, 300.06692541])
stacked_averaged_models.fit(train, y_train[:,1])
stacked_pred2 = stacked_averaged_models.predict(test)
model_lgb.fit(train, y_train[:,1])
model_xgb.fit(train, y_train[:,1])
xgb_pred2 = model_xgb.predict(test)
lgb_pred2 = model_lgb.predict(test)
[LightGBM] [Warning] feature_fraction is set=0.9, colsample_bytree=1.0 will be ignored. Current value: feature_fraction=0.9
[LightGBM] [Warning] bagging_fraction is set=0.8, subsample=1.0 will be ignored. Current value: bagging_fraction=0.8
[LightGBM] [Warning] bagging_freq is set=5, subsample_freq=0 will be ignored. Current value: bagging_freq=5
[LightGBM] [Warning] feature_fraction is set=0.9, colsample_bytree=1.0 will be ignored. Current value: feature_fraction=0.9
[LightGBM] [Warning] bagging_fraction is set=0.8, subsample=1.0 will be ignored. Current value: bagging_fraction=0.8
[LightGBM] [Warning] bagging_freq is set=5, subsample_freq=0 will be ignored. Current value: bagging_freq=5
[LightGBM] [Warning] Auto-choosing row-wise multi-threading, the overhead of testing was 0.000092 seconds.
You can set `force_row_wise=true` to remove the overhead.
And if memory is not enough, you can set `force_col_wise=true`.
[LightGBM] [Info] Total Bins 310
[LightGBM] [Info] Number of data points in the train set: 16000, number of used features: 2
[LightGBM] [Info] Start training from score 200.000605
y_pred2= stacked_pred2 * 0.1+ xgb_pred2 * 0.5+ lgb_pred2 *0.4
stacked_averaged_models.fit(train, y_train[:,2])
stacked_pred3 = stacked_averaged_models.predict(test)
model_lgb.fit(train, y_train[:,2])
model_xgb.fit(train, y_train[:,2])
xgb_pred3 = model_xgb.predict(test)
lgb_pred3 = model_lgb.predict(test)
[LightGBM] [Warning] feature_fraction is set=0.9, colsample_bytree=1.0 will be ignored. Current value: feature_fraction=0.9
[LightGBM] [Warning] bagging_fraction is set=0.8, subsample=1.0 will be ignored. Current value: bagging_fraction=0.8
[LightGBM] [Warning] bagging_freq is set=5, subsample_freq=0 will be ignored. Current value: bagging_freq=5
[LightGBM] [Warning] feature_fraction is set=0.9, colsample_bytree=1.0 will be ignored. Current value: feature_fraction=0.9
[LightGBM] [Warning] bagging_fraction is set=0.8, subsample=1.0 will be ignored. Current value: bagging_fraction=0.8
[LightGBM] [Warning] bagging_freq is set=5, subsample_freq=0 will be ignored. Current value: bagging_freq=5
[LightGBM] [Warning] Auto-choosing row-wise multi-threading, the overhead of testing was 0.000077 seconds.
You can set `force_row_wise=true` to remove the overhead.
And if memory is not enough, you can set `force_col_wise=true`.
[LightGBM] [Info] Total Bins 310
[LightGBM] [Info] Number of data points in the train set: 16000, number of used features: 2
[LightGBM] [Info] Start training from score 200.016679
y_pred3= stacked_pred3 * 0.1+ xgb_pred3 * 0.5+lgb_pred3 *0.4
y_pred=np.zeros((600,3))
y_pred[:,0]=y_pred1
y_pred[:,1]=y_pred2
y_pred[:,2]=y_pred3
y_test
array([[300.072, 200.123, 200.045],
       [300.069, 200.128, 200.037],
       [300.067, 200.116, 200.037],
       ...,
       [300.137, 200.171, 200.083],
       [300.148, 200.186, 200.103],
       [300.144, 200.164, 200.092]])
y_pred
array([[300.03405544, 200.09409789, 199.99896254],
       [300.0522131 , 200.10222113, 200.01049061],
       [300.04176403, 200.09988092, 200.00640313],
       ...,
       [300.06766932, 200.11155261, 200.02879545],
       [300.07598615, 200.11245487, 200.0334616 ],
       [300.07354786, 200.11253359, 200.0326937 ]])
accuracy = my_loss(y_test, y_pred)
print('accuracy:'+str(accuracy))
accuracy:10008.390582018752
# df = pd.DataFrame(y_pred)
# df.to_csv('new/提交8.csv')
# df = pd.DataFrame(y_pred)
# df.to_csv('new/predict_label3.csv')
# plot_importance(model,importance_type ="weight")
# plt.show()
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页