Predicting High-Impact IT Tickets: Notes from a Small Classification Project

What I did and learned building a model to flag high-impact IT incidents early: avoiding leakage, handling rare classes and trading precision for recall.
Machine Learning
Author
Published

April 28, 2023

These are my notes from a small project: predicting which IT support tickets will turn out to be high impact, so the IT team can prioritise them as soon as they’re opened. I’m writing it down mainly for the lessons, which apply to most tabular classification problems.

Code: Zilch123/IT-Ticket-Impact-Prediction

The problem

The data is an incident log of about 99,000 records. Each ticket has an impact level: high, medium or low. A few things stood out in the exploration:

  • 95% of tickets are medium impact. High-impact tickets are only about 2.5%.
  • Knowledge documents are used unevenly. None of the high-impact tickets had a knowledge document attached, compared with 20% of medium and 40% of low.
  • A few groups dominate. 30% of tickets were opened by one group, and 30% were handled by one support group.
  • A handful of service categories cover almost half the tickets.

The business need is to catch high-impact tickets, so I turned it into a binary problem: high versus everything else.

df_solution['impact'] = df_solution['impact'].map({'1 - High':1, '2 - Medium':2,'3 - Low':2 })

Lesson 1: only use what you know at prediction time

This was the most important decision in the whole project. Some columns describe the ticket when it’s opened: who raised it, when, which category. Others are filled in later, while the ticket is being solved: the support group, whether a knowledge document was used, the linked problem or change request.

ticket_attributes = ['ID', 'ID_status', 'active', 'count_reassign',
       'count_opening', 'count_updated', 'ID_caller', 'opened_by',
       'opened_time', 'Created_by', 'created_at', 'updated_by', 'updated_at',
       'type_contact', 'location', 'category_ID', 'user_symptom']

solution_attributes = ['Support_group', 'support_incharge', 'Doc_knowledge',
       'confirmation_check', 'impact', 'notify', 'problem_ID',
       'change_request']

The solution attributes would make the model look great, because the knowledge-document column alone separates high impact well. But they don’t exist yet when the ticket is opened, which is exactly when we want the prediction. Using them is target leakage, so the model only gets the ticket attributes.

Lesson 2: clean the odd encodings first

Missing values were stored as ?, and one status column used -100. Neither shows up as null until you replace them:

df_ticket = df_ticket.replace('?', np.nan)
df_ticket.loc[df_ticket['ID_status']=='-100', 'ID_status'] = np.nan

Lesson 3: timestamps hold useful features

Raw timestamps aren’t useful to a tree model, but things derived from them are. I extracted the weekday and hour for the created, opened and updated times. I also added the average opening hour per ticket ID and per category, then dropped the raw timestamps.

Lesson 4: plan for categories you haven’t seen

Many categorical columns had values that appear only once or twice. These don’t help the model learn, and new ones will show up in production. I replaced rare values (3 occurrences or fewer) with Unknown:

def clip_cat_labels(df: pd.DataFrame, cat_columns: list, label_count=3) -> pd.DataFrame:
    df_cat_clipped = df.copy()
    for col in cat_columns:
        value_count_df = df[col].value_counts().reset_index()
        cat_values_with_low_count = value_count_df[value_count_df[col]<=label_count]['index'].tolist()
        cat_clipped = df[col].mask(df[col].isin(cat_values_with_low_count))
        df_cat_clipped[col] = cat_clipped
    return df_cat_clipped

The label encoders are fitted with an Unknown class included and saved. At inference time, any value the encoder hasn’t seen maps to Unknown instead of crashing.

Lesson 5: for imbalance, try the simple fix first

With only 2.5% positives, the model needs help to pay attention to the rare class. I tried SMOTE and ADASYN oversampling, but neither beat simple class weights:

from sklearn.utils import class_weight
classes_weights = class_weight.compute_sample_weight(class_weight='balanced', y=y_train_xgb)

model_xgb = XGBClassifier(max_depth=16, n_estimators= 100, learning_rate=0.2,
                          min_child_weight=1, gamma=0.5)
model_xgb.fit(X_train_xgb, y_train_xgb, sample_weight=classes_weights)

I also tried KNN, iterative and MissForest imputation for missing values. None improved the metrics over filling with Unknown. It’s worth writing down what didn’t work, so you don’t try it again.

Lesson 6: different models give different trade-offs

I trained two models and then combined them:

  • XGBoost, with features chosen using SelectFromModel. It catches most high-impact tickets but raises many false alarms.
  • Random forest, with settings found using auto-sklearn. It’s precise but misses many.
  • A soft-voting ensemble of the two, which averages their probabilities. Changing each model’s weight moves the balance between precision and recall.
eclf = EnsembleVoteClassifier(clfs=[model_rf, model_xgb], weights=[2, 1], voting='soft')
eclf.fit(X_train_xgb, y_train)

Results on a 5% hold-out set kept aside from the start, for the high-impact class:

Model Recall Precision
XGBoost 0.89 0.36
Ensemble (equal weights) 0.71 0.85
Random forest 0.54 0.94

Which one is “best” is a business decision, not a modelling one. If every missed high-impact ticket is costly and the team is happy to double-check alerts, the XGBoost model (89% recall) is the better fit. If too many false alarms mean people start ignoring them, the ensemble (85% precision) is safer.

Taking it further

If the IT team found the prototype useful, the next steps would be:

  • Serve it with a FastAPI service in a container, with a CI/CD pipeline.
  • Pilot it with a small group of IT staff using the predictions, compared against a group working the usual way, to check it actually saves time.
  • Monitor it for data drift (for example, a KS test on the input features) and model drift (tracking recall and F1 over time), with automatic alerts.
  • Track experiments with a tool like MLflow, and retrain as more labelled data comes in.

The same data could support other uses: suggesting which support group a ticket should go to, predicting the related problem ID, or recommending knowledge documents.

What I’d check next time

Looking back, the data looks like an event log, where the same incident appears in several rows as it’s updated. I split the data randomly by row, and used the incident ID as a feature. That means rows from the same incident can end up in both training and test sets, which can make the scores look better than they really are. Next time I’d split by incident ID (for example with GroupShuffleSplit) and drop the ID itself as a feature.