I want to use gridsearch to get right parameters but got failed #189
Unanswered
guanjen375
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I think it has to do with |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to modify the parameter by gridsearchcv. Unforunately, I enforced an error when I want to do this:
Here is my code: (Same as /src/Train-Models/XGBoost_Model_ML.py)
import sqlite3
import pandas as pd
import xgboost as xgb
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from tqdm import tqdm
import numpy as np
from sklearn import datasets, svm
from sklearn.model_selection import GridSearchCV
dataset = "dataset_2012-23"
con = sqlite3.connect("../../Data/dataset.sqlite")
data = pd.read_sql_query(f"select * from "{dataset}"", con, index_col="index")
con.close()
margin = data['Home-Team-Win']
data.drop(['Score', 'Home-Team-Win', 'TEAM_NAME', 'Date', 'TEAM_NAME.1', 'Date.1', 'OU-Cover', 'OU','TEAM_NAME','TEAM_NAME.1','TEAM_ID','TEAM_ID.1'],
axis=1, inplace=True)
data = data.values
data = data.astype(float)
x_train, x_test, y_train, y_test = train_test_split(data, margin, test_size=.1)
cv_param = {'max_depth': [2,3,4]}
param = {
'eta': 0.1,
'objective': 'multi:softprob',
'num_class': 2
}
clf = xgb.XGBClassifier(**param)
grid = GridSearchCV(estimator=clf,param_grid=cv_param)
print("Start Fit...")
grid.fit(x_train,y_train)
print("Generate best estimator...")
best_estimator = grid.best_estimator_
print(best_estimator)
The error message is as follows:
Start Fit...
ValueError: Classification metrics can't handle a mix of binary and multilabel-indicator targets
Can you tell me how to modify my code?
Beta Was this translation helpful? Give feedback.
All reactions