# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
# Author : <NAME>
# github link : https://github.com/amirshnll/Wine
# dataset link : http://archive.ics.uci.edu/ml/datasets/Wine
# email : <EMAIL>
# -

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

# +


col_names = ['class', 'Alcohol', 'Malic acid', 'Ash', 'Alcalinity of ash', 'Magnesium', 'Total phenols', 'Flavanoids', ' Nonflavanoid phenols','Proanthocyanins','Color intensity','Hue','OD280/OD315 of diluted wines','Proline']
wine =pd.read_csv("wine.csv",header=None, names=col_names)
# -

wine.head()

# +

inputs =wine.drop('class',axis='columns')
target = wine['class']
# -

inputs

# +
#  ایجاد دو دسته داده های آموزشی و تست برای ارزیابی عملکرد 
from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(inputs, target, test_size=0.3,random_state=109) 

# +
# توابع رگوسیون
from sklearn.linear_model import LogisticRegression

logreg = LogisticRegression()

logreg.fit(X_train,y_train)

y_pred=logreg.predict(X_test)
# -

# ایجاد ماتریس در هم ریختگی
from sklearn import metrics
cnf_matrix = metrics.confusion_matrix(y_test, y_pred)
cnf_matrix

# +

#ساخت ماتریس درهم ریختگی برای   ارزیابی عملکرد یک طبقه بندی و نشان دادن تعداد درست و نادرست
class_names=[0,1] # name  of classes
fig, ax = plt.subplots()
tick_marks = np.arange(len(class_names))
plt.xticks(tick_marks, class_names)
plt.yticks(tick_marks, class_names)
# ساخت هیت مپ
sns.heatmap(pd.DataFrame(cnf_matrix), annot=True, cmap="YlGnBu" ,fmt='g')
ax.xaxis.set_label_position("top")
plt.tight_layout()
plt.title('Confusion matrix', y=1.1)
plt.ylabel('Actual label')
plt.xlabel('Predicted label')
# -

print("Accuracy:",metrics.accuracy_score(y_test, y_pred))




StarcoderdataJupyterScriptsDedupFiltered