<jupyter_start><jupyter_text>Load Dataset<jupyter_code># import libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
%matplotlib inline
# read dataset and print first 5 rows
data = pd.read_csv('../data/beer_data.csv')
data.head()
# print the shape of the dataset
data.shape<jupyter_output><empty_output><jupyter_text>Feature Engineering  Handle null values<jupyter_code># check null values
data.isnull().sum()
# Drop null values of Cellar Temprature column
data = data[~data['Cellar Temperature'].isnull()]
data.reset_index(drop=True, inplace=True)
# fill ABV null values with the mean
data['ABV'].fillna(data['ABV'].mean(), inplace=True)<jupyter_output><empty_output><jupyter_text>Handle Categorical Values Ratings column have numerical data but as object type and have comma included.**For example**: 1,112So, remove the comma and convert the datatype to float<jupyter_code># remove ',' from the Ratings' column data and convert the column to float64
data['Ratings'] = data['Ratings'].apply(lambda x: np.float64(x.replace(',', '')))<jupyter_output><empty_output><jupyter_text>Cellar Temprature have numerical data but the data type is object.The data is in the form of **41-42**.So, basically the data is minimum temprature - maximum temprature. We can split this column into two separate columns.- min_temp- max_tempand then convert the data to float type.<jupyter_code>data['min_cellar_temp'] = data['Cellar Temperature'].apply(lambda x: int(str(x).split('-')[0].strip()))
data['max_cellar_temp'] = data['Cellar Temperature'].apply(lambda x: int(str(x).split('-')[1].strip()))<jupyter_output><empty_output><jupyter_text>Drop Cellar Temprature column because we don't need this column<jupyter_code>data.drop('Cellar Temperature', axis=1, inplace=True)<jupyter_output><empty_output><jupyter_text>Our dataset is too large so let's shuffle the dataset and create a new dataset with the first 10,000 values<jupyter_code>from sklearn.utils import shuffle
data = shuffle(data)
dataset_1 = data[:50000]<jupyter_output><empty_output><jupyter_text>Split data into **features** and **target**<jupyter_code># Split data into X and y
X = dataset_1.drop('Score', axis=1)
y = dataset_1['Score']<jupyter_output><empty_output><jupyter_text>Create Train and Test sets<jupyter_code># create train and test set
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=42)<jupyter_output><empty_output><jupyter_text>Apply Support Vector Regression<jupyter_code># import support vector regressor
from sklearn.svm import SVR

model = SVR()

# train the model using train data
model.fit(X_train, y_train)

# predict data for test set
pred = model.predict(X_test)

# evaluate the model using root mean log squared error
def rmlse(y_test, pred):
    error = np.square(np.log10(pred+1) - np.log10(y_test+1)).mean() ** 0.5
    score = 1 - error
    return score
# print the score
rmlse(y_test, pred)
# plot the actual and predicted values to show the difference
plt.scatter(y_test,pred)
plt.xlabel('Actual')
plt.ylabel('Predicted')
plt.show();
# save the model
import pickle

pickle.dump(model, open('beer.model', 'wb'))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11650185414091471, 'fraction_numerical': 0.013288009888751545, 'mean_word_length': 6.818840579710145, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '101892', 'license': 'MIT', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1060, 'n_words': 310, 'path': 'beer_score_prediction/notebooks/beer_score_prediction.ipynb', 'repo_name': 'sharmas1ddharth/DS_Projects', 'size': '3236'}