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?

  • $\begingroup$ Do you really need to cluster ? why not doing classification on label ? $\endgroup$ – lcrmorin Feb 26 at 9:04
  • $\begingroup$ 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. $\endgroup$ – 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

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

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")

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.


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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