In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
QuadraticDiscriminantAnalysis()
InĀ [28]:
lda.decision_function
Out[28]:
<bound method LinearDiscriminantAnalysis.decision_function of LinearDiscriminantAnalysis()>
InĀ [31]:
y_pred=qda.predict(X_test.iloc[:,1:])print('Accuracy of logistic regression classifier on test set: {:.2f}'.format(qda.score(X_test.iloc[:,1:],y_test)))
Accuracy of logistic regression classifier on test set: 0.97
y_pred=lda.predict(X_test.iloc[:,1:])print('Accuracy of logistic regression classifier on test set: {:.2f}'.format(lda.score(X_test.iloc[:,1:],y_test)))
Accuracy of logistic regression classifier on test set: 0.98
---------------------------------------------------------------------------TypeError Traceback (most recent call last)
File ~/.local/lib/python3.13/site-packages/sklearn/metrics/_classification.py:126, in _check_targets(y_true, y_pred) 125try:
--> 126 unique_values =_union1d(y_true,y_pred,xp) 127exceptTypeErroras e:
128# We expect y_true and y_pred to be of the same data type. 129# If `y_true` was provided to the classifier as strings, 130# `y_pred` given by the classifier will also be encoded with 131# strings. So we raise a meaningful error
File ~/.local/lib/python3.13/site-packages/sklearn/utils/_array_api.py:220, in _union1d(a, b, xp) 219 a_unique, b_unique = cached_unique(a, b, xp=xp)
--> 220return xp.asarray(numpy.union1d(a_unique,b_unique))
221assert a.ndim == b.ndim ==1
File ~/.local/lib/python3.13/site-packages/numpy/lib/_arraysetops_impl.py:1176, in union1d(ar1, ar2) 1148""" 1149Find the union of two arrays. 1150 (...) 1174array([1, 2, 3, 4, 6]) 1175"""-> 1176returnunique(np.concatenate((ar1,ar2),axis=None))
File ~/.local/lib/python3.13/site-packages/numpy/lib/_arraysetops_impl.py:291, in unique(ar, return_index, return_inverse, return_counts, axis, equal_nan) 290if axis isNone:
--> 291 ret =_unique1d(ar,return_index,return_inverse,return_counts, 292equal_nan=equal_nan,inverse_shape=ar.shape,axis=None) 293return _unpack_tuple(ret)
File ~/.local/lib/python3.13/site-packages/numpy/lib/_arraysetops_impl.py:358, in _unique1d(ar, return_index, return_inverse, return_counts, equal_nan, inverse_shape, axis) 357else:
--> 358ar.sort() 359 aux = ar
TypeError: '<' not supported between instances of 'bool' and 'str'
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
Cell In[47], line 1----> 1print(classification_report(y_test,y_pred_new_threshold))
File ~/.local/lib/python3.13/site-packages/sklearn/utils/_param_validation.py:216, in validate_params.<locals>.decorator.<locals>.wrapper(*args, **kwargs) 210try:
211with config_context(
212 skip_parameter_validation=(
213 prefer_skip_nested_validation or global_skip_validation
214 )
215 ):
--> 216returnfunc(*args,**kwargs) 217except InvalidParameterError as e:
218# When the function is just a wrapper around an estimator, we allow 219# the function to delegate validation to the estimator, but we replace 220# the name of the estimator by the name of the function in the error 221# message to avoid confusion. 222 msg = re.sub(
223r"parameter of \w+ must be",
224f"parameter of {func.__qualname__} must be",
225str(e),
226 )
File ~/.local/lib/python3.13/site-packages/sklearn/metrics/_classification.py:2671, in classification_report(y_true, y_pred, labels, target_names, sample_weight, digits, output_dict, zero_division) 2563"""Build a text report showing the main classification metrics. 2564 2565Read more in the :ref:`User Guide <classification_report>`. (...) 2667<BLANKLINE> 2668""" 2670 y_true, y_pred = attach_unique(y_true, y_pred)
-> 2671 y_type, y_true, y_pred =_check_targets(y_true,y_pred) 2673if labels isNone:
2674 labels = unique_labels(y_true, y_pred)
File ~/.local/lib/python3.13/site-packages/sklearn/metrics/_classification.py:132, in _check_targets(y_true, y_pred) 126 unique_values = _union1d(y_true, y_pred, xp)
127exceptTypeErroras e:
128# We expect y_true and y_pred to be of the same data type. 129# If `y_true` was provided to the classifier as strings, 130# `y_pred` given by the classifier will also be encoded with 131# strings. So we raise a meaningful error--> 132raiseTypeError(
133"Labels in y_true and y_pred should be of the same type. " 134f"Got y_true={xp.unique(y_true)} and " 135f"y_pred={xp.unique(y_pred)}. Make sure that the " 136"predictions provided by the classifier coincides with " 137"the true labels." 138 ) frome 139if unique_values.shape[0] >2:
140 y_type ="multiclass"TypeError: Labels in y_true and y_pred should be of the same type. Got y_true=['No' 'Yes'] and y_pred=[False True]. Make sure that the predictions provided by the classifier coincides with the true labels.