电信用户流失数据集构架流失模型预测。
Classifiers=[["Random Forest",RandomForestClassifier()],
["Support Vector Machine",SVC()],
["LogisticRegression",LogisticRegression()],
["KNN",KNeighborsClassifier(n_neighbors=5)],
["Naive Bayes",GaussianNB()],
["Decision Tree",DecisionTreeClassifier()],
["AdaBoostClassifier", AdaBoostClassifier()],
["GradientBoostingClassifier", GradientBoostingClassifier()],
["XGB", XGBClassifier(enable_categorical=True)],
["CatBoost", CatBoostClassifier(logging_level='Silent')]
]
Classify_result= []
names= []
prediction= []
f1score = []
for name, classifier in Classifiers:
classifier=classifier
classifier.fit(x_train, y_train)
y_pred = classifier.predict(x_test)
recall = recall_score(y_test, y_pred)
precision = precision_score(y_test,y_pred)
f1score = 2 * (recall * precision) / (recall + precision)
class_eva = pd.DataFrame([recall, precision, f1score])
Classify_result.append(class_eva)
name = pd.Series(name)
names.append(name)
y_pred = pd.Series(y_pred)
ValueError Traceback (most recent call last)
in ()
5 for name, classifier in Classifiers:
6 classifier=classifier
7 classifier.fit(x_train, y_train)
8 y_pred = classifier.predict(x_test)
9 recall = recall_score(y_test, y_pred)
D:\python-data\python\lib\site-packages\xgboost\core.py in inner_f(*args, **kwargs)
530 for k, arg in zip(sig.parameters, args):
531 kwargs[k] = arg
532 return f(**kwargs)
533
534 return inner_f
D:\python-data\python\lib\site-packages\xgboost\sklearn.py in fit(self, X, y, sample_weight, base_margin, eval_set, eval_metric, early_stopping_rounds, verbose, xgb_model, sample_weight_eval_set, base_margin_eval_set, feature_weights, callbacks)
1378
1379 model, metric, params, early_stopping_rounds, callbacks = self._configure_fit(
1380 xgb_model, eval_metric, params, early_stopping_rounds, callbacks
1381 )
1382 train_dmatrix, evals = _wrap_evaluation_matrices(
D:\python-data\python\lib\site-packages\xgboost\sklearn.py in _configure_fit(self, booster, eval_metric, params, early_stopping_rounds, callbacks)
849 if self.enable_categorical and tree_method not in cat_support:
850 raise ValueError(
851 "Experimental support for categorical data is not implemented for"
852 " current tree method yet."
853 )
ValueError: Experimental support for categorical data is not implemented for current tree method yet.
Classify_result=[]