<jupyter_start><jupyter_text>Linear<jupyter_code>xTrain = year1[['mean_return', 'volatility']]
scaler.fit(xTrain)
xTrain = scaler.transform(xTrain)
yTrain = year1.label

xTest = year2[['mean_return', 'volatility']]
scaler.fit(xTest)
xTest = scaler.transform(xTest)
yTest = year2.label


clf = svm.SVC(kernel='linear')
clf.fit(xTrain, yTrain)
yPredict = clf.predict(xTest)

print(accuracy_score(yTest, yPredict))

## Confusion Matrix I choose 
temp = confusion_matrix(yTest, yPredict)
print(temp)

tn = temp[0][0]
fn = temp[1][0]
tp = temp[1][1]
fp = temp[0][1]

tpr = tp / (tp + fn)
tnr = tn / (tn + fp)

print('TPR = {}, TNR = {}'.format(tpr, tnr))

# Strategy check
dfDetail = pd.read_csv('./GOOGL_weekly_return_volatility_detailed.csv')
year2Detail = dfDetail[dfDetail.Year == 2020]
year2Detail = year2Detail.reset_index(drop = True)

## Add label to detail
lMap = labelMapping(year2.Year, year2.Week_Number, yPredict)
temp = []
for (y, w) in zip(year2Detail.Year, year2Detail.Week_Number):
    key = (y, w)
    temp.append(lMap[key]) 
year2Detail['Label'] = temp
year2Detail = year2Detail[['Year', 'Week_Number', 'Close', 'Label']]

## Cut goo2020
goo2020Week = cutWeek(53, year2Detail)




## trading 
total = proficCalculator(goo2020Week, 100)
print("Using Label: {}".format(total))

## trding BH
firstWeek = goo2020Week[0]
firstClose = firstWeek.Close[0]

lastWeek = goo2020Week[-1]
lastClose = lastWeek.Close[len(lastWeek)-1]

r = 1 + (lastClose - firstClose) / lastClose
total = 100 * r
print("Buy on first day and Sell on last day: {}".format(total))<jupyter_output>Using Label: 239.64550014107087
Buy on first day and Sell on last day: 121.17033527942765<jupyter_text>Gaussian SVM<jupyter_code>xTrain = year1[['mean_return', 'volatility']]
scaler.fit(xTrain)
xTrain = scaler.transform(xTrain)
yTrain = year1.label

xTest = year2[['mean_return', 'volatility']]
scaler.fit(xTest)
xTest = scaler.transform(xTest)
yTest = year2.label


clf = svm.SVC(kernel='rbf')
clf.fit(xTrain, yTrain)
yPredict = clf.predict(xTest)

print(accuracy_score(yTest, yPredict))

## Confusion Matrix I choose 
temp = confusion_matrix(yTest, yPredict)
print(temp)

tn = temp[0][0]
fn = temp[1][0]
tp = temp[1][1]
fp = temp[0][1]

tpr = tp / (tp + fn)
tnr = tn / (tn + fp)

print('TPR = {}, TNR = {}'.format(tpr, tnr))

# Strategy check
dfDetail = pd.read_csv('./GOOGL_weekly_return_volatility_detailed.csv')
year2Detail = dfDetail[dfDetail.Year == 2020]
year2Detail = year2Detail.reset_index(drop = True)

## Add label to detail
lMap = labelMapping(year2.Year, year2.Week_Number, yPredict)
temp = []
for (y, w) in zip(year2Detail.Year, year2Detail.Week_Number):
    key = (y, w)
    temp.append(lMap[key]) 
year2Detail['Label'] = temp
year2Detail = year2Detail[['Year', 'Week_Number', 'Close', 'Label']]

## Cut goo2020
goo2020Week = cutWeek(53, year2Detail)




## trading 
total = proficCalculator(goo2020Week, 100)
print("Using Label: {}".format(total))

## trding BH
firstWeek = goo2020Week[0]
firstClose = firstWeek.Close[0]

lastWeek = goo2020Week[-1]
lastClose = lastWeek.Close[len(lastWeek)-1]

r = 1 + (lastClose - firstClose) / lastClose
total = 100 * r
print("Buy on first day and Sell on last day: {}".format(total))<jupyter_output>Using Label: 238.07688171932494
Buy on first day and Sell on last day: 121.17033527942765<jupyter_text>poly degree2<jupyter_code>xTrain = year1[['mean_return', 'volatility']]
scaler.fit(xTrain)
xTrain = scaler.transform(xTrain)
yTrain = year1.label

xTest = year2[['mean_return', 'volatility']]
scaler.fit(xTest)
xTest = scaler.transform(xTest)
yTest = year2.label


clf = svm.SVC(kernel='poly', degree=2)
clf.fit(xTrain, yTrain)
yPredict = clf.predict(xTest)

print(accuracy_score(yTest, yPredict))

## Confusion Matrix I choose 
temp = confusion_matrix(yTest, yPredict)
print(temp)

tn = temp[0][0]
fn = temp[1][0]
tp = temp[1][1]
fp = temp[0][1]

tpr = tp / (tp + fn)
tnr = tn / (tn + fp)

print('TPR = {}, TNR = {}'.format(tpr, tnr))

# Strategy check
dfDetail = pd.read_csv('./GOOGL_weekly_return_volatility_detailed.csv')
year2Detail = dfDetail[dfDetail.Year == 2020]
year2Detail = year2Detail.reset_index(drop = True)

## Add label to detail
lMap = labelMapping(year2.Year, year2.Week_Number, yPredict)
temp = []
for (y, w) in zip(year2Detail.Year, year2Detail.Week_Number):
    key = (y, w)
    temp.append(lMap[key]) 
year2Detail['Label'] = temp
year2Detail = year2Detail[['Year', 'Week_Number', 'Close', 'Label']]

## Cut goo2020
goo2020Week = cutWeek(53, year2Detail)




## trading 
total = proficCalculator(goo2020Week, 100)
print("Using Label: {}".format(total))

## trding BH
firstWeek = goo2020Week[0]
firstClose = firstWeek.Close[0]

lastWeek = goo2020Week[-1]
lastClose = lastWeek.Close[len(lastWeek)-1]

r = 1 + (lastClose - firstClose) / lastClose
total = 100 * r
print("Buy on first day and Sell on last day: {}".format(total))<jupyter_output>Using Label: 130.6809069546468
Buy on first day and Sell on last day: 121.17033527942765
{'fraction_non_alphanumeric': 0.15318209194940774, 'fraction_numerical': 0.05681590042160209, 'mean_word_length': 5.5552631578947365, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '201754', 'license': 'MIT', 'n_tokens_mistral': 2147, 'n_tokens_neox': 1943, 'n_words': 421, 'path': 'Assignment_11/SVM/SVM code.ipynb', 'repo_name': 'KyleLeePiupiupiu/CS677_Assignment', 'size': '4981'}