Objective (loss) functions और base learners

XGBoost के साथ Extreme Gradient Boosting

Sergey Fogelson

Head of Data Science, TelevisaUnivision

Objective functions और हम इन्हें क्यों उपयोग करते हैं

  • यह बताता है कि prediction असल परिणाम से कितना दूर है
  • किसी डेटा कलेक्शन के लिए अनुमानित और वास्तविक मानों का फर्क मापता है
  • लक्ष्य: ऐसा मॉडल पाना जो loss function को न्यूनतम करे
XGBoost के साथ Extreme Gradient Boosting

Common loss functions और XGBoost

  • xgboost में loss function के नाम:
    • reg:squarederror - regression समस्याओं के लिए उपयोग करें
    • reg:logistic - जब केवल decision चाहिए, probability नहीं, तब classification के लिए
    • binary:logistic - जब probability चाहिए, सिर्फ decision नहीं
XGBoost के साथ Extreme Gradient Boosting

Base learners और हमें इनकी क्यों ज़रूरत है

  • XGBoost एक meta-model बनाता है जो कई individual models से मिलकर final prediction देता है
  • Individual models = base learners
  • ऐसे base learners चाहिए जिनका संयोजन करके final prediction non-linear बने
  • हर base learner डेटासेट के अलग-अलग भागों में अच्छी तरह भेद/भविष्यवाणी कर सके
  • दो तरह के base learners: tree और linear
XGBoost के साथ Extreme Gradient Boosting

Trees as base learners उदाहरण: Scikit-learn API

import xgboost as xgb
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split

boston_data = pd.read_csv("boston_housing.csv")

X, y = boston_data.iloc[:,:-1],boston_data.iloc[:,-1] X_train, X_test, y_train, y_test= train_test_split(X, y, test_size=0.2, random_state=123)
xg_reg = xgb.XGBRegressor(objective='reg:squarederror', n_estimators=10, seed=123) xg_reg.fit(X_train, y_train) preds = xg_reg.predict(X_test)
XGBoost के साथ Extreme Gradient Boosting

Trees as base learners उदाहरण: Scikit-learn API

rmse = np.sqrt(mean_squared_error(y_test,preds))

print("RMSE: %f" % (rmse))
RMSE: 129043.2314
XGBoost के साथ Extreme Gradient Boosting

Linear base learners उदाहरण: learning API only

import xgboost as xgb
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split

boston_data = pd.read_csv("boston_housing.csv")

X, y = boston_data.iloc[:,:-1],boston_data.iloc[:,-1]

X_train, X_test, y_train, y_test= train_test_split(X, y, test_size=0.2, 
                                                         random_state=123)

DM_train = xgb.DMatrix(data=X_train,label=y_train) DM_test = xgb.DMatrix(data=X_test,label=y_test)
params = {"booster":"gblinear","objective":"reg:squarederror"}
xg_reg = xgb.train(params = params, dtrain=DM_train, num_boost_round=10) preds = xg_reg.predict(DM_test)
XGBoost के साथ Extreme Gradient Boosting

Linear base learners उदाहरण: learning API only

rmse = np.sqrt(mean_squared_error(y_test,preds))

print("RMSE: %f" % (rmse))
RMSE: 124326.24465
XGBoost के साथ Extreme Gradient Boosting

चलो काम शुरू करें!

XGBoost के साथ Extreme Gradient Boosting

Preparing Video For Download...