I am new to ML, and XGB is really confusing me. I understand that for Python XGB can be imported directly from the xgb library or via SKLearn.
The methods for xgb from the direct xgb library also differ from SKLearn xgb. Eg xgb library uses xgb.train while SKLearn xgb uses fit.
I tried the xgb from SKLearn xgb, but got the below error:
TypeError: fit() missing 1 required positional argument: 'y'
- What is wrong with my below code?
- And is the direct xgb better than SKLearn xgb?
Would appreciate some help. Thank you
from xgboost.sklearn import XGBClassifier from sklearn.utils import class_weight from sklearn.model_selection import train_test_split X1=s_matrix2 # a sparse matrix Y1=df['Label'].values X_train, X_test, y_train, y_test = train_test_split(X1, Y1, random_state=0, test_size=0.2) classes_weights = class_weight.compute_sample_weight( class_weight='balanced', y=y_train ) xgb_model=XGBClassifier.fit(X_train, y_train, sample_weight=classes_weights) ```