2016-02-19 63 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