-1
$\begingroup$

After performing clustering and detailed cluster analysis, I am confident that my clusters make sense.

Now, for each cluster, I would like to generate rules in the form of decision tree output. With this, I intend to achieve two things:

  1. Most significant variables
  2. Most significant combinations of variables which lead to the cluster

I do not want to perform decision tree classification with K clusters as K classes and instead obtain rules for the population which is already segmented. Is there a way I can do this?

$\endgroup$
2
  • 5
    $\begingroup$ Can you elaborate on why you don't like the idea of training a (shallow) Decision Tree model with your clusters as labels, and using those rules? $\endgroup$
    – Andy M
    Commented May 3, 2019 at 13:27
  • $\begingroup$ Firstly, it will create class imbalance problems as all my classes do not have equal number of members. Secondly, the maximum accuracy that I am achieving with a max_depth 5 is 34%. At this accuracy, I believe the bins are not useful. Thirdly, since my clusters already look meaningful, I do not want to spend time in training a decision tree. I just want an automated way of generating the rules from the feature values representing each cluster. $\endgroup$ Commented May 6, 2019 at 7:16

2 Answers 2

1
$\begingroup$

I do not want to perform decision tree classification with K clusters as K classes

You should.

A tree is a representation of rules in which you follow a path which begins in the root node and ends in every leaf node.

If the tree separates between x<=30 and x>30, then the rules are:

If x<=30 then
    Follow path A
Else:
    Follow Path B
$\endgroup$
1
  • $\begingroup$ I did this and the best accuracy I am getting is 34%. I am afraid I cannot trust the rules generated by this model. $\endgroup$ Commented May 9, 2019 at 5:37
1
$\begingroup$

This almost sounds like a combination of supervised learning and unsupervised learning. Consider finding significant features that predict a target variable like this (fee in your own data).

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# matplotlib inline

df = pd.read_csv("https://rodeo-tutorials.s3.amazonaws.com/data/credit-data-trainingset.csv")
df.head()

from sklearn.ensemble import RandomForestClassifier

features = np.array(['revolving_utilization_of_unsecured_lines',
                     'age', 'number_of_time30-59_days_past_due_not_worse',
                     'debt_ratio', 'monthly_income','number_of_open_credit_lines_and_loans', 
                     'number_of_times90_days_late', 'number_real_estate_loans_or_lines',
                     'number_of_time60-89_days_past_due_not_worse', 'number_of_dependents'])
clf = RandomForestClassifier()
clf.fit(df[features], df['serious_dlqin2yrs'])

# from the calculated importances, order them from most to least important
# and make a barplot so we can visualize what is/isn't important
importances = clf.feature_importances_
sorted_idx = np.argsort(importances)


padding = np.arange(len(features)) + 0.5
plt.barh(padding, importances[sorted_idx], align='center')
plt.yticks(padding, features[sorted_idx])
plt.xlabel("Relative Importance")
plt.title("Variable Importance")
plt.show()

enter image description here

When you have your best features selected, consider applying KMeans, AffinityPropagation, Mean Shift, SpectralClustering, AgglomerativeClustering, or DBSCAN. See the link below for more details.

Comparing Python Clustering Algorithms | The hdbscan Clustering Library

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.