'Stacking scikit, Ensemble Machine Learning With Python
I am trying to create a stack with various algorithms to compare their performances, taking into consideration the feature scales I created which are in dictionary format.
I ave the stack code here, which gives me this error: TypeError: 'numpy.float64' object is not callable
My X and y are respectively:
array([[ 2.47475454, 0.40165523, 1.68081787, ..., -6.59044146,
-2.21290585, -3.139579 ],
[ 0.84802507, 2.81841945, -2.76008732, ..., 3.00844461,
0.78661954, -1.27681551],
[ -1.90041246, -0.56901823, -1.76220236, ..., 3.37336417,
-2.28613707, 1.90344983],
array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0,
1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0,
0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0
This is the stacking code:
from sklearn.datasets import make_classification
from sklearn.model_selection import RepeatedStratifiedKFold
# get the dataset
def get_dataset():
return X, y
def get_models():
models = dict()
models['lr'] = LogisticRegression()
models['knn'] = KNeighborsClassifier()
models['cart'] = DecisionTreeClassifier()
models['svm'] = SVC()
models['bayes'] = GaussianNB()
return (models)
def evaluate_model(model, X, y):
cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=3, random_state=1)
scores = cross_val_score(model, X, y, scoring='accuracy', cv=cv, n_jobs=-1, error_score='raise')
return scores
# define dataset
X, y = get_dataset()
# get the models to evaluate
models = get_models()
# evaluate the models and store results
results, names = list(), list()
for name, model in models.items():
scores = evaluate_model(model, X, y)
results.append(scores)
names.append(name)
print('>%s %.3f (%.3f)' % (names, mean(scores), std(scores)))
# plot model performance for comparison
pyplot.boxplot(results, labels=names, showmeans=True)
pyplot.show()
I would like to fix this error, which I dont understand why its being called... then I would like to somehow include the iteration on the feature scales for normalisation etc
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
