본문 바로가기
IT/머신러닝

[54일차] 03. 라소(Lasso)

by GWLEE 2022. 9. 6.

 

 

 

 

 

 

for C, marker in zip([0.001, 1, 100], ['o', '^', 'v']):
    lr_l1 = LogisticRegression(C=C, penalty="l1", solver='liblinear').fit(X_train, y_train)
    print("Training accuracy of l1 logreg with C={:.3f}: {:.2f}".format(C, lr_l1.score(X_train, y_train)))
    print("Test accuracy of l1 logreg with C={:.3f}: {:.2f}".format(C, lr_l1.score(X_test, y_test)))
    plt.plot(lr_l1.coef_.T, marker, label="C={:.3f}".format(C))
    
    
plt.xticks(range(cancer.data.shape[1]), cancer.feature_names, rotation=90)
plt.hlines(0, 0, cancer.data.shape[1])
plt.xlabel("Coefficient index")
plt.ylabel("Coefficient magnitude")

plt.ylim(-5, 5)
plt.legend(loc=3)
plt.show()

 

 

 

 

 

 

'IT > 머신러닝' 카테고리의 다른 글

[54일차] 07. Clustering  (0) 2022.09.07
[54일차] 06. Unsupervised learning  (0) 2022.09.06
[54일차] 05. SVM  (0) 2022.09.06
[54일차] 04. 결정 트리 ( Decision Trees)  (0) 2022.09.06
[53일차] 01. Intro / 02. k-NN / 03.Linear  (0) 2022.09.05

댓글