如何提高朴素贝叶斯的准确性

时间:2017-10-06 13:02:09

标签: python scikit-learn naivebayes multinomial

我正在使用以下代码

imageView.setDrawingCacheEnabled(true);
imageView.buildDrawingCache();
Bitmap bitmap = imageView.getDrawingCache();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] data = baos.toByteArray();

UploadTask uploadTask = mountainsRef.putBytes(data); 
uploadTask.addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) {
            // Handle unsuccessful uploads
        } }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
            Uri downloadUrl = taskSnapshot.getDownloadUrl();
        } });

并且获得了可靠性.55我尝试使用更改参数进行调整,但没有运气数据如下:

import pandas as pd
from sklearn.model_selection import train_test_split
import numpy as np
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import Pipeline

data = pd.read_csv("severeinjury.csv",error_bad_lines=False)
numpy_array = data.as_matrix()
X = numpy_array[:,15]
Y = numpy_array[:,17]

X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=.2, random_state=67)
##print(list(X_train))
text_clf = Pipeline([('vect', CountVectorizer(stop_words='english')), ('tfidf', TfidfTransformer()), ('clf', MultinomialNB()),])
#text_clf = text_clf.fit(list(X_train),list(Y_train))
text_clf = text_clf.fit(X_train,Y_train)
predicted = text_clf.predict(X_test)
accuracy=np.mean(predicted == Y_test)
print(accuracy)

X =[ "Three correctional facility guards were escorting a restrained federal prison inmate when he became disruptive, requiring the use of force. \nTwo guards and the inmate fell onto the Lieutenant's right leg, fracturing his fibula. He was transported to the hospital and released the following day."
 'Employee in the Machine Shop received second degree burns to the back of his legs after the torch he was using exploded.'
 'A truck driver fell approximately 4 feet while descending a tanker trailer ladder.  The employee was kept overnight awaiting test results.'
 ...,
 "An employee was walking down a flight of three stairs from the client's home into their garage when she missed the last step and fell. She was hospitalized for a fractured tibia and fibula."
 'An employee was hospitalized for carbon monoxide poisoning while working at a construction site.'
 "An employee was cutting the strapping on a bundle of steel square tubing. The bundle was approximately waste high and stacked on top of other material cribbed by 4'x 4' lumber. The bundle fell onto the employee when the last retaining band was cut breaking the employee's right leg."]

原始数据可在互联网上找到https://www.osha.gov/severeinjury/index.html 我是文本分析领域的新宠,因此任何示例都会对提高准确性更有帮助。

0 个答案:

没有答案