Open neel6762 opened 2 years ago
Could you post a code snippet so we can reproduce your issue? This is about CTClassifier, right? In the CTClassifier code, it does make use of the unlabeled_pool_size input, but it may just be that with your specific data it always converges to the same classifications no matter what this is set as.
Thank you, It might be that case, but even when I individually check the predict proba score they are actually high. I might be implementing it in a wrong way if you can please verify. In addition to this, there is very limited documentation for that. How to use the unlabelled data in this scenario. This is how I am trying based on the original paper.
unlabelled_data_ind = round(len(df) 0.20) train_ind = unlabelled_data_ind + round(len(df) 0.60) test_ind = train_ind + round(len(df) * 0.20) unlabelled = df.iloc[:unlabelled_data_ind] train = df.iloc[unlabelled_data_ind:train_ind] test = df.iloc[train_ind:]
X_train = train.drop('target', axis=1) y_train = train['target']
X_test = test.drop('target', axis=1) y_test = test['target']
X_unlabeled = unlabelled.drop('target', axis=1) y_unlabeled = unlabelled['target'] y_unlabeled.loc[:]= None
X_train = pd.concat([X_train,X_unlabeled],axis=0) y_train = pd.concat([y_train,y_unlabeled],axis=0)
n_features = 27 X_train1 = X_train.iloc[:,:n_features // 2] X_train2 = X_train.iloc[:, n_features // 2:] X_test1 = X_test.iloc[:,:n_features // 2] X_test2 = X_test.iloc[:, n_features // 2:] estimator1 = RandomForestClassifier(n_estimators=100, bootstrap = True,max_features = 'sqrt') estimator2 = SVC(kernel='linear',probability = True) ctc = CTClassifier(estimator1, estimator2, random_state=1,unlabeled_pool_size=30) ctc = ctc.fit([X_train1, X_train2], y_train) preds = ctc.predict([X_test1, X_test2]) predict_proba_values = ctc.predict_proba([X_test1, X_test2]) print("f1-score:",f1_score(y_test, preds)) print("accuracy:",accuracy_score(y_test, preds)) print("Confusion Matrix") print(confusion_matrix(y_test,preds))
the confusion matrix: [[42, 18] [0,0]]
Help would be good
Based upon my understanding, for the semi supervised scenario, the parameters to ct.fit() should be : 1) the two data views on which two classifiers train and 2) the parameters 'y' which is a combination of unlabelled and labelled target class. These parameters were set accordingly. Also, all other functions were passed parameters correctly (ctc.predict and ctc.predict_proba) and they were in accordance with the original paper on Semi Supervised Co training. I am not sure why the results were incorrect. Any help or guidance will be appreciated as there is very limited information available for implementing this for semi - supervised scenario.
It's a little hard to debug without your actual data, but a couple things:
Input data to ct.fit() should be a list of length 2 where each item is a np array of shape (n_samples, n_features_i). In your case it looks like your first view has 13 features and the second has 14.
y should be an array containing class labels for each row in X_train1 and X_train2. Any row that you want to be "unlabeled" should be np.nan in y. For example, if you have 7 samples, y might be np.array([0, 0, 1, np.nan, np.nan, 1, np.nan]). After calling ct.fit(), you can check the attribute ct.n_classes, and this should be 2 if you truly have 2 classes in your training labels.
Is your confusion matrix saying that there were 42 examples of class 1 which were correctly classified, and 18 examples of class 1 which were incorrectly classified as class 2? If so, that means you only have 1 class in your test dataset, not 2, right? Is that what you expect?
Have you tried different random states to see if the predict_proba outputs are identical or not?
I'm a little confused about what the issue is. Are you surprised about the confusion matrix? Is it just that the predictions are super bad?
Expected Behavior
Tell us what should happen
Actual Behavior
Tell us what happens instead
Template Code
Full Traceback
Your Environment