# Unsupervised clustering improved with supervised classification accuracy

I have a set of labeled samples each containing up to 300 different objects. For every object I have a set of features describing the object.

For example,

• Sample with label '1': 50 objects of type 1, 20 of type 2 (=70 total)
• Sample with label '2': 100 objects of type 1, 30 of type 3 (=130 total)

Now I want to find the best clustering that results in highest accuracy after classification. And I don't know how many object-types I should use and how these types should be described.

Current workflow is like that:

1. find the clusters for all objects from all samples (300 in our example) using self-organized maps using the features I have for each object.
2. Calculate the cluster representation of each sample by finding the best matching unit and make a 2d-histogram (kind of a 'hit-map' for the SOM)
3. Train a random-forest model with the cluster representation (from step 2) and get the accuracy of a validation set.
4. start over at step 1

My Problem is that step 1 is independent from step 3. So the self-organized maps find clusters that might or might not lead to a better classification in step 3. I need a way to feed the accuracy of step 4 into the SOM training algorithm.

Any suggestions how to do that?

• Do you really need to cluster ? why not doing classification on label ? – lcrmorin Feb 26 at 9:04
• Because I need to label first. My sample have for example 350 different objects. Some with similar properties, others not. So I have the similar objects first before I can label them. However, I cannot say at the beginning what "similar" means. – RaJa Feb 27 at 10:06

Wow, I just answered another question very similar to this. Ok, it seems like you are doing 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

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)