notebook中安装lightgbm的gpu版本
生活随笔
收集整理的這篇文章主要介紹了
notebook中安装lightgbm的gpu版本
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
注意一定要打開kaggle notebook右側的Internet和GPU鏈接,否則會安裝失敗的。
?
%%time !rm -r /opt/conda/lib/python3.6/site-packages/lightgbm !git clone --recursive https://github.com/Microsoft/LightGBM !apt-get install -y -qq libboost-all-dev %%time !cd LightGBM;rm -r build;mkdir build;cd build;echo"here1";cmake -DUSE_GPU=1 -DOpenCL_LIBRARY=/usr/local/cuda/lib64/libOpenCL.so -DOpenCL_INCLUDE_DIR=/usr/local/cuda/include/ ..;echo"here2";make -j$(nproc) %%time !cd LightGBM/python-package/;python3 setup.py install --precompile !mkdir -p /etc/OpenCL/vendors && echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd !rm -r LightGBM !pip install -q 'pandas==0.25' --force-reinstall # CPU times: user 584 ms, sys: 496 ms, total: 1.08 s # Wall time: 35.5 s?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
下面是一個更快速的方案,把kaggle notebook中已經編譯好的東西放到github中保存起來,需要的時候直接git clone
%%time # CPU times: user 928 ms, sys: 328 ms, total: 1.26 s # Wall time: 43.7 s !rm -r /kaggle/working/lightgbm_kaggle !rm -r /kaggle/working/LightGBM !rm -r /opt/conda/lib/python3.6/site-packages/lightgbm # !git clone --recursive https://github.com/Microsoft/LightGBM !git clone https://github.com/appleyuchi/lightgbm_kaggle !mv lightgbm_kaggle LightGBM !apt-get install -y -qq libboost-all-dev # !cd LightGBM;rm -r build;mkdir build;cd build;echo"here1";cmake -DUSE_GPU=1 -DOpenCL_LIBRARY=/usr/local/cuda/lib64/libOpenCL.so -DOpenCL_INCLUDE_DIR=/usr/local/cuda/include/ ..;echo"here2";make -j$(nproc) !cd LightGBM/python-package/;python setup.py install --precompile !mkdir -p /etc/OpenCL/vendors && echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd?
# Latest Pandas version !pip install -q 'pandas==0.25' --force-reinstall測試代碼如下:
# %% [code] import numpy as np # linear algebra import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv) import os print(os.listdir("../input"))# %% [code] print("Pandas version:", pd.__version__)# %% [code] import warnings warnings.filterwarnings("ignore")# %% [code] import gc gc.enable()# %% [code] import lightgbm as lgb print("LightGBM version:", lgb.__version__)# %% [markdown] # ## Preprocessing# %% [code] from sklearn.preprocessing import LabelEncoder# %% [code] train_transaction = pd.read_csv('../input/train_transaction.csv', index_col='TransactionID') test_transaction = pd.read_csv('../input/test_transaction.csv', index_col='TransactionID')train_identity = pd.read_csv('../input/train_identity.csv', index_col='TransactionID') test_identity = pd.read_csv('../input/test_identity.csv', index_col='TransactionID')sample_submission = pd.read_csv('../input/sample_submission.csv', index_col='TransactionID')# %% [code] train = train_transaction.merge(train_identity, how='left', left_index=True, right_index=True) test = test_transaction.merge(test_identity, how='left', left_index=True, right_index=True)print(train.shape) print(test.shape)# %% [code] y_train = train['isFraud'].copy() del train_transaction, train_identity, test_transaction, test_identity gc.collect()# %% [code] # Drop target, fill in NaNs X_train = train.drop('isFraud', axis=1) X_test = test.copy() del train, test gc.collect()# %% [code] X_train = X_train.fillna(-999) X_test = X_test.fillna(-999)# %% [code] %%time # Label Encoding for f in X_train.columns:if X_train[f].dtype=='object' or X_test[f].dtype=='object': lbl = LabelEncoder()lbl.fit(list(X_train[f].values) + list(X_test[f].values))X_train[f] = lbl.transform(list(X_train[f].values))X_test[f] = lbl.transform(list(X_test[f].values))# %% [markdown] # ## Modeling# %% [code] # LGBMClassifier with GPU clf = lgb.LGBMClassifier(max_bin = 63,num_leaves = 255,num_iterations = 500,learning_rate = 0.01,tree_learner = 'serial',task = 'train',is_training_metric = False,min_data_in_leaf = 1,min_sum_hessian_in_leaf = 100,sparse_threshold=1.0,device = 'gpu',num_thread = -1,save_binary= True,seed= 42,feature_fraction_seed = 42,bagging_seed = 42,drop_seed = 42,data_random_seed = 42,objective = 'binary',boosting_type = 'gbdt',verbose = 1,metric = 'auc',is_unbalance = True,boost_from_average = False, )# %% [code] %time clf.fit(X_train, y_train)# %% [code] gc.collect()# %% [markdown] # ## Feature Importances# %% [code] import matplotlib.pyplot as plt import seaborn as snsfeature_imp = pd.DataFrame(sorted(zip(clf.feature_importances_,X_train.columns)), columns=['Value','Feature'])plt.figure(figsize=(20, 10)) sns.barplot(x="Value", y="Feature", data=feature_imp.sort_values(by="Value", ascending=False)[:20]) plt.title('LightGBM Feature Importance - Top 20') plt.tight_layout() plt.show() plt.savefig('lgbm_importances.png')# %% [markdown] # ## Submission# %% [code] sample_submission['isFraud'] = clf.predict_proba(X_test)[:,1] sample_submission.to_csv('fast_lightgbm_gpu.csv')?
總結
以上是生活随笔為你收集整理的notebook中安装lightgbm的gpu版本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: No module named 'pan
- 下一篇: 下采样downsample代码