I am trying to run several machine learning algorithms on a dataset to predict whether the salary/income is greater than 50k or less than equal to 50k. I made a function and am passing the values to it, with different size sample sets of 1% samples, 10% samples and 100% samples. I am getting an unknown error 'Unknown label type: 'continuous-multioutput'' I don't know what this error is.
I tried changing the classification algorithms I used but no use. It displays the same error for all the alogrithms.
from sklearn.metrics import fbeta_score, accuracy_score
def train_predict (learner, sample_size, X_train, X_test, y_train, y_test):
results = {}
start = time()
learner = learner.fit(X_train[:sample_size], y_train)
end = time()
results['train_time'] = end - start
start = time()
predictions_test = learner.predict(X_test)
predictions_train = learner.predict(X_train[:sample_size])
end = time()
results['pred_time'] = end - start
results['acc_train'] = accuracy_score(X_train[:sample_size], y_train[:sample_size])
results['acc_test'] = accuracy_score[X_test, y_test]
results['f_train'] = fbeta_score(X_train[:sample_size], y_train[:sample_size], beta = 1)
resutts['f_test'] = fbeta_score(X_test, y_test, beta = 1)
print("{} trained on {} samples. ".format(learner.__class__.__name__, sample_size))
return results
from sklearn.tree import DecisionTreeClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC
clf_A = DecisionTreeClassifier()
clf_B = GaussianNB()
clf_C = SVC()
samples_100 = len(X_train) #taking 100% i.e. all the data in training set
samples_10 = int(len(X_train)*.1) # taking 10% of the training data
samples_1 = int(len(X_train)*.01) #taking 1% of the training data
results= {}
for clf in [clf_A, clf_B, clf_C]:
clf_name = clf.__class__.__name__
results[clf_name] = {}
for i, samples in enumerate([samples_1, samples_10, samples_100]):
results[clf_name][i] = \
train_predict(clf, samples, X_train, y_train, X_test, y_test)
vs.evaluate(results, accuracy, fscore)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-66-e06d42fbd15b> in <module>
5 for i, samples in enumerate([samples_1, samples_10, samples_100]):
6 results[clf_name][i] = \
----> 7 train_predict(clf, samples, X_train, y_train, X_test, y_test)
8 vs.evaluate(results, accuracy, fscore)
<ipython-input-62-4484b803a707> in train_predict(learner, sample_size, X_train, X_test, y_train, y_test)
2 results = {}
3 start = time()
----> 4 learner = learner.fit(X_train[:sample_size], y_train)
5 end = time()
6 results['train_time'] = end - start
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\tree\tree.py in fit(self, X, y, sample_weight, check_input, X_idx_sorted)
799 sample_weight=sample_weight,
800 check_input=check_input,
--> 801 X_idx_sorted=X_idx_sorted)
802 return self
803
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\tree\tree.py in fit(self, X, y, sample_weight, check_input, X_idx_sorted)
138
139 if is_classification:
--> 140 check_classification_targets(y)
141 y = np.copy(y)
142
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\multiclass.py in check_classification_targets(y)
169 if y_type not in ['binary', 'multiclass', 'multiclass-multioutput',
170 'multilabel-indicator', 'multilabel-sequences']:
--> 171 raise ValueError("Unknown label type: %r" % y_type)
172
173
ValueError: Unknown label type: 'continuous-multioutput'
I want this code to run and show the accuracy and other metrics of these algorithms for this datasets.
P.S. I know the code is too long and cumbersome but please take efforts to go through it and let me know the solution. I am newbie in this machine learning domain. Any help will be highly appreciated.
P.S. Please don't mark this question as duplicate I have already been through similar questions and tried all that was suggested there but in vain. It wan't of any use to me.
Ok, I got the error the problem was with the way I was sampling the data sets. I changed the sampling code using frac attribute and the error disappeared.
samples_100 = df.sample(frac = 1) #taking 100% i.e. all the data in training set
samples_10 = df.sample(frac = .1) #taking 10% of the training data
samples_1 = df.sample(frac = .01) #taking 1% of the training data