Issue
I want to get the accuracy score for meanshift based on the code below.
I tried with a classification algorithm from sklearn and the "score" was able to produce the accuracy, but when it comes to clustering algorithm such as Birch, kmeans, meanshift, algglomerative, it seems like I'm not able to get the accuracy score through the same code.
from sklearn.cluster import MeanShift
kfold = 5
mean = MeanShift()
Count1 = 1
Aa1 = 0
Cnt1 = len(X)
kf = KFold(n_splits=kfold)
for train_index,test_index in kf.split(X):
X_train,X_test = X[train_index],X[test_index]
Y_train,Y_test = Y[train_index],Y[test_index]
model1 = mean
model1.fit(X_train, Y_train)
Pa_1=model1.predict(X_test)
AC1=model1.score(X_test,Y_test)
Aa1 += AC1
print()
print("Accuracy for DT GA: %f" % (Aa1/kfold))
Output:
---------------------------------------------------------------------------
AttributeError
Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_33368/2687219843.py in <module>
12 model1.fit(X_train, Y_train)
13 Pa_1=model1.predict(X_test)
---> 14 AC1=model1.score(X_test,Y_test)
15
16 Aa1 += AC1
AttributeError: 'MeanShift' object has no attribute 'score'
Solution
Yes, the error is true. MeanShift
really doesn't have any score
attribute.
As you wamted to get the accuracy, you need to use matrics
from sklearn
.
I am giving you a small snippet.
from sklearn.metrics import accuracy_score
...
...
Pa_1=model1.predict(X_test)
AC1=accuracy_score(Y_test, Pa_1) #<--- See this line
...
See the accuracy_score
documentation:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.accuracy_score.html
You can check more matrices as per your need: https://scikit-learn.org/stable/modules/classes.html#module-sklearn.metrics
Answered By - Arkadip Bhattacharya
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.