【发布时间】:2021-04-05 13:50:15
【问题描述】:
我正在为一家公司使用 Logistic 回归,以使用其客户数据找出导致客户流失的特定变量。
应用分析方法和评估方法。注释显示结果中两种方法的数据
x = dF.drop("Churn", axis=1)
y = dF["Churn"]
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=1)
logmodel = LogisticRegression()
logmodel.fit(x_train, y_train)
输出:
C:\Users\Rebecca\Anaconda3\lib\site-packages\sklearn\linear_model\logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
FutureWarning)
ValueError
Traceback (most recent call last)
<ipython-input-268-0c050c82a577> in <module>
----> 1 logmodel.fit(x_train, y_train)
~\Anaconda3\lib\site-
packages\sklearn\linear_model\logistic.py in fit(self, X, y, sample_weight)
1530
1531 X, y = check_X_y(X, y,
accept_sparse='csr', dtype=_dtype, order="C",
-> 1532 accept_large_sparse=solver != 'liblinear')
1533 check_classification_targets(y)
1534 self.classes_ = np.unique(y)
~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in check_X_y(X, y, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)
717 ensure_min_features=ensure_min_features,
718 warn_on_dtype=warn_on_dtype,
--> 719 estimator=estimator)
720 if multi_output:
721 y = check_array(y, 'csr', force_all_finite=True, ensure_2d=False,
~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
494 try:
495 warnings.simplefilter('error', ComplexWarning)
--> 496 array = np.asarray(array, dtype=dtype, order=order)
497 except ComplexWarning:
498 raise ValueError("Complex data not supported\n"
~\Anaconda3\lib\site-packages\numpy\core\numeric.py in asarray(a, dtype, order)
536
537 """
--> 538 return array(a, dtype, copy=False, order=order)
539
540
ValueError: could not convert string to float: 'Bank transfer (automatic)'
【问题讨论】:
-
数据框
df的内容是什么? -
变量“银行转账(自动)”是字符串格式,你应该做标签编码。
-
@BhaskarDhariyal 你能告诉我怎么做吗?
-
@Yatin customerID SeniorCitizen Partner Dependents tenure InternetService OnlineBackup Contract PaperlessBilling PaymentMethod ... TechSupport_No Internet 服务 TechSupport_Yes StreamingTV_No StreamingTV_No Internet 服务 StreamingTV_Yes StreamingMovies_No StreamingMovies_No Internet 服务 StreamingMovies_Yes Churn_No Churn_Yes
-
请将其编辑到您的问题中...
标签: python scikit-learn logistic-regression