#fill -999 to NAs
X = X_train.fillna(-999)
y = y_train.fillna(-999)
import lightgbm as lgb
import xgboost as xgb
NFOLDS = 8
folds = KFold(n_splits=NFOLDS)
#====================================
xgb_submission=sample_submission.copy()
xgb_submission['isFraud'] = 0
import xgboost as xgb
from sklearn.metrics import roc_auc_score
for fold_n, (train_index, valid_index) in enumerate(folds.split(X)):
X_train_, X_valid = X.iloc[train_index], X.iloc[valid_index]
y_train_, y_valid = y.iloc[train_index], y.iloc[valid_index]
#xgbclf.fit(X_train_,y_train_)
rf_clf1 = RandomForestClassifier(n_estimators=300, max_depth = 10, min_samples_leaf=8, \
min_samples_split=8, random_state=0)
rf_clf1.fit(X_train,y_train_)
pred = rf_clf1.predict(X_test)
print(pred)
I checked the X or y has any Nan but no
but it gives the error with ValueError: Input contains NaN, infinity or a value too large for dtype('float32').
> print(type(X),type(y))
> <class 'pandas.core.frame.DataFrame'> <class'pandas.core.series.Series'>
When does this error appear actually - while assigning X_train_, X_valid values or while fitting the datasets to RandomForest algorithm?
I also see from the code that in the first turn you define X_train_ dataframe:
**X_train_**, X_valid = X.iloc[train_index], X.iloc[valid_index]
Whereas you fit the rf_clf1 object to another dataset (namely: X_train )
rf_clf1.fit(X_train,y_train_)
So here the missing _ in the variable name might be the case as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.