Sep-21-2018, 01:47 AM
(This post was last modified: Sep-21-2018, 01:47 AM by sandy49992.)
pd.np.random.seed(123) df = pd.read_csv('LoanStats_2017+2016-39orgin.csv', encoding='big5') df = df.fillna(df.mean()) accuracies = defaultdict(list) f1err=defaultdict(list) f2err=defaultdict(list) dummy_code=pd.get_dummies(df[['home_ownership','purpose','verification_status','grade']]) df=df.drop(['home_ownership','purpose','mths_since_last_delinq','verification_status','grade'],axis=1) df=df.join(dummy_code) N_replications = 10 for counter in range(73000, 240000, 12000): c = df.sample(counter) # behaviour of this function is controlled by numpy RandomState, we set it value above X = c.drop('loan_status', axis=1) #dtrain = xgb.DMatrix(X, label=[0,1]) #X = X.sample(counter, axis=1) Y = c['loan_status'] for i in range(N_replications): X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.3) model=XGBClassifier(max_depth = 5,objective='binary:logistic') model.fit(X_train.round(), y_train.round()) y_train=y_train.tolist() y_pred = model.predict(X_test) y_pre = [int(item>0) for item in y_pred] predictions = [round(value) for value in y_pre] accuracies[counter].append((accuracy_score(y_test , predictions))) f1err[counter].append(1-precision_score(y_test, predictions)) f2err[counter].append(1-recall_score(y_test, predictions))hello, Scidam.
thank you for your help.
Now I find error in my code, but I'm not sure why it happen?
--->error:accuracies[counter].append((accuracy_score(y_test , predictions)))
Classification metrics can't handle a mix of continuous and binary targets
Could you help me? Where it's wrong?