【问题标题】:Churn model in Python?Python中的流失模型?
【发布时间】:2020-03-30 02:48:08
【问题描述】:

流失率 - 从最广泛的意义上说,是衡量在特定时期内从集体群体中移出的个人或项目的数量。

我的问题是我可以使用 Python 使用逻辑回归在流失模型中调查什么?

【问题讨论】:

  • 您的问题是要选择哪些特征,或者回归会向您显示哪些关于客户流失的信息?
  • 这是一个非常广泛的问题。到目前为止,您是否有一些示例数据或代码示例?

标签: python pandas scikit-learn churn


【解决方案1】:
import pandas as pd
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix, accuracy_score, classification_report

features = ['tenure', 'age', 'address', 'income', 'ed', 'employ', 'equip',   'callcard', 'wireless','churn']
churn_df = pd.read_csv("https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/ML0101ENv3/labs/ChurnData.csv")
churn_df = churn_df[features]
churn_df['churn'] = churn_df['churn'].astype('int')
X_normal = preprocessing.StandardScaler().fit_transform(churn_df.drop('churn',axis=1).to_numpy())
y = churn_df['churn']

##split model
X_train, X_test, y_train, y_test = train_test_split( X_normal, y, test_size=0.2, random_state=4)


LR = LogisticRegression(C=0.001, solver='liblinear').fit(X_train,y_train)
print(classification_report(LR.predict(X_test),y_test))
for f,w in zip(features,LR.coef_[0]):
    print("Feature - {} has a weight of - {:.5f}".format(f,w))

>>
0.625
Feature - tenure has a weight of - -0.02402
Feature - age has a weight of - -0.01687
Feature - address has a weight of - -0.01598
Feature - income has a weight of - -0.00497
Feature - ed has a weight of - 0.01042
Feature - employ has a weight of - -0.01900
Feature - equip has a weight of - 0.02367
Feature - callcard has a weight of - -0.02006
Feature - wireless has a weight of - 0.02094

可以告诉您哪些功能对流失很重要。正特征正在搅动它们 (1),而负系数则保留它们

【讨论】:

  • 我们可以在 features 中包含 NaN 值吗?如果没有,为什么?
猜你喜欢
  • 2018-02-03
  • 1970-01-01
  • 1970-01-01
  • 2011-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多