<jupyter_start><jupyter_text>1) Heart Disease UCI (Heart.csv) 데이터를 읽어서 30%를 test set으로 분리<jupyter_code>X = df.iloc[:, 0:13]
y = df.target.values
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)<jupyter_output><empty_output><jupyter_text>2) 3-NN, Gaussian Naive Bayes, Logistic Regression 분류 알고리즘에 대한 성능 확인<jupyter_code>import mglearn
from sklearn.neighbors import KNeighborsClassifier
clf = KNeighborsClassifier(n_neighbors=3)
clf.fit(X_train, y_train)
train_accuracy = clf.score(X_train, y_train)
test_accuracy = clf.score(X_test, y_test)
print("Train accuracy : ", train_accuracy)
print("Test accuracy : ", test_accuracy)
from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB()
gnbfit = gnb.fit(X_train, y_train)
train_accuracy = gnbfit.score(X_train, y_train)
test_accuracy = gnbfit.score(X_test, y_test)

print("Train accuracy : ", train_accuracy)
print("Test accuracy : ", test_accuracy)
from sklearn.linear_model import LogisticRegression

logrfit01 = LogisticRegression(C=0.01).fit(X_train, y_train)
train_accuracy = logrfit01.score(X_train, y_train)
test_accuracy = logrfit01.score(X_test, y_test)
print("Train accuracy(C=0.01) : ", train_accuracy)
print("Test accuracy(C=0.01) : ", test_accuracy)

logrfit = LogisticRegression().fit(X_train, y_train)
train_accuracy = logrfit.score(X_train, y_train)
test_accuracy = logrfit.score(X_test, y_test)
print("Train accuracy(C=1) : ", train_accuracy)
print("Test accuracy(C=1) : ", test_accuracy)

logrfit100 = LogisticRegression(C=100).fit(X_train, y_train)
train_accuracy = logrfit100.score(X_train, y_train)
test_accuracy = logrfit100.score(X_test, y_test)
print("Train accuracy(C=100) : ", train_accuracy)
print("Test accuracy(C=100) : ", test_accuracy)<jupyter_output>Train accuracy(C=0.01) :  0.8066037735849056
Test accuracy(C=0.01) :  0.7802197802197802
Train accuracy(C=1) :  0.8632075471698113
Test accuracy(C=1) :  0.8021978021978022
Train accuracy(C=100) :  0.8679245283018868
Test accuracy(C=100) :  0.8131868131868132<jupyter_text>3) Logistic Regression 의 특징 계수(coef)에 대한 그래프를 그리기 (강의자료 10쪽 참고)<jupyter_code>plt.plot(logrfit01.coef_.T, 'o', label = 'C=0.01')
plt.plot(logrfit.coef_.T, '^', label = 'C=1')
plt.plot(logrfit100.coef_.T, 'v', label = 'C=100')
plt.xticks(range(df.iloc[:, 0:13].shape[1]), df.columns, rotation=90)
xlims = plt.xlim()
plt.hlines(0, xlims[0], xlims[1])
plt.xlim(xlims)
plt.ylim(-2.5, 2.5)
plt.xlabel('features')
plt.ylabel('coef')
plt.legend()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14336917562724014, 'fraction_numerical': 0.0760653126244524, 'mean_word_length': 7.457912457912458, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '332073', 'license': 'CC-BY-3.0', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1110, 'n_words': 178, 'path': 'Logistic_Regression_UCI_hd.ipynb', 'repo_name': 'wlgh312/DataMining', 'size': '2511'}