Wine test

We firtly import this library

import pandas as pd
import numpy as np

from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.svm import SVR
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score

df = pd.read_csv("wine.csv",sep=",")
df = df.dropna()


y = df["Wine"]
X = df.drop(["Wine"], axis = 1)
X_train, X_test, y_train, y_test = train_test_split(X, 
                                                    y, 
                                                    test_size=0.30, 
                                                    random_state=42)
svm_model = SVC(kernel = "linear").fit(X_train, y_train)
y_pred = svm_model.predict(X_test)
accuracy_score(y_test, y_pred)
svm = SVC()

svm_params = {"C": np.arange(1,10), "kernel": ["linear","rbf","poly"]}
svm_cv_model = GridSearchCV(svm, svm_params, cv = 5, n_jobs = -1, verbose = 2).fit(X_train, y_train)
svm_cv_model.best_score_
svm_cv_model.best_params_
svm_tuned = SVC(C = 2, kernel = "linear").fit(X_train, y_train)
y_pred = svm_tuned.predict(X_test)
accuracy_score(y_test, y_pred)
Alcohol = input("gir: ")
Malicacid= input("gir: ")
Ash= input("gir: ")
Alcalinityofash  = input("gir: ")
Magnesium= input("gir: ")
Totalphenols= input("gir: ")
Flavanoids= input("gir: ")
Nonflavanoidphenols= input("gir: ")
Proanthocyanins= input("gir: ")
Colorintensity= input("gir: ")
Hue= input("gir: ")
wines= input("gir: ")
Proline= input("gir: ") 
x_degerler = np.array([[Alcohol,Malicacid,Ash,Alcalinityofash,Magnesium,Totalphenols,Flavanoids,Nonflavanoidphenols,Proanthocyanins,Colorintensity,Hue,wines,Proline]])
print("x_yeni: {}".format(x_degerler.shape))

prediction = svm_tuned.predict(x_degerler)
print("tahmin: {}".format(prediction))

kontrolcu=int(prediction)
if kontrolcu==1:
    print("Tahmin sonucu: 1. sınıf kalite ")
elif kontrolcu==2:
    print("Tahmin sonucu: 2. sınıf kalite")
elif kontrolcu==3:
    print("Tahmin sonucu: 3. sınıf kalite")

Download

For download dataset and code click here.

Bir yanıt yazın