<jupyter_start><jupyter_text>Sample Wine Classifier on Wine Dataset<jupyter_code># Import important libraries
import numpy as np
import pandas as pd
import matplotlib as plt
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import LogisticRegression
from sklearn.naive_bayes import GaussianNB
from sklearn.neighbors import KNeighborsClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import GradientBoostingClassifier

from sklearn.model_selection import train_test_split

%matplotlib inline<jupyter_output><empty_output><jupyter_text>Load Dataset<jupyter_code>df = pd.read_csv('wine12.csv')
#test = pd.read_csv('test_data.csv')
#Adding Columns

df.columns = [  'name'
                 ,'alcohol'
                 ,'malicAcid'
                 ,'ash'
                 ,'ashalcalinity'
                 ,'magnesium'
                 ,'totalPhenols'
                 ,'flavanoids'
                 ,'nonFlavanoidPhenols'
                 ,'proanthocyanins'
                 ,'colorIntensity'
                 ,'hue'
                 ,'od280_od315'
                 ,'proline'
                ]<jupyter_output><empty_output><jupyter_text>Analyze Train Dataset<jupyter_code>df.head()
df.shape
df.isnull().sum()
df.describe()<jupyter_output><empty_output><jupyter_text>Create Test and Train Splits<jupyter_code>X= df.drop(['name', 'ash'], axis=1)

X.head()
y = df['name']
y.head()
train_X, valid_X, train_y, valid_y = train_test_split(X, y, test_size = 0.3)

print(train_X.shape, valid_X.shape)
models = []

models.append(("Logistic Regression:",LogisticRegression()))
models.append(("Naive Bayes:",GaussianNB()))
models.append(("K-Nearest Neighbour:",KNeighborsClassifier(n_neighbors=3)))
models.append(("Decision Tree:",DecisionTreeClassifier()))
models.append(("Random Forest:",RandomForestClassifier(n_estimators=20)))
models.append(("MLP:",MLPClassifier(hidden_layer_sizes=(45,30,15),solver='sgd',learning_rate_init=0.01,max_iter=500)))
models.append(("AdaBoostClassifier:",AdaBoostClassifier()))
models.append(("GradientBoostingClassifier:",GradientBoostingClassifier()))

print('Models appended...')
results = []
names = []
for name,model in models:
    kfold = KFold(n_splits=10, random_state=0)
    cv_result = cross_val_score(model,train_X,train_y.values.ravel(), cv = kfold,scoring = "accuracy")
    names.append(name)
    results.append(cv_result)
for i in range(len(names)):
    print(names[i],results[i].mean()*100)<jupyter_output>Logistic Regression: 94.4444444444
Naive Bayes: 95.5555555556
K-Nearest Neighbour: 94.4444444444
Decision Tree: 95.5555555556
Random Forest: 98.8888888889
MLP: 48.8888888889
AdaBoostClassifier: 96.6666666667
GradientBoostingClassifier: 94.4444444444
StarcoderdataJupyterStructuredCleanDedup