text_plain_output_1.png
from sklearn import linear_model

from sklearn.feature_extraction.text import TfidfVectorizer

from sklearn.preprocessing import LabelEncoder

import matplotlib.mlab as mlab

import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

data = pd.read_csv('../input/winemag-data_first150k.csv')

import matplotlib.mlab as mlab

num_bins = 20
n, bins, patches = plt.hist(data['points'], num_bins, normed=1, facecolor='blue', alpha=0.5)
plt.title('Distribution of Wine Scores')
plt.xlabel('Score out of 100')
plt.ylabel('Frequency')

mu = 88 # mean of distribution
sigma = 3 # standard deviation of distribution

y = mlab.normpdf(bins, mu, sigma) # create the y line

plt.plot(bins, y, 'r--')

df = data.dropna(subset=['description'])  # drop all NaNs

df_sorted = df.sort_values(by='points', ascending=True)  # sort by points

num_of_wines = df_sorted.shape[0]  # number of wines
worst = df_sorted.head(int(0.25*num_of_wines))  # 25 % of worst wines listed
best = df_sorted.tail(int(0.25*num_of_wines))  # 25 % of best wines listed

from sklearn.feature_extraction.text import TfidfVectorizer
vectorizer = TfidfVectorizer(stop_words='english', analyzer='word')

X1 = vectorizer.fit_transform(best['description'])
idf = vectorizer.idf_
goodlist = vectorizer.vocabulary_

X = vectorizer.fit_transform(worst['description'])
idf = vectorizer.idf_
not_so_good_list = vectorizer.vocabulary_

from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
y = le.fit_transform(best['variety'])

reg = linear_model.Ridge(alpha=0.5, solver='sag')

y = data['points']
x = vectorizer.fit_transform(data['description'])
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=32)
reg.fit(x_train, y_train)