9951 explained code solutions for 126 technologies


python-scikit-learnXgboost regression usage example


from sklearn import datasets, model_selection
import xgboost as xgb

X, y = datasets.load_diabetes(return_X_y=True)
X_train, X_test, y_train, y_test = model_selection.train_test_split(X, y)

model = xgb.XGBRegressor()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)ctrl + c
from sklearn import

import module from scikit-learn

import xgboost as xgb

Loads XGBoost module

load_diabetes

loads sample diabetes database

model_selection.train_test_split

splits given X and y datasets to test (25% of values by default) and train (75% of values by default) subsets

xgb.XGBRegressor(

creates XGBoost regression model

.fit(

train transformation model

.predict(

predict target variable based on given features dataset


Usage example

from sklearn import datasets, model_selection
import xgboost as xgb

X, y = datasets.load_diabetes(return_X_y=True)
X_train, X_test, y_train, y_test = model_selection.train_test_split(X, y)

model = xgb.XGBRegressor()
model.fit(X_train, y_train)

print(model.score(X_test, y_test))
output
0.35751336429972946