Python Forum
average aggregate function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
average aggregate function
#1
How to find average aggregate function for two classifier using method in python?
Reply
#2
The question seems not enough clear to me. What is the problem context? What did you try so far?
Reply
#3
Hi scidam,

Thanks for the reply. I am a student. I am trying to create a probability for decision tree and multilayer perceptron. I am facing an issue in creating an aggregate method for each class using the above-mentioned classifiers. I want to know how to create a method for classes that are in the data set.


1. here class means four classes which are given in the dataset

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import plot_confusion_matrix
from sklearn.naive_bayes import GaussianNB, MultinomialNB
from sklearn.metrics import accuracy_score
from sklearn.neighbors import KNeighborsClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import precision_score, recall_score,auc
from sklearn.metrics import roc_curve,roc_auc_score, plot_roc_curve
from sklearn.preprocessing import LabelEncoder




path="G:\Forest.xlsx"
rawdata= pd.read_excel(path)
print("data summary")
print(rawdata.describe())
nrow, ncol = rawdata.shape

X, y = rawdata.iloc[:, 1:].values, rawdata.iloc[:, 0].values

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, stratify=y, random_state=0)

clf = DecisionTreeClassifier(criterion='entropy')
clf=clf.fit(X_train, y_train)
tar_pred = clf.predict(X_test)
prob = clf.predict_proba(X_test)
#print("Accuracy score of our model with Decision Tree:",accuracy_score(y_test, tar_pred))
#precision = precision_score(y_true=y_test, y_pred=tar_pred, average='micro')
#print("Precision score of our model with Decision Tree :", precision)

#recall = recall_score(y_true=y_test, y_pred=tar_pred, average='micro')
#print("Recall score of our model with Decision Tree :", recall)
print("probability:",prob)
print("Accuracy score of our model with DT :", accuracy_score(y_test, tar_pred))
scores = cross_val_score(clf, X, y, cv=10)
print("Accuracy score of our model with DT under cross validation :", scores.mean())
print('Mean Accuracy of DT: %.3f%%' % (sum(scores)/float(len(scores))))
clf_MLP = MLPClassifier(hidden_layer_sizes=(5, 2), activation='logistic', solver='sgd', learning_rate='constant', learning_rate_init=0.1)
clf_MLP.fit(X_train, np.ravel(y_train, order='C'))
predictions = clf_MLP.predict(X_test)
pro=clf_MLP.predict_proba(X_test)
print("Accuracy score of our model with MLP :", accuracy_score(y_test, predictions))
scores = cross_val_score(clf_MLP, X, y, cv=10)
print("Accuracy score of our model with MLP under cross validation :", scores.mean())
print("probability:",pro)

print('Mean Accuracy Of MLP: %.3f%%' % (sum(scores)/float(len(scores))))
Reply
#4
Lets consider a hypothetic example:

true_classes = [1, 1, 0, 2, 2, 2]
predict_probas_clf1.shape = (6, 3)
predict_probas_clf2.shape = (6, 3)
Can you show what are you trying to calculate? Are you trying to somehow combine values of probabilities according to true/predicted classes? If you want to get error estimations per classes, maybe you need to consider confusion matrix...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Not able to figure out how to create bar plot on aggregate data - Python darpInd 1 2,289 Mar-30-2020, 11:37 AM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020