<jupyter_start><jupyter_text>Naive Bayes Exercise<jupyter_code># import pandas 
import pandas as pd
from sklearn import datasets

#Load dataet
wine = datasets.load_wine()<jupyter_output><empty_output><jupyter_text>* Print the available keys of the wine dictionary.<jupyter_code>wine.keys()<jupyter_output><empty_output><jupyter_text>* Print the names of the 13 features.<jupyter_code>print("Features: ", wine.feature_names)<jupyter_output>Features:  ['alcohol', 'malic_acid', 'ash', 'alcalinity_of_ash', 'magnesium', 'total_phenols', 'flavanoids', 'nonflavanoid_phenols', 'proanthocyanins', 'color_intensity', 'hue', 'od280/od315_of_diluted_wines', 'proline']<jupyter_text>* Print the label type of the different wines (class_0, class_1, class_2).<jupyter_code>print("Labels: ", wine.target_names)<jupyter_output>Labels:  ['class_0' 'class_1' 'class_2']<jupyter_text>* Print the data (feature) shape.<jupyter_code>wine.data.shape<jupyter_output><empty_output><jupyter_text>* Import the train_test_split function from sklearn.<jupyter_code>from sklearn.model_selection import train_test_split<jupyter_output><empty_output><jupyter_text>* Split the dataset into training set and test set. Use a 70:30 train & test ratio.<jupyter_code>X_train, X_test, y_train, y_test = train_test_split(wine.data, 
                                                    wine.target,
                                                    test_size=0.3,
                                                    random_state=42)<jupyter_output><empty_output><jupyter_text>* Import the Gaussian Naive Bayes model from sklearn.<jupyter_code>from sklearn import naive_bayes<jupyter_output><empty_output><jupyter_text>* Instatiate a Gaussian Classifier.<jupyter_code>gnb = naive_bayes.GaussianNB()<jupyter_output><empty_output><jupyter_text>* Train the model using the training set.<jupyter_code>gnb.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>* Predict the response on the testing set.<jupyter_code>y_pred = gnb.predict(X_test)
y_pred<jupyter_output><empty_output><jupyter_text>* Import accuracy_score from scikit-learn.<jupyter_code>from sklearn import metrics
metrics.accuracy_score(y_test, y_pred)*100<jupyter_output><empty_output><jupyter_text>* What is the accuracy of our classifier?<jupyter_code>print("Accuracy score: ", metrics.accuracy_score(y_test, y_pred)*100)<jupyter_output>Accuracy score:  100.0
{'fraction_non_alphanumeric': 0.10642737896494157, 'fraction_numerical': 0.01335559265442404, 'mean_word_length': 5.829059829059829, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '628776', 'license': 'MIT', 'n_tokens_mistral': 861, 'n_tokens_neox': 809, 'n_words': 151, 'path': 'w5/w5d4/naive_bayes_exercise.ipynb', 'repo_name': 'bmskarate/lighthouseMain', 'size': '2396'}