We are now ready to evaluate the performance of predicting whether a call was correctly classified as a fire incident.
We will perform the model analysis which will require importing the following:
from sklearn import metrics
This section walks through the steps to evaluate the model performance.
- Create a confusion matrix using the
.crosstab()
function, as seen in the following script:
df_predicted.crosstab('label', 'prediction').show()
Import
metrics
fromsklearn
to help measure accuracy using the following script:
from sklearn import metrics
- Create two variables for the
actual
andpredicted
columns from the dataframe that will be used to measure accuracy, using the following script:
actual = df_predicted.select('label').toPandas() predicted = df_predicted.select('prediction').toPandas()
- Compute the accuracy prediction score using the following script:
metrics.accuracy_score(actual, predicted)