如何提高精度并提高召回率?

时间:2019-07-23 21:45:34

标签: python keras

我想提高总体指标得分。特别是精度和召回率。但是我不知道如何执行此操作,并尝试了我想过的所有方法。

虽然我似乎死定了,而且对均匀的方向也没有特别的想法。

import pandas as pd
import numpy as np
import keras
from keras.models import Sequential
from keras.layers import Dense
import matplotlib.pyplot as plt
from sklearn.svm import SVC
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import confusion_matrix, classification_report
import sklearn.metrics as metrics
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.naive_bayes import GaussianNB
import tensorflow as tf
import pickle
from sklearn.decomposition import PCA



#Normalize Data
heart_data = pd.read_csv('test.csv')
heart_data.drop('id',axis=1,inplace=True)

heart_data.head()
y = heart_data.target.values
x_data = heart_data.drop(['target'], axis = 1)
x = (x_data - np.min(x_data)) / (np.max(x_data) - np.min(x_data)).values
n_cols = x.shape[1]

#Splitting Data
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)




def regression_model():
    # create model
    model = Sequential()
    #inputs
    model.add(Dense(50, activation='sigmoid', input_shape=(n_cols,)))
    model.add(Dense(50, activation='sigmoid')) # activation function
    model.add(Dense(1))

    # compile model
    model.compile(optimizer='adam', loss='mean_squared_error')
    #loss measures the results and figures out how bad it did. Optimizer generates next guess.
    return model


# build the model
model = regression_model()
print (model)
# fit the model
history=model.fit(x_train, y_train, validation_data=(x_test,y_test), epochs=100, batch_size=10)

#K Nearest Neighbor

neigh = KNeighborsClassifier(n_neighbors=6)
neigh.fit(x_test, y_test)
y_test_pred = neigh.predict(x_test)
print("Test Accuracy of KNN Algorithm: {:.2f}%".format(neigh.score(x_test,y_test)*100))
print('KNN Teacher Classification report \n',classification_report(y_test, y_test_pred))
with open('knearest_teacher', 'wb') as k:
    pickle.dump(neigh, k)
#Support Vector Machine

svm = SVC(random_state = 1)
svm.fit(x_test, y_test)
y_test_pred = svm.predict(x_test)
print("Test Accuracy of SVM Alg orithm: {:.2f}%".format(svm.score(x_test,y_test)*100))
print('SVM Teacher Classification report \n',classification_report(y_test, y_test_pred))
with open('supportvector_teacher', 'wb') as s:
    pickle.dump(svm, s)

#Random Forest

rf = RandomForestClassifier(n_estimators = 1000, random_state = 1)
rf.fit(x_train, y_train)
y_test_pred = rf.predict(x_test)
print("Random Forest Algorithm Accuracy Score : {:.2f}%".format(rf.score(x_test,y_test)*100))
print('Random Teacher Forest Classification report \n',classification_report(y_test, y_test_pred))
with open('randomforest_teacher', 'wb') as f:
    pickle.dump(rf, f)
#Naive Bayes

nb = GaussianNB()
nb.fit(x_train, y_train)
y_test_pred = nb.predict(x_test)
print("Naive Bayes Algorithm Accuracy Score : {:.2f}%".format(nb.score(x_test,y_test)*100))
print('Naive Bayes Teacher Classification report \n',classification_report(y_test, y_test_pred))
with open('supportvector_teacher', 'wb') as s:
    pickle.dump(svm, s)




model.save('teacher_trained.model')


我希望获得90%的百分比,但是我认为问题可能出在数据集本身中,因为没人能做到这一点。 Dataset

0 个答案:

没有答案