![python 逻辑回归](https://i-blog.csdnimg.cn/blog_migrate/5a5ad5f87d4c7e2026fa5908b4e5b02a.png)
python 逻辑回归
Python中的逻辑回归-测试 (Logistic Regression in Python - Testing)
We need to test the above created classifier before we put it into production use. If the testing reveals that the model does not meet the desired accuracy, we will have to go back in the above process, select another set of features (data fields), build the model again, and test it. This will be an iterative step until the classifier meets your requirement of desired accuracy. So let us test our classifier.
在投入生产使用之前,我们需要测试上面创建的分类器。 如果测试表明模型不符合期望的精度,我们将不得不返回上述过程,选择另一组特征(数据字段),再次构建模型并进行测试。 这将是一个迭代步骤,直到分类器满足您的所需精度要求为止。 因此,让我们测试分类器。
预测测试数据 (Predicting Test Data)
To test the classifier, we use the test data generated in the earlier stage. We call the predict method on the created object and pass the X array of the test data as shown in the following command −
为了测试分类器,我们使用在较早阶段生成的测试数据。 我们在创建的对象上调用预报方法,并传递测试数据的X数组,如以下命令所示-
In [24]: predicted_y = classifier.predict(X_test)
This generates a single dimensional array for the entire training data set giving the prediction for each row in the X array. You can examine this array by using the following command −
这将为整个训练数据集生成一维数组,从而为X数组中的每一行提供预测。 您可以使用以下命令检查此数组-
In [25]: predicted_y
The following is the output upon the execution the above two commands −
以下是执行以上两个命令后的输出-
Out[25]: array([0, 0, 0, ..., 0, 0, 0])
The output indicates that the first and last three customers are not the potential candidates for the Term Deposit. You can examine the entire array to sort out the potential customers. To do so, use the following Python code snippet −
输出表明前三个客户不是定期存款的潜在候选人。 您可以检查整个阵列以找出潜在客户。 为此,请使用以下Python代码段-
In [26]: for x in range(len(predicted_y)):
if (predicted_y[x] == 1):
print(x, end="\t")
The output of running the above code is shown below −
运行上面的代码的输出如下所示-
![Term Deposit](https://i-blog.csdnimg.cn/blog_migrate/32ac30d06f548e2115166ef5e4085f3c.png)
The output shows the indexes of all rows who are probable candidates for subscribing to TD. You can now give this output to the bank’s marketing team who would pick up the contact details for each customer in the selected row and proceed with their job.
输出显示所有可能预订TD的行的索引。 现在,您可以将此输出提供给银行的营销团队,该团队将为选定行中的每个客户选择详细联系信息,然后继续他们的工作。
Before we put this model into production, we need to verify the accuracy of prediction.
在将此模型投入生产之前,我们需要验证预测的准确性。
验证准确性 (Verifying Accuracy)
To test the accuracy of the model, use the score method on the classifier as shown below −
要测试模型的准确性,请在分类器上使用评分方法,如下所示-
In [27]: print('Accuracy: {:.2f}'.format(classifier.score(X_test, Y_test)))
The screen output of running this command is shown below −
运行此命令的屏幕输出如下所示-
Accuracy: 0.90
It shows that the accuracy of our model is 90% which is considered very good in most of the applications. Thus, no further tuning is required. Now, our customer is ready to run the next campaign, get the list of potential customers and chase them for opening the TD with a probable high rate of success.
它表明我们模型的精度为90%,在大多数应用中被认为是非常好的。 因此,不需要进一步的调整。 现在,我们的客户已准备好进行下一个广告系列,获取潜在客户列表,并追逐他们以可能的高成功率打开TD。
python 逻辑回归