<jupyter_start><jupyter_text>Predicting Red Wine Quality with New Method Wine DataData from http://archive.ics.uci.edu/ml/datasets/Wine+Quality Citations<NAME>, <NAME>, <NAME>, <NAME> and <NAME>. Modeling wine preferences by data mining from physicochemical properties.In Decision Support Systems, Elsevier, 47(4):547-553. ISSN: 0167-9236.Available at:- [@Elsevier](http://dx.doi.org/10.1016/j.dss.2009.05.016)- [Pre-press (pdf)](http://www3.dsi.uminho.pt/pcortez/winequality09.pdf)- [bib](http://www3.dsi.uminho.pt/pcortez/dss09.bib)<NAME>. and <NAME>. (2017). UCI Machine Learning Repository [http://archive.ics.uci.edu/ml]. Irvine, CA: University of California, School of Information and Computer Science. Setup<jupyter_code>%matplotlib inline

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns

red_wine = pd.read_csv('../../ch_09/data/winequality-red.csv')<jupyter_output><empty_output><jupyter_text>Making the `high_quality` column<jupyter_code>red_wine['high_quality'] = pd.cut(red_wine.quality, bins=[0, 6, 10], labels=[0, 1])
red_wine.high_quality.value_counts(normalize=True)<jupyter_output><empty_output><jupyter_text>Building your first Support Vector Machine<jupyter_code>from sklearn.model_selection import train_test_split
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC

y = red_wine.pop('high_quality')
X = red_wine.drop(columns=['quality'])

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

pipeline = Pipeline([
    ('scale', StandardScaler()), ('svm', SVC(C=5, random_state=0, probability=True))
]).fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Evaluating the SVM<jupyter_code>quality_preds = pipeline.predict(X_test)
from sklearn.metrics import classification_report
print(classification_report(y_test, quality_preds))
from ml_utils.classification import plot_pr_curve

plot_pr_curve(y_test, pipeline.predict_proba(X_test)[:,1])
from ml_utils.classification import confusion_matrix_visual

confusion_matrix_visual(y_test, quality_preds, ['low', 'high'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12864963503649635, 'fraction_numerical': 0.025547445255474453, 'mean_word_length': 7.370229007633588, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '375398', 'license': 'MIT', 'n_tokens_mistral': 818, 'n_tokens_neox': 753, 'n_words': 154, 'path': 'solutions/ch_09/exercise_5.ipynb', 'repo_name': 'rvmuthukumar/Hands-On-Data-Analysis-with-Pandas', 'size': '2220'}