Skip to content

Conversation

OskarLiew
Copy link
Contributor

This pull requests aims to solve the second issue mentioned in #97. When creating a committee without any training data, calling Committee.fit(X, y) would cause an error because Committee.classes_ was None.

The following code would cause an error in vote_entropy and other disagreement functions:

import numpy as np
from sklearn.svm import SVC
from modAL.uncertainty import uncertainty_sampling
from modAL.disagreement import vote_entropy_sampling
from modAL.models import ActiveLearner, Committee

# Create data
X = np.array([[0, 0],
              [0, 1],
              [1, 0],
              [1, 1]])

y = np.array([1, 1, 0 ,0])

X_teach = X[:3]
y_teach = y[:3]

X_query = X[3].reshape((-1, 2))
y_query = y[3]

# ActiveLearner
svm = SVC(probability=True, gamma='auto')
learner = ActiveLearner(svm, uncertainty_sampling)

learner.fit(X_teach, y_teach)

query_idx, query_inst = learner.query(X_query)

print('Index %d, Coordinates %s' % (query_idx, query_inst))

# Committee
estimators = [SVC(probability=True, gamma='auto') for _ in range(20)]
learner_list = [ActiveLearner(estimator, uncertainty_sampling) for estimator in estimators]
committee = Committee(learner_list, vote_entropy_sampling)

committee.fit(X_teach, y_teach)

query_idx, query_inst = committee.query(X_query)

print('Index %d, Coordinates %s' % (query_idx, query_inst))

p_vote = np.zeros(shape=(X.shape[0], len(committee.classes_)))
TypeError: object of type 'NoneType' has no len()

With the fix, it is able to run smoothly.

@cosmic-cortex cosmic-cortex merged commit ff7a52f into modAL-python:dev Sep 22, 2020
@cosmic-cortex
Copy link
Member

Thanks for the fix! Sorry to be almost two weeks late, I am a little behind on modAL maintainance :)

@OskarLiew OskarLiew deleted the fix/fit-empty-committee branch September 6, 2022 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants