2016-02-19 64 views
7

我試圖在python中安裝XGBoost包。 我正在使用Windows操作系統,64位。我經歷了以下。如何在Windows上的python中安裝XGBoost包

軟件包目錄指出xgboost對Windows不穩定並且被禁用: 窗口上的pip安裝目前已被禁用以用於進一步的調查,請從github安裝。 https://pypi.python.org/pypi/xgboost/

我不熟悉Visual Studio,面臨構建XGBoost的問題。 我錯過了在數據科學中利用xgboost包的機會。

請指導,以便我可以在Python中導入XGBoost包。

感謝

回答

2

首先需要通過構建「使」庫中,然後就可以安裝使用anaconda提示(如果你想它蟒蛇)或混帳bash的(如果你在Python只用它)。

首先follow the official guide以下程序(Git中的Bash在Windows上):

git clone --recursive https://github.com/dmlc/xgboost 
git submodule init 
git submodule update 

然後install TDM-GCC here和做的Git Bash的以下內容:

alias make='mingw32-make' 
cp make/mingw64.mk config.mk; make -j4 

最後,請執行以下操作使用anaconda提示或Git Bash:

cd xgboost\python-package 
python setup.py install 

另請參閱SE偉大的資源:在Windows操作系統

Official Guide

Installing Xgboost on Windows

Installing XGBoost For Anaconda on Windows

+0

非常感謝。我已經跟蹤了你指出的資源並在windows中安裝了xgboost。然而,我遇到了一個問題,當我運行以下命令來獲取cv參數時: – shan

+0

我得到WindowsError:[錯誤193]當我嘗試導入xgboost時%1不是有效的Win32應用程序 –

0

我已經安裝xgboost按照上面的資源,這是不可用至今的點子。 然而,我試圖用下面的函數代碼,以獲得CV參數調諧:創建

#Import libraries: 
import pandas as pd 
import numpy as np 
import xgboost as xgb 
from xgboost.sklearn import XGBClassifier 
from sklearn import cross_validation, metrics #Additional sklearn functions 
from sklearn.grid_search import GridSearchCV #Perforing grid search 

import matplotlib.pylab as plt 
%matplotlib inline 
from matplotlib.pylab import rcParams 
rcParams['figure.figsize'] = 12, 4 

train = pd.read_csv('train_data.csv') 
target = 'target_value' 
IDcol = 'ID' 

的函數,以獲得最佳的參數,並顯示在視覺形式的輸出。

def modelfit(alg, dtrain, predictors,useTrainCV=True, cv_folds=5, early_stopping_rounds=50): 

if useTrainCV: 
    xgb_param = alg.get_xgb_params() 
    xgtrain = xgb.DMatrix(dtrain[predictors].values, label=dtrain[target].values) 
    cvresult = xgb.cv(xgb_param, xgtrain, num_boost_round=alg.get_params()['n_estimators'], nfold=cv_folds, 
     metrics='auc', early_stopping_rounds=early_stopping_rounds, show_progress=False) 
    alg.set_params(n_estimators=cvresult.shape[0]) 

#Fit the algorithm on the data 
alg.fit(dtrain[predictors], dtrain[target_label],eval_metric='auc') 

#Predict training set: 
dtrain_predictions = alg.predict(dtrain[predictors]) 
dtrain_predprob = alg.predict_proba(dtrain[predictors])[:,1] 

#Print model report: 
print "\nModel Report" 
print "Accuracy : %.4g" % metrics.accuracy_score(dtrain[target_label].values, dtrain_predictions) 
print "AUC Score (Train): %f" % metrics.roc_auc_score(dtrain[target_label], dtrain_predprob) 

feat_imp = pd.Series(alg.booster().get_fscore()).sort_values(ascending=False) 
feat_imp.plot(kind='bar', title='Feature Importances') 
plt.ylabel('Feature Importance Score') 

現在,當函數被調用,以獲得最佳的參數:雖然顯示的特徵重要性圖表

#Choose all predictors except target & IDcols 
    predictors = [x for x in train.columns if x not in [target]] 
    xgb = XGBClassifier(
    learning_rate =0.1, 
    n_estimators=1000, 
    max_depth=5, 
    min_child_weight=1, 
    gamma=0, 
    subsample=0.7, 
    colsample_bytree=0.7, 
    objective= 'binary:logistic', 
    nthread=4, 
    scale_pos_weight=1, 
    seed=198) 
modelfit(xgb, train, predictors) 

,但在圖表頂部的紅色框中的參數信息丟失: enter image description here 諮詢過使用linux/mac操作系統並安裝了xgboost的人。他們正在獲取上述信息。 我想知道是否是由於具體的實現,我建立並安裝在Windows中。以及我如何獲取圖表上方顯示的參數信息。 截至目前,我正在獲取圖表,而不是其中的紅色框和信息。 謝謝。

1

從這裏構建:從here

  • 下載xgboost WHL文件(確保以符合您的Python版本和系統架構,如 「xgboost-0.6-CP35-cp35m-win_amd64.whl」 爲Python 3.5在64位機)
  • 打開命令提示符
  • cd到您的下載文件夾(或任何你保存在WHL文件) PIP安裝xgboost-0.6-CP35-cp35m-win_amd64.whl(或任何你WHL文件命名)
4

如果您正在使用anaconda(或miniconda),可以使用下列內容:

  • conda install py-xgboost
+0

只是一個簡短的提示:在Anaconda Promt中運行,在Administrator中運行。否則它不適合我。 – CGFoX

+0

使用anaconda安裝成功時,xgboost仍然不會顯示在「pip list」中,並且在嘗試導入時出現錯誤。 – CGFoX

0

可以點子安裝catboost。它是最近開源的漸變增強庫,在大多數情況下它比XGBoost更準確,更快速,並且具有分類特徵支持。 這是圖書館的網站: https://catboost.yandex