<jupyter_start><jupyter_text>SVM<jupyter_code>#the sales channel (Hotel/Restaurant/Cafe = 1 vs. Retail = 2) 
#the region (Lisbon = 1, Oporto = 2, or Other = 3) of the retailer<jupyter_output><empty_output><jupyter_text>Linear SVM<jupyter_code>df_svm = pd.read_csv('wholesale-customers.csv', sep=',')
df_svm.head()
from sklearn import svm, grid_search
import numpy as np
from sklearn.model_selection import cross_val_score
from sklearn import datasets, svm
X = df_svm.iloc[:,1:]
y = df_svm.iloc[:,:1]
X.head()
y.head()
transformed_y = (-1)**y
transformed_y.head()
standardized_X_values = preprocessing.scale(X)
standardized_X = pd.DataFrame(data = standardized_X_values)
standardized_X.columns = X.columns.values
standardized_X.head()
svc = svm.SVC(kernel='linear')
C_s = np.logspace(-10, 0, 10)

scores = list()
#scores_std = list()
for C in C_s:
    svc.C = C
    cv_scores = cross_val_score(svc, standardized_X, np.ravel(y), cv=10, n_jobs=-1)
    scores.append(np.mean(cv_scores))
scores
best_c = Cs[np.argmax(scores)]
best_c
 _, ax = plt.subplots(1,1)
ax.semilogx(Cs, scores)
plt.ylabel("SVM Accuracy")
plt.xlabel("Linear SVM Hyperparameter: C")
plt.title("Linear SVM Cross-Validation Accuracy vs Hypermeter C")
l_svm = svm.SVC(kernel='linear', C= 1)
model = l_svm.fit(standardized_X, np.ravel(y))
linearsvm_coefficients_array = np.append(model.coef_, model.intercept_)
indices = np.append(standardized_X.columns,"intercept")
linearsvm_coefficients = pd.DataFrame(linearsvm_coefficients_array,index = indices).rename(columns = {0: "coefficients"})
linearsvm_coefficients<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13786650031191516, 'fraction_numerical': 0.012476606363069246, 'mean_word_length': 6.6380952380952385, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '526436', 'license': 'MIT', 'n_tokens_mistral': 662, 'n_tokens_neox': 617, 'n_words': 121, 'path': 'Part 2/Linear SVM.ipynb', 'repo_name': 'sumaanyu/Some-Regression-and-Classification-Projects', 'size': '1603'}