<jupyter_start><jupyter_text><jupyter_code>#mounting google drive...
from google.colab import drive
drive.mount('/content/drive')
#importing libraries
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import TfidfVectorizer
from scipy.sparse import hstack
from sklearn.svm import LinearSVC
from sklearn.metrics import confusion_matrix 
from sklearn.metrics import accuracy_score 
from sklearn.metrics import classification_report 
import seaborn as sns
import matplotlib.pyplot as plt
#loading the training dataset
df = pd.read_csv('/content/drive/My Drive/ml/train.csv')
df
#some visualization of data

sns.kdeplot(df.price)<jupyter_output><empty_output><jupyter_text>Majority of the price for wines ranges between 0 to 250,  also few wines has price as high as 3000 also.<jupyter_code>df['points'] = df['points']
df['price_log'] = np.log(df['price'])

#Crossing prices and Points
plt.figure(figsize=(10,4))

g = sns.regplot(x='points', y='price_log', 
                data=df, line_kws={'color':'red'},
                x_jitter=True, fit_reg=True, color='darkgreen')
g.set_title("Points x Price Distribuition", fontsize=20)
g.set_xlabel("Points", fontsize= 15)
g.set_ylabel("Price (log)", fontsize= 15)
plt.show()<jupyter_output><empty_output><jupyter_text>Very meaningfull scatter plot.*   The highest prices isn't of the wine with highest points.*   The most expensive wine have points between 87 and 90Maybe it would be interesting to find cheapest wines with the same quality.<jupyter_code># bar plot
print("Top countries that the wine is from \n")
df['country'].value_counts().head(10).plot.bar()
print("Top province(state) that the wine is from")
df['province'].value_counts().head(10).plot.pie()
#features selection ( only taking review_title and	review_description as other features are not contributing much for the prediction of variety.)
df = df.drop(['region_2','region_1','country','province','winery','user_name','designation','price','points', 'price_log'],axis=1)

# making new data frame with dropped NAN values
data = df.dropna(axis = 0, how ='any') 
data
#fiting the TfidfVectorizer on corpus of review_title and	review_description that will be going to use in the testset also.
tfidf1 = TfidfVectorizer(stop_words='english').fit(data['review_title'])
tfidf2 = TfidfVectorizer(stop_words='english').fit(data['review_description'])

def create_features(data):
    review_title = tfidf1.transform(data['review_title'])
    review_description = tfidf2.transform(data['review_description'])
    return hstack((review_title, review_description))

features = create_features(data)
y = data['variety']
# dividing the data into train(80%) and test(20%)
train_x, test_x, train_y, test_y = train_test_split(features, y, test_size=0.2, random_state=42)

# Creating SVM model
classifier = LinearSVC()
linearSVC_model = classifier.fit(train_x, train_y) 
y_score = linearSVC_model.predict(test_x)

# calculating accuracy score
print("accuracy score is : "+ str(accuracy_score(test_y, y_score))) 
# Python script for confusion matrix creation. 
print('Confusion Matrix :')
cm = confusion_matrix(test_y, y_score) 

df_cm = pd.DataFrame(cm, columns=np.unique(y), index = np.unique(y))
df_cm.index.name = 'Actual'
df_cm.columns.name = 'Predicted'
plt.figure(figsize = (30,20))
sns.heatmap(df_cm, cmap="Blues", annot=True, fmt='d',annot_kws={"size": 20})
print("classification report :")
print( classification_report(test_y, y_score) )
#making prediction on test dataset
#loading the test dataset
df2 = pd.read_csv('/content/drive/My Drive/ml/test.csv')

features2 = create_features(df2)

predictions = linearSVC_model.predict(features2)
df2['variety'] = pd.Series(predictions)
df2.to_csv('submissions.csv')
df2<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1206174777603349, 'fraction_numerical': 0.0141287284144427, 'mean_word_length': 6.481409001956947, 'pattern_counts': {'":': 1, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '323073', 'license': 'Apache-2.0', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1236, 'n_words': 327, 'path': 'Wine_variety_Prediction.ipynb', 'repo_name': 'anuj-glitch/Wine-variety-prediction', 'size': '3822'}