<jupyter_start><jupyter_text>Support Vector Machine<jupyter_code>#reading and cleaning data
churn_df=pd.read_csv("train.csv")
mydata = churn_df.drop(['review_title','review_description','user_name','designation','winery','country'], axis=1)
churn_df = mydata.dropna()
churn_df.head()
# replace function for wine varieties
def replace(str1,num):
    churn_df['variety'].replace(
    to_replace=[str1],
    value=num,
    inplace=True
    )
# converting into unique numeric values for SVM
replace("Chardonnay",0)
replace("Red Blend",1)
replace("Nebbiolo",2)
replace("Bordeaux-style White Blend",3)
replace("Malbec",4)
replace("<NAME>",5)
replace("Zinfandel",6)
replace("<NAME>",7)
replace("<NAME>",6)
replace("Gamay",9)
replace("<NAME>",10)
replace("Bordeaux-style Red Blend",11)
replace("Sangiovese",12)
replace("Syrah",13)
replace("White Blend",14)
replace("<NAME>",15)
replace("Portuguese Red",16)
replace("Rhône-style Red Blend",17)
replace("Rosé",18)
replace("Champagne Blend",19)
replace("Merlot",20)
replace("Riesling",21)                  
replace("Sparkling Blend",22)
replace("<NAME>",23)
replace("Tempranillo",24)
replace("<NAME>",25)
replace("Portuguese White",26)
replace("Gewürztraminer",27)
features_df=churn_df[['points',"price"]]
X = np.asanyarray(features_df)
X[0:5]
churn_df['variety']=churn_df['variety'].astype('int')
y = np.asanyarray(churn_df['variety'])
y[0:5]
#train / test split
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size = 0.4, random_state = 4)
print("Trained Set :",X_train.shape,y_train.shape)
print("Tested Set :",X_test.shape,y_test.shape)
#modelling by Using Scikit learn SVM
from sklearn import svm
clf = svm.SVC(kernel = 'rbf')
clf.fit(X_train,y_train)
#predicting on the basis of SVM model built
yhat = clf.predict(X_test)
yhat[0:5]
from sklearn import metrics
print("The Accuracy of the model is : ",metrics.accuracy_score(y_test,yhat))
from sklearn.metrics import f1_score
f1_score(y_test,yhat,average='weighted')<jupyter_output><empty_output><jupyter_text>Decision Tree Classification:<jupyter_code>#constructing Decision Tree Classifier
df = pd.read_csv("train.csv")
my_data = df
my_data = my_data.dropna()
X = my_data[["points","price","province"]]
X[0:5]
y = my_data["variety"].values
y[0:5]
#preprocessing
le_province = preprocessing.LabelEncoder()
le_province.fit(['Washington','California','Oregon','New York'])
X.iloc[:,2]=le_province.transform(X.iloc[:,2])
train_X,test_X,train_y,test_y = train_test_split(X,y,test_size = 0.4,random_state = 4)
#plotting decision Tree
varTree = DecisionTreeClassifier( criterion = "entropy",max_depth = 4)
varTree
varTree.fit(train_X,train_y)
predTree = varTree.predict(test_X)
predTree
dot_data = StringIO()
filename ="VarTree.png"
featureNames = churn_df.columns[0:3]
targetNames = churn_df["variety"].unique().tolist()
out = tree.export_graphviz(varTree,feature_names = featureNames,out_file =dot_data,class_names = np.unique(train_y),filled = True,special_characters =True,rotate = True)
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
graph.write_png(filename)
img = mpimg.imread(filename)
plt.figure(figsize = (100,50))
plt.imshow(img,interpolation ="nearest")
plt.show()
test =pd.read_csv("test.csv")
testdata = df.drop(['review_title','review_description','user_name','designation','winery','country'], axis=1)
testdata2 = testdata.dropna()
test_data = testdata2[["points","price"]]
test_data.head()
yhat2 = clf.predict(test_data)
yhat2[0:5]
#writing in the csv file
import pandas as pd
df = pd.read_csv('abc.csv')
new_column = pd.DataFrame({'Predicted Value': yhat2})
df = df.merge(new_column, left_index = True, right_index = True)
df.to_csv('abc.csv', index = False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16469321851453175, 'fraction_numerical': 0.022874058127018298, 'mean_word_length': 8.6796875, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '568070', 'license': 'MIT', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1376, 'n_words': 237, 'path': 'main.ipynb', 'repo_name': 'pratham0203/wine-variety', 'size': '3769'}